diff --git a/src/plugins/debugger/qml/qmlengine.cpp b/src/plugins/debugger/qml/qmlengine.cpp index 1da0baf8ab00348e7134df9dd6841fd284fa8cfa..e160a11c36331b58d4740c2b57b94032db728267 100644 --- a/src/plugins/debugger/qml/qmlengine.cpp +++ b/src/plugins/debugger/qml/qmlengine.cpp @@ -1045,13 +1045,15 @@ void QmlEngine::onDebugQueryStateChanged( qobject_cast<QmlJsDebugClient::QDeclarativeDebugExpressionQuery *>( sender()); if (query && state != QmlJsDebugClient::QDeclarativeDebugQuery::Error) { - QtMessageLogItem *item = constructLogItemTree(query->result()); + QtMessageLogItem *item = constructLogItemTree(qtMessageLogHandler()->root(), + query->result()); if (item) qtMessageLogHandler()->appendItem(item); } else qtMessageLogHandler()-> - appendItem(new QtMessageLogItem(QtMessageLogHandler::ErrorType, - _("Error evaluating expression."))); + appendItem(new QtMessageLogItem(qtMessageLogHandler()->root(), + QtMessageLogHandler::ErrorType, + _("Error evaluating expression."))); delete query; } @@ -1122,7 +1124,8 @@ void QmlEngine::appendDebugOutput(QtMsgType type, const QString &message, //This case is not possible return; } - QtMessageLogItem *item = new QtMessageLogItem(itemType, message); + QtMessageLogItem *item = new QtMessageLogItem(qtMessageLogHandler()->root(), + itemType, message); item->file = info.file; item->line = info.line; qtMessageLogHandler()->appendItem(item); @@ -1175,8 +1178,9 @@ bool QmlEngine::evaluateScriptExpression(const QString& expression) //Incase of invalid context, show Error message qtMessageLogHandler()-> appendItem(new QtMessageLogItem( + qtMessageLogHandler()->root(), QtMessageLogHandler::ErrorType, - _("Cannot evaluate without" + _("Cannot evaluate without " "a valid QML/JS Context.")), qtMessageLogHandler()->rowCount()); } @@ -1287,12 +1291,12 @@ bool QmlEngine::canEvaluateScript(const QString &script) } QtMessageLogItem *QmlEngine::constructLogItemTree( - const QVariant &result, const QString &key) + QtMessageLogItem *parent, const QVariant &result, const QString &key) { if (!result.isValid()) return 0; - QtMessageLogItem *item = new QtMessageLogItem(); + QtMessageLogItem *item = new QtMessageLogItem(parent); if (result.type() == QVariant::Map) { if (key.isEmpty()) item->text = _("Object"); @@ -1302,7 +1306,8 @@ QtMessageLogItem *QmlEngine::constructLogItemTree( QMapIterator<QString, QVariant> i(result.toMap()); while (i.hasNext()) { i.next(); - QtMessageLogItem *child = constructLogItemTree(i.value(), i.key()); + QtMessageLogItem *child = constructLogItemTree(item, + i.value(), i.key()); if (child) item->insertChild(item->childCount(), child); } @@ -1313,7 +1318,7 @@ QtMessageLogItem *QmlEngine::constructLogItemTree( item->text = QString(_("[%1] : List")).arg(key); QVariantList resultList = result.toList(); for (int i = 0; i < resultList.count(); i++) { - QtMessageLogItem *child = constructLogItemTree(resultList.at(i), + QtMessageLogItem *child = constructLogItemTree(item, resultList.at(i), QString::number(i)); if (child) item->insertChild(item->childCount(), child); diff --git a/src/plugins/debugger/qml/qmlengine.h b/src/plugins/debugger/qml/qmlengine.h index 48ebf238da5a44b1dadbf89a16aaee640f33c44e..3f285da4a3b6c887c9752115b6e1e5e848f4a10e 100644 --- a/src/plugins/debugger/qml/qmlengine.h +++ b/src/plugins/debugger/qml/qmlengine.h @@ -187,7 +187,8 @@ private: void updateEditor(Core::IEditor *editor, const QTextDocument *document); bool canEvaluateScript(const QString &script); - QtMessageLogItem *constructLogItemTree(const QVariant &result, + QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent, + const QVariant &result, const QString &key = QString()); bool adjustBreakpointLineAndColumn(const QString &filePath, quint32 *line, quint32 *column, bool *valid); diff --git a/src/plugins/debugger/qml/qmlv8debuggerclient.cpp b/src/plugins/debugger/qml/qmlv8debuggerclient.cpp index e83e587da15e3da8d18bc832ba4da046a395a4ab..db20ac22e7b99a0c26b7acf687c7471bd82816a0 100644 --- a/src/plugins/debugger/qml/qmlv8debuggerclient.cpp +++ b/src/plugins/debugger/qml/qmlv8debuggerclient.cpp @@ -128,8 +128,8 @@ public: //TODO:: remove this method void reformatRequest(QByteArray &request); - QtMessageLogItem *constructLogItemTree(const QmlV8ObjectData &objectData, - const QVariant &refsVal); + QtMessageLogItem *constructLogItemTree(QtMessageLogItem *parent, + const QmlV8ObjectData &objectData, const QVariant &refsVal); private: QByteArray packMessage(const QByteArray &type, const QByteArray &message = QByteArray()); QScriptValue initObject(); @@ -974,6 +974,7 @@ void QmlV8DebuggerClientPrivate::reformatRequest(QByteArray &request) } QtMessageLogItem *QmlV8DebuggerClientPrivate::constructLogItemTree( + QtMessageLogItem *parent, const QmlV8ObjectData &objectData, const QVariant &refsVal) { @@ -987,12 +988,12 @@ QtMessageLogItem *QmlV8DebuggerClientPrivate::constructLogItemTree( text = QString(_("%1: %2")).arg(QString::fromAscii(objectData.name)) .arg(objectData.value.toString()); - QtMessageLogItem *item = new QtMessageLogItem( - QtMessageLogHandler::UndefinedType, text); + QtMessageLogItem *item = new QtMessageLogItem(parent, + QtMessageLogHandler::UndefinedType, text); foreach (const QVariant &property, objectData.properties) { QtMessageLogItem *child = constructLogItemTree( - extractData(property, refsVal), refsVal); + item, extractData(property, refsVal), refsVal); if (child) item->insertChild(item->childCount(), child); } @@ -1837,7 +1838,8 @@ void QmlV8DebuggerClient::updateEvaluationResult(int sequence, bool success, con } else if (d->debuggerCommands.contains(sequence)) { d->updateLocalsAndWatchers.removeOne(sequence); QmlV8ObjectData body = d->extractData(bodyVal, refsVal); - QtMessageLogItem *item = d->constructLogItemTree(body, refsVal); + QtMessageLogItem *item = d->constructLogItemTree(d->engine->qtMessageLogHandler()->root(), + body, refsVal); if (item) d->engine->qtMessageLogHandler()->appendItem(item); //Update the locals diff --git a/src/plugins/debugger/qtmessageloghandler.cpp b/src/plugins/debugger/qtmessageloghandler.cpp index e8eae4038aec50f2cd716dd812e4fd7accb81127..5639eca855f886ab3c9d344adbd975860167509f 100644 --- a/src/plugins/debugger/qtmessageloghandler.cpp +++ b/src/plugins/debugger/qtmessageloghandler.cpp @@ -45,8 +45,8 @@ namespace Internal { // /////////////////////////////////////////////////////////////////////// -QtMessageLogItem::QtMessageLogItem(QtMessageLogHandler::ItemType itemType, - const QString &text, QtMessageLogItem *parent) +QtMessageLogItem::QtMessageLogItem(QtMessageLogItem *parent, + QtMessageLogHandler::ItemType itemType, const QString &text) : m_parentItem(parent), text(text), itemType(itemType), @@ -86,8 +86,8 @@ bool QtMessageLogItem::insertChildren(int position, int count) for (int row = 0; row < count; ++row) { QtMessageLogItem *item = new - QtMessageLogItem(QtMessageLogHandler::UndefinedType, QString(), - this); + QtMessageLogItem(this , QtMessageLogHandler::UndefinedType, + QString()); m_childItems.insert(position, item); } @@ -99,10 +99,6 @@ bool QtMessageLogItem::insertChild(int position, QtMessageLogItem *item) if (position < 0 || position > m_childItems.size()) return false; - if (item->parent()) - item->parent()->detachChild(item->childNumber()); - - item->m_parentItem = this; m_childItems.insert(position, item); return true; @@ -143,7 +139,7 @@ bool QtMessageLogItem::detachChild(int position) QtMessageLogHandler::QtMessageLogHandler(QObject *parent) : QAbstractItemModel(parent), m_hasEditableRow(false), - m_rootItem(new QtMessageLogItem()), + m_rootItem(new QtMessageLogItem(0)), m_maxSizeOfFileName(0) { } @@ -157,8 +153,8 @@ void QtMessageLogHandler::clear() { beginResetModel(); reset(); - delete m_rootItem; - m_rootItem = new QtMessageLogItem(); + qDeleteAll(m_rootItem->m_childItems); + m_rootItem->m_childItems.clear(); endResetModel(); if (m_hasEditableRow) @@ -180,7 +176,7 @@ bool QtMessageLogHandler::appendItem(QtMessageLogItem *item, int position) bool QtMessageLogHandler::appendMessage(QtMessageLogHandler::ItemType itemType, const QString &message, int position) { - return appendItem(new QtMessageLogItem(itemType, message), position); + return appendItem(new QtMessageLogItem(m_rootItem, itemType, message), position); } void QtMessageLogHandler::setHasEditableRow(bool hasEditableRow) @@ -202,7 +198,7 @@ bool QtMessageLogHandler::hasEditableRow() const void QtMessageLogHandler::appendEditableRow() { int position = m_rootItem->childCount(); - if (appendItem(new QtMessageLogItem(QtMessageLogHandler::InputType), position)) + if (appendItem(new QtMessageLogItem(m_rootItem, QtMessageLogHandler::InputType), position)) emit selectEditableRow(index(position, 0), QItemSelectionModel::ClearAndSelect); } @@ -289,7 +285,8 @@ QModelIndex QtMessageLogHandler::parent(const QModelIndex &index) const return QModelIndex(); //can parentItem be 0? - QTC_ASSERT(parentItem, qDebug("Parent is Null!!")); + if (!parentItem) + return QModelIndex(); return createIndex(parentItem->childNumber(), 0, parentItem); } diff --git a/src/plugins/debugger/qtmessageloghandler.h b/src/plugins/debugger/qtmessageloghandler.h index 9031c8e94c31a44b8ed51a300ce23498eafa4a3b..82969eeebe7e881489623762a2779bff0aa6aee0 100644 --- a/src/plugins/debugger/qtmessageloghandler.h +++ b/src/plugins/debugger/qtmessageloghandler.h @@ -78,6 +78,8 @@ public: int sizeOfFile(const QFont &font); int sizeOfLineNumber(const QFont &font); + QtMessageLogItem *root() const { return m_rootItem; } + public slots: void clear(); @@ -116,9 +118,9 @@ private: class QtMessageLogItem { public: - QtMessageLogItem(QtMessageLogHandler::ItemType type = QtMessageLogHandler::UndefinedType, - const QString &data = QString(), - QtMessageLogItem *parent = 0); + QtMessageLogItem(QtMessageLogItem *parent, + QtMessageLogHandler::ItemType type = QtMessageLogHandler::UndefinedType, + const QString &data = QString()); ~QtMessageLogItem(); QtMessageLogItem *child(int number); @@ -139,6 +141,9 @@ public: QtMessageLogHandler::ItemType itemType; QString file; int line; + +private: + friend class QtMessageLogHandler; }; } //Internal