diff --git a/src/plugins/debugger/gdb/gdbengine.cpp b/src/plugins/debugger/gdb/gdbengine.cpp index 5bd2327e44c8959a51578fc28d02d301ccd517f8..4819a126189134811d9f21d819f7a22960298510 100644 --- a/src/plugins/debugger/gdb/gdbengine.cpp +++ b/src/plugins/debugger/gdb/gdbengine.cpp @@ -3418,8 +3418,10 @@ void GdbEngine::handleDebuggingHelperValue2(const GdbResultRecord &record, setWatchDataType(childtemplate, contents.findChild("childtype")); setWatchDataChildCount(childtemplate, contents.findChild("childnumchild")); //qDebug() << "DATA:" << data.toString(); - insertData(data); + + qq->watchHandler()->insertData(data); int i = 0; + QList<WatchData> list; foreach (GdbMi item, children.children()) { WatchData data1 = childtemplate; GdbMi name = item.findChild("name"); @@ -3454,9 +3456,10 @@ void GdbEngine::handleDebuggingHelperValue2(const GdbResultRecord &record, if (!qq->watchHandler()->isExpandedIName(data1.iname)) data1.setChildrenUnneeded(); //qDebug() << "HANDLE CUSTOM SUBCONTENTS:" << data1.toString(); - insertData(data1); + list.append(data1); ++i; } + qq->watchHandler()->insertBulkData(list); } void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record, diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 99dad9ace00624c4831fde4e7ee188c1685adf33..1aab5ebc60a11445edb5f0a5fe37c1bbe57c95d9 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -750,10 +750,15 @@ QVariant WatchModel::headerData(int section, Qt::Orientation orientation, int ro return QVariant(); } -static bool iNameSorter(const WatchItem *item1, const WatchItem *item2) +struct IName : public QString { - QString name1 = item1->iname.section('.', -1); - QString name2 = item2->iname.section('.', -1); + IName(const QString &iname) : QString(iname) {} +}; + +bool operator<(const IName &iname1, const IName &iname2) +{ + QString name1 = iname1.section('.', -1); + QString name2 = iname2.section('.', -1); if (!name1.isEmpty() && !name2.isEmpty()) { if (name1.at(0).isDigit() && name2.at(0).isDigit()) return name1.toInt() < name2.toInt(); @@ -761,6 +766,12 @@ static bool iNameSorter(const WatchItem *item1, const WatchItem *item2) return name1 < name2; } + +static bool iNameSorter(const WatchItem *item1, const WatchItem *item2) +{ + return IName(item1->iname) < IName(item2->iname); +} + static int findInsertPosition(const QList<WatchItem *> &list, const WatchItem *item) { QList<WatchItem *>::const_iterator it = @@ -806,6 +817,63 @@ void WatchModel::insertData(const WatchData &data) } } +void WatchModel::insertBulkData(const QList<WatchData> &list) +{ + // qDebug() << "WMI:" << list.toString(); + QTC_ASSERT(!list.isEmpty(), return); + QString parentIName = parentName(list.at(0).iname); + WatchItem *parent = findItem(parentIName, m_root); + if (!parent) { + WatchData parent; + parent.iname = parentIName; + insertData(parent); + MODEL_DEBUG("\nFIXING MISSING PARENT FOR\n" << list.at(0).iname); + return; + } + QModelIndex index = watchIndex(parent); + + QMap<IName, WatchData> newList; + typedef QMap<IName, WatchData>::iterator Iterator; + foreach (const WatchItem &data, list) + newList[data.iname] = data; + + foreach (WatchItem *oldItem, parent->children) { + Iterator it = newList.find(oldItem->iname); + if (it == newList.end()) { + newList[oldItem->iname] = *oldItem; + } else { + bool changed = !it->value.isEmpty() + && it->value != oldItem->value + && it->value != strNotInScope; + it->changed = changed; + it->generation = generationCounter; + } + } + + // overwrite existing items + Iterator it = newList.begin(); + int oldCount = newList.size() - list.size(); + QTC_ASSERT(oldCount == parent->children.size(), return); + for (int i = 0; i < oldCount; ++i, ++it) + parent->children[i]->setData(*it); + QModelIndex idx = watchIndex(parent); + emit dataChanged(idx.sibling(0, 0), idx.sibling(oldCount - 1, 2)); + + // add new items + if (oldCount < newList.size()) { + beginInsertRows(index, oldCount, newList.size() - 1); + //MODEL_DEBUG("INSERT : " << data.iname << data.value); + for (int i = oldCount; i < newList.size(); ++i, ++it) { + WatchItem *item = new WatchItem(*it); + item->parent = parent; + item->generation = generationCounter; + item->changed = true; + parent->children.append(item); + } + endInsertRows(); + } +} + WatchItem *WatchModel::findItem(const QString &iname, WatchItem *root) const { if (root->iname == iname) @@ -874,6 +942,26 @@ void WatchHandler::insertData(const WatchData &data) } } +// bulk-insertion +void WatchHandler::insertBulkData(const QList<WatchData> &list) +{ + if (list.isEmpty()) + return; + QHash<QString, QList<WatchData> > hash; + + foreach (const WatchData &data, list) { + if (data.isSomethingNeeded()) + emit watchDataUpdateNeeded(data); + else + hash[parentName(data.iname)].append(data); + } + foreach (const QString &parentIName, hash.keys()) { + WatchModel *model = modelForIName(parentIName); + QTC_ASSERT(model, return); + model->insertBulkData(hash[parentIName]); + } +} + void WatchHandler::removeData(const QString &iname) { WatchModel *model = modelForIName(iname); @@ -1109,9 +1197,9 @@ WatchModel *WatchHandler::model(WatchType type) const WatchModel *WatchHandler::modelForIName(const QString &iname) const { - if (iname.startsWith(QLatin1String("local."))) + if (iname.startsWith(QLatin1String("local"))) return m_locals; - if (iname.startsWith(QLatin1String("watch."))) + if (iname.startsWith(QLatin1String("watch"))) return m_watchers; if (iname.startsWith(QLatin1String("tooltip"))) return m_tooltips; diff --git a/src/plugins/debugger/watchhandler.h b/src/plugins/debugger/watchhandler.h index 6b71540d8a57e100d4385881535b5de88b15a366..10ec730bfe7965132b5850eaba40f614ede256be 100644 --- a/src/plugins/debugger/watchhandler.h +++ b/src/plugins/debugger/watchhandler.h @@ -189,6 +189,7 @@ private: const WatchItem *parentItem, const QModelIndex &parentIndex) const; void insertData(const WatchData &data); + void insertBulkData(const QList<WatchData> &data); WatchItem *findItem(const QString &iname, WatchItem *root) const; void reinitialize(); void removeOutdated(); @@ -228,6 +229,7 @@ public: void showEditValue(const WatchData &data); void insertData(const WatchData &data); + void insertBulkData(const QList<WatchData> &data); void removeData(const QString &iname); WatchData *findItem(const QString &iname) const;