debugger: save a few cycles in the watchmodel

Change-Id: I56afd567361b2a65db4e0103a64540dc4305981c
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
hjk
2012-05-30 17:55:25 +02:00
committed by hjk
parent 836a13a97d
commit f5c688cadc

View File

@@ -119,20 +119,23 @@ static QByteArray stripForFormat(const QByteArray &ba)
// destruction of items. // destruction of items.
class WatchItem; class WatchItem;
typedef QList<WatchItem *> WatchItems;
WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname); WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname);
void itemDestructor(WatchModel *model, WatchItem *item); void itemDestructor(WatchModel *model, WatchItem *item);
class WatchItem : public WatchData class WatchItem : public WatchData
{ {
public: public:
WatchItem *parent; WatchItem *parent; // Not owned.
QList<WatchItem *> children; WatchItems children; // Not owned. Handled via itemDestructor().
bool modified;
private: private:
friend WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname); friend WatchItem *itemConstructor(WatchModel *model, const QByteArray &iname);
friend void itemDestructor(WatchModel *model, WatchItem *item); friend void itemDestructor(WatchModel *model, WatchItem *item);
WatchItem() { parent = 0; } WatchItem() { parent = 0; modified = false; }
~WatchItem() {} ~WatchItem() {}
WatchItem(const WatchItem &); // Not implemented. WatchItem(const WatchItem &); // Not implemented.
}; };
@@ -175,6 +178,8 @@ private:
void fetchMore(const QModelIndex &parent); void fetchMore(const QModelIndex &parent);
void invalidateAll(const QModelIndex &parentIndex = QModelIndex()); void invalidateAll(const QModelIndex &parentIndex = QModelIndex());
void unmodifyTree(WatchItem *item);
WatchItem *createItem(const QByteArray &iname, const QString &name, WatchItem *parent); WatchItem *createItem(const QByteArray &iname, const QString &name, WatchItem *parent);
friend class WatchHandler; friend class WatchHandler;
@@ -192,7 +197,7 @@ private:
void reinitialize(); void reinitialize();
void destroyItem(WatchItem *item); // With model notification. void destroyItem(WatchItem *item); // With model notification.
void destroyChildren(WatchItem *item); // With model notification. void destroyChildren(WatchItem *item); // With model notification.
void destroyHelper(const QList<WatchItem *> &items); // Without model notification. void destroyHelper(const WatchItems &items); // Without model notification.
void emitDataChanged(int column, void emitDataChanged(int column,
const QModelIndex &parentIndex = QModelIndex()); const QModelIndex &parentIndex = QModelIndex());
@@ -347,7 +352,7 @@ void WatchModel::dumpHelper(WatchItem *item)
dumpHelper(child); dumpHelper(child);
} }
void WatchModel::destroyHelper(const QList<WatchItem *> &items) void WatchModel::destroyHelper(const WatchItems &items)
{ {
for (int i = items.size(); --i >= 0; ) { for (int i = items.size(); --i >= 0; ) {
WatchItem *item = items.at(i); WatchItem *item = items.at(i);
@@ -387,7 +392,7 @@ void WatchModel::destroyChildren(WatchItem *item)
if (item->children.isEmpty()) if (item->children.isEmpty())
return; return;
QList<WatchItem *> items = item->children; WatchItems items = item->children;
// Deregister from model and parent. // Deregister from model and parent.
// It's sufficient to do this non-recursively. // It's sufficient to do this non-recursively.
@@ -767,16 +772,18 @@ QModelIndex WatchModel::parent(const QModelIndex &idx) const
return QModelIndex(); return QModelIndex();
const WatchItem *item = watchItem(idx); const WatchItem *item = watchItem(idx);
if (!item->parent || item->parent == m_root) const WatchItem *father = watchItem(idx);
if (!father || father == m_root)
return QModelIndex(); return QModelIndex();
const WatchItem *grandparent = item->parent->parent; const WatchItem *grandparent = father->parent;
if (!grandparent) if (!grandparent)
return QModelIndex(); return QModelIndex();
for (int i = 0; i < grandparent->children.size(); ++i) const WatchItems &uncles = grandparent->children;
if (grandparent->children.at(i) == item->parent) for (int i = 0, n = uncles.size(); i < n; ++i)
return createIndex(i, 0, (void*) item->parent); if (uncles.at(i) == father)
return createIndex(i, 0, (void*) father);
return QModelIndex(); return QModelIndex();
} }
@@ -851,6 +858,15 @@ void WatchModel::invalidateAll(const QModelIndex &parentIndex)
emit dataChanged(idx1, idx2); emit dataChanged(idx1, idx2);
} }
void WatchModel::unmodifyTree(WatchItem *item)
{
item->modified = false;
const WatchItems &items = item->children;
for (int i = items.size(); --i >= 0; )
unmodifyTree(items.at(i));
}
// Truncate value for item view, maintaining quotes. // Truncate value for item view, maintaining quotes.
static QString truncateValue(QString v) static QString truncateValue(QString v)
{ {