WatchHandler: Move generationCounter to individual WatchModels

Change-Id: I39cdd48ed02cbcf6702076245c765cb6c8926c1b
Reviewed-on: http://codereview.qt-project.org/4429
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
Aurindam Jana
2011-09-08 12:22:13 +02:00
committed by hjk
parent 2db7393234
commit 84364b7884
3 changed files with 27 additions and 24 deletions

View File

@@ -498,7 +498,7 @@ void IPCEngineHost::rpcCallback(quint64 f, QByteArray payload)
break; break;
wh->beginCycle(fullCycle); wh->beginCycle(fullCycle);
wh->insertBulkData(wd); wh->insertBulkData(wd);
wh->endCycle(fullCycle); wh->endCycle();
} }
break; break;
case IPCEngineGuest::NotifyAddBreakpointOk: case IPCEngineGuest::NotifyAddBreakpointOk:

View File

@@ -71,9 +71,6 @@ enum { debugModel = 0 };
#define MODEL_DEBUG(s) do { if (debugModel) qDebug() << s; } while (0) #define MODEL_DEBUG(s) do { if (debugModel) qDebug() << s; } while (0)
#define MODEL_DEBUGX(s) qDebug() << s #define MODEL_DEBUGX(s) qDebug() << s
static int watcherCounter = 0;
static int generationCounter = 0;
QHash<QByteArray, int> WatchHandler::m_watcherNames; QHash<QByteArray, int> WatchHandler::m_watcherNames;
QHash<QByteArray, int> WatchHandler::m_typeFormats; QHash<QByteArray, int> WatchHandler::m_typeFormats;
@@ -132,7 +129,8 @@ public:
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
WatchModel::WatchModel(WatchHandler *handler, WatchType type) WatchModel::WatchModel(WatchHandler *handler, WatchType type)
: QAbstractItemModel(handler), m_handler(handler), m_type(type) : QAbstractItemModel(handler), m_handler(handler), m_type(type),
m_generationCounter(0)
{ {
m_root = new WatchItem; m_root = new WatchItem;
m_root->hasChildren = 1; m_root->hasChildren = 1;
@@ -188,8 +186,11 @@ void WatchModel::emitAllChanged()
emit layoutChanged(); emit layoutChanged();
} }
void WatchModel::beginCycle() void WatchModel::beginCycle(bool fullCycle)
{ {
if (fullCycle)
m_generationCounter++;
emit enableUpdates(false); emit enableUpdates(false);
} }
@@ -234,7 +235,7 @@ void WatchModel::removeOutdated()
void WatchModel::removeOutdatedHelper(WatchItem *item) void WatchModel::removeOutdatedHelper(WatchItem *item)
{ {
if (item->generation < generationCounter) { if (item->generation < m_generationCounter) {
destroyItem(item); destroyItem(item);
} else { } else {
foreach (WatchItem *child, item->children) foreach (WatchItem *child, item->children)
@@ -1011,7 +1012,7 @@ void WatchModel::insertData(const WatchData &data)
// Overwrite old entry. // Overwrite old entry.
oldItem->setData(data); oldItem->setData(data);
oldItem->changed = data.hasChanged(*oldItem); oldItem->changed = data.hasChanged(*oldItem);
oldItem->generation = generationCounter; oldItem->generation = m_generationCounter;
QModelIndex idx = watchIndex(oldItem); QModelIndex idx = watchIndex(oldItem);
emit dataChanged(idx, idx.sibling(idx.row(), 2)); emit dataChanged(idx, idx.sibling(idx.row(), 2));
@@ -1029,7 +1030,7 @@ void WatchModel::insertData(const WatchData &data)
// Add new entry. // Add new entry.
WatchItem *item = new WatchItem(data); WatchItem *item = new WatchItem(data);
item->parent = parent; item->parent = parent;
item->generation = generationCounter; item->generation = m_generationCounter;
item->changed = true; item->changed = true;
const int n = findInsertPosition(parent->children, item); const int n = findInsertPosition(parent->children, item);
beginInsertRows(index, n, n); beginInsertRows(index, n, n);
@@ -1091,12 +1092,12 @@ void WatchModel::insertBulkData(const QList<WatchData> &list)
Iterator it = newList.find(oldSortKey); Iterator it = newList.find(oldSortKey);
if (it == newList.end()) { if (it == newList.end()) {
WatchData data = *oldItem; WatchData data = *oldItem;
data.generation = generationCounter; data.generation = m_generationCounter;
newList.insert(oldSortKey, data); newList.insert(oldSortKey, data);
} else { } else {
it->changed = it->hasChanged(*oldItem); it->changed = it->hasChanged(*oldItem);
if (it->generation == -1) if (it->generation == -1)
it->generation = generationCounter; it->generation = m_generationCounter;
} }
} }
@@ -1114,7 +1115,7 @@ void WatchModel::insertBulkData(const QList<WatchData> &list)
<< " WITH " << it->iname << it->generation; << " WITH " << it->iname << it->generation;
parent->children[i]->setData(*it); parent->children[i]->setData(*it);
if (parent->children[i]->generation == -1) if (parent->children[i]->generation == -1)
parent->children[i]->generation = generationCounter; parent->children[i]->generation = m_generationCounter;
//emit dataChanged(idx.sibling(i, 0), idx.sibling(i, 2)); //emit dataChanged(idx.sibling(i, 0), idx.sibling(i, 2));
} else { } else {
//qDebug() << "SKIPPING REPLACEMENT" << parent->children.at(i)->iname; //qDebug() << "SKIPPING REPLACEMENT" << parent->children.at(i)->iname;
@@ -1131,7 +1132,7 @@ void WatchModel::insertBulkData(const QList<WatchData> &list)
qDebug() << "ADDING" << it->iname; qDebug() << "ADDING" << it->iname;
item->parent = parent; item->parent = parent;
if (item->generation == -1) if (item->generation == -1)
item->generation = generationCounter; item->generation = m_generationCounter;
item->changed = true; item->changed = true;
parent->children.append(item); parent->children.append(item);
} }
@@ -1184,6 +1185,7 @@ void WatchModel::formatRequests(QByteArray *out, const WatchItem *item) const
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
WatchHandler::WatchHandler(DebuggerEngine *engine) WatchHandler::WatchHandler(DebuggerEngine *engine)
: m_watcherCounter(0)
{ {
m_engine = engine; m_engine = engine;
m_inChange = false; m_inChange = false;
@@ -1203,15 +1205,13 @@ WatchHandler::WatchHandler(DebuggerEngine *engine)
void WatchHandler::beginCycle(bool fullCycle) void WatchHandler::beginCycle(bool fullCycle)
{ {
if (fullCycle) m_return->beginCycle(fullCycle);
++generationCounter; m_locals->beginCycle(fullCycle);
m_return->beginCycle(); m_watchers->beginCycle(fullCycle);
m_locals->beginCycle(); m_tooltips->beginCycle(fullCycle);
m_watchers->beginCycle();
m_tooltips->beginCycle();
} }
void WatchHandler::endCycle(bool /*fullCycle*/) void WatchHandler::endCycle()
{ {
m_return->endCycle(); m_return->endCycle();
m_locals->endCycle(); m_locals->endCycle();
@@ -1346,7 +1346,7 @@ void WatchHandler::watchExpression(const QString &exp)
WatchData data; WatchData data;
data.exp = exp.toLatin1(); data.exp = exp.toLatin1();
data.name = exp; data.name = exp;
m_watcherNames[data.exp] = watcherCounter++; m_watcherNames[data.exp] = m_watcherCounter++;
saveWatchers(); saveWatchers();
if (exp.isEmpty()) if (exp.isEmpty())
@@ -1469,7 +1469,7 @@ void WatchHandler::clearWatches()
for (int i = watches.size() - 1; i >= 0; i--) for (int i = watches.size() - 1; i >= 0; i--)
m_watchers->destroyItem(watches.at(i)); m_watchers->destroyItem(watches.at(i));
m_watcherNames.clear(); m_watcherNames.clear();
watcherCounter = 0; m_watcherCounter = 0;
updateWatchersWindow(); updateWatchersWindow();
emitAllChanged(); emitAllChanged();
saveWatchers(); saveWatchers();

View File

@@ -107,7 +107,7 @@ private:
void emitDataChanged(int column, void emitDataChanged(int column,
const QModelIndex &parentIndex = QModelIndex()); const QModelIndex &parentIndex = QModelIndex());
void beginCycle(); // Called at begin of updateLocals() cycle. void beginCycle(bool fullCycle); // Called at begin of updateLocals() cycle.
void endCycle(); // Called after all results have been received. void endCycle(); // Called after all results have been received.
friend QDebug operator<<(QDebug d, const WatchModel &m); friend QDebug operator<<(QDebug d, const WatchModel &m);
@@ -127,6 +127,7 @@ private:
void formatRequests(QByteArray *out, const WatchItem *item) const; void formatRequests(QByteArray *out, const WatchItem *item) const;
DebuggerEngine *engine() const; DebuggerEngine *engine() const;
int itemFormat(const WatchData &data) const; int itemFormat(const WatchData &data) const;
int m_generationCounter;
WatchHandler *m_handler; WatchHandler *m_handler;
WatchType m_type; WatchType m_type;
@@ -151,7 +152,7 @@ public:
void beginCycle(bool fullCycle = true); // Called at begin of updateLocals() cycle void beginCycle(bool fullCycle = true); // Called at begin of updateLocals() cycle
void updateWatchers(); // Called after locals are fetched void updateWatchers(); // Called after locals are fetched
void endCycle(bool fullCycle = true); // Called after all results have been received void endCycle(); // Called after all results have been received
void showEditValue(const WatchData &data); void showEditValue(const WatchData &data);
void insertData(const WatchData &data); void insertData(const WatchData &data);
@@ -220,6 +221,8 @@ private:
WatchModel *m_watchers; WatchModel *m_watchers;
WatchModel *m_tooltips; WatchModel *m_tooltips;
DebuggerEngine *m_engine; DebuggerEngine *m_engine;
int m_watcherCounter;
}; };
} // namespace Internal } // namespace Internal