From 57c0cc8f95e99e4937b0d8166d76a3ea3209175d Mon Sep 17 00:00:00 2001 From: Peter Lohrmann Date: Wed, 28 Jan 2015 13:49:24 -0800 Subject: [PATCH] glvdebug: Refactor column index logic in QGroupThreadsProxyModel. * Centralize where the column index comparison happens to make reading the code easier. * Also a helper function for coverting a proxy column index into a 'thread #' column index. --- .../glvdebug/glvdebug_qgroupthreadsproxymodel.h | 54 +++++++++++----------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/tools/glave/src/glvdebug/glvdebug_qgroupthreadsproxymodel.h b/tools/glave/src/glvdebug/glvdebug_qgroupthreadsproxymodel.h index 09fc0e4..0dd3de8 100644 --- a/tools/glave/src/glvdebug/glvdebug_qgroupthreadsproxymodel.h +++ b/tools/glave/src/glvdebug/glvdebug_qgroupthreadsproxymodel.h @@ -128,9 +128,9 @@ public: { return firstResult.data(role); } - else if (index.column() >= sourceModel()->columnCount()) + else if (isThreadColumn(index.column())) { - int threadIndex = index.column() - sourceModel()->columnCount(); + int threadIndex = getThreadColumnIndex(index.column()); return QString("%1").arg(m_uniqueThreadIdMapToColumn.key(threadIndex)); } @@ -146,9 +146,9 @@ public: { return QVariant(QString("Thread %1").arg(m_groupList[index.row()].threadId)); } - else if (index.column() >= sourceModel()->columnCount()) + else if (isThreadColumn(index.column())) { - int threadIndex = index.column() - sourceModel()->columnCount(); + int threadIndex = getThreadColumnIndex(index.column()); return QString("%1").arg(m_uniqueThreadIdMapToColumn.key(threadIndex)); } else @@ -175,7 +175,7 @@ public: //--------------------------------------------------------------------------------------------- virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const { - if (section < sourceModel()->columnCount()) + if (!isThreadColumn(section)) { return sourceModel()->headerData(section, orientation, role); } @@ -183,7 +183,7 @@ public: { if (role == Qt::DisplayRole) { - int threadIndex = section - sourceModel()->columnCount(); + int threadIndex = getThreadColumnIndex(section); return QString("Thread %1").arg(threadIndex); } } @@ -235,26 +235,16 @@ public: { if (!isGroup(child)) { -// if (child.column() >= sourceModel()->columnCount()) -// { -// // this is a Thread column -// // TODO: Need to find the proper parent -//// QModelIndex sibling = m_groupList[child.row -// return QModelIndex(); -// } -// else + QModelIndex result = m_mapProxyToParent[child.column()].value(child); + if (result.isValid()) { - QModelIndex result = m_mapProxyToParent[child.column()].value(child); - if (result.isValid()) - { - return result; - } - else - { - // parent is a frame - int frameIndex = (int)child.internalId(); - return createIndex(frameIndex, 0, (void*)&m_groupList[frameIndex]); - } + return result; + } + else + { + // parent is a frame + int frameIndex = (int)child.internalId(); + return createIndex(frameIndex, 0, (void*)&m_groupList[frameIndex]); } } } @@ -269,7 +259,7 @@ public: return QModelIndex(); QModelIndex result; - if (proxyIndex.column() < sourceModel()->columnCount()) + if (!isThreadColumn(proxyIndex.column())) { // it is a column for the source model and not for one of our thread IDs (which isn't in the source, unless we map it to the same Thread Id column?) result = m_mapProxyToSrc[proxyIndex.column()].value(proxyIndex); @@ -338,6 +328,18 @@ private: } //--------------------------------------------------------------------------------------------- + bool isThreadColumn(int columnIndex) const + { + return (columnIndex >= sourceModel()->columnCount()); + } + + //--------------------------------------------------------------------------------------------- + int getThreadColumnIndex(int proxyColumnIndex) const + { + return proxyColumnIndex - sourceModel()->columnCount(); + } + + //--------------------------------------------------------------------------------------------- void addNewGroup(uint32_t threadId) { // create frame info -- 2.7.4