debugger: insert all children of WatchData as a single block

This commit is contained in:
hjk
2009-07-13 12:28:47 +02:00
parent e9d0285fbc
commit 25716914a5
3 changed files with 100 additions and 7 deletions

View File

@@ -3418,8 +3418,10 @@ void GdbEngine::handleDebuggingHelperValue2(const GdbResultRecord &record,
setWatchDataType(childtemplate, contents.findChild("childtype")); setWatchDataType(childtemplate, contents.findChild("childtype"));
setWatchDataChildCount(childtemplate, contents.findChild("childnumchild")); setWatchDataChildCount(childtemplate, contents.findChild("childnumchild"));
//qDebug() << "DATA:" << data.toString(); //qDebug() << "DATA:" << data.toString();
insertData(data);
qq->watchHandler()->insertData(data);
int i = 0; int i = 0;
QList<WatchData> list;
foreach (GdbMi item, children.children()) { foreach (GdbMi item, children.children()) {
WatchData data1 = childtemplate; WatchData data1 = childtemplate;
GdbMi name = item.findChild("name"); GdbMi name = item.findChild("name");
@@ -3454,9 +3456,10 @@ void GdbEngine::handleDebuggingHelperValue2(const GdbResultRecord &record,
if (!qq->watchHandler()->isExpandedIName(data1.iname)) if (!qq->watchHandler()->isExpandedIName(data1.iname))
data1.setChildrenUnneeded(); data1.setChildrenUnneeded();
//qDebug() << "HANDLE CUSTOM SUBCONTENTS:" << data1.toString(); //qDebug() << "HANDLE CUSTOM SUBCONTENTS:" << data1.toString();
insertData(data1); list.append(data1);
++i; ++i;
} }
qq->watchHandler()->insertBulkData(list);
} }
void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record, void GdbEngine::handleDebuggingHelperValue3(const GdbResultRecord &record,

View File

@@ -750,10 +750,15 @@ QVariant WatchModel::headerData(int section, Qt::Orientation orientation, int ro
return QVariant(); return QVariant();
} }
static bool iNameSorter(const WatchItem *item1, const WatchItem *item2) struct IName : public QString
{ {
QString name1 = item1->iname.section('.', -1); IName(const QString &iname) : QString(iname) {}
QString name2 = item2->iname.section('.', -1); };
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.isEmpty() && !name2.isEmpty()) {
if (name1.at(0).isDigit() && name2.at(0).isDigit()) if (name1.at(0).isDigit() && name2.at(0).isDigit())
return name1.toInt() < name2.toInt(); return name1.toInt() < name2.toInt();
@@ -761,6 +766,12 @@ static bool iNameSorter(const WatchItem *item1, const WatchItem *item2)
return name1 < name2; 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) static int findInsertPosition(const QList<WatchItem *> &list, const WatchItem *item)
{ {
QList<WatchItem *>::const_iterator it = 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 WatchItem *WatchModel::findItem(const QString &iname, WatchItem *root) const
{ {
if (root->iname == iname) 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) void WatchHandler::removeData(const QString &iname)
{ {
WatchModel *model = modelForIName(iname); WatchModel *model = modelForIName(iname);
@@ -1109,9 +1197,9 @@ WatchModel *WatchHandler::model(WatchType type) const
WatchModel *WatchHandler::modelForIName(const QString &iname) const WatchModel *WatchHandler::modelForIName(const QString &iname) const
{ {
if (iname.startsWith(QLatin1String("local."))) if (iname.startsWith(QLatin1String("local")))
return m_locals; return m_locals;
if (iname.startsWith(QLatin1String("watch."))) if (iname.startsWith(QLatin1String("watch")))
return m_watchers; return m_watchers;
if (iname.startsWith(QLatin1String("tooltip"))) if (iname.startsWith(QLatin1String("tooltip")))
return m_tooltips; return m_tooltips;

View File

@@ -189,6 +189,7 @@ private:
const WatchItem *parentItem, const QModelIndex &parentIndex) const; const WatchItem *parentItem, const QModelIndex &parentIndex) const;
void insertData(const WatchData &data); void insertData(const WatchData &data);
void insertBulkData(const QList<WatchData> &data);
WatchItem *findItem(const QString &iname, WatchItem *root) const; WatchItem *findItem(const QString &iname, WatchItem *root) const;
void reinitialize(); void reinitialize();
void removeOutdated(); void removeOutdated();
@@ -228,6 +229,7 @@ public:
void showEditValue(const WatchData &data); void showEditValue(const WatchData &data);
void insertData(const WatchData &data); void insertData(const WatchData &data);
void insertBulkData(const QList<WatchData> &data);
void removeData(const QString &iname); void removeData(const QString &iname);
WatchData *findItem(const QString &iname) const; WatchData *findItem(const QString &iname) const;