From a93760c7890720b46d62b7803569a24948c05a4d Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 30 Aug 2018 09:56:51 +0200 Subject: [PATCH] Debugger: Move handling of currentThread to thread handler Make the individual thread items more agnostic of their environment. The result is closer to the break handler setup. Change-Id: I1a3f6138e5f32e930313e07d3c6a37144c180050 Reviewed-by: Christian Stenger --- src/plugins/debugger/threadshandler.cpp | 25 ++++++++++++++++--------- src/plugins/debugger/threadshandler.h | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/plugins/debugger/threadshandler.cpp b/src/plugins/debugger/threadshandler.cpp index acb3c4f35b7..8148cf3f1d5 100644 --- a/src/plugins/debugger/threadshandler.cpp +++ b/src/plugins/debugger/threadshandler.cpp @@ -55,8 +55,8 @@ namespace Internal { // ThreadItem -ThreadItem::ThreadItem(const ThreadsHandler *handler, const ThreadData &data) - : threadData(data), handler(handler) +ThreadItem::ThreadItem(const ThreadData &data) + : threadData(data) {} QVariant ThreadItem::data(int column, int role) const @@ -68,12 +68,6 @@ QVariant ThreadItem::data(int column, int role) const return threadPart(column); case Qt::ToolTipRole: return threadToolTip(); - case Qt::DecorationRole: - // Return icon that indicates whether this is the active stack frame. - if (column == 0) - return this == handler->currentThread() ? Icons::LOCATION.icon() - : Icons::EMPTY.icon(); - break; default: break; } @@ -229,6 +223,19 @@ ThreadsHandler::ThreadsHandler(DebuggerEngine *engine) }); } +QVariant ThreadsHandler::data(const QModelIndex &index, int role) const +{ + if (role == Qt::DecorationRole && index.column() == 0) { + // Return icon that indicates whether this is the active thread. + TreeItem *item = itemForIndex(index); + if (item && item == m_currentThread) + return Icons::LOCATION.icon(); + return Icons::EMPTY.icon(); + } + + return ThreadsHandlerModel::data(index, role); +} + bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int role) { if (role == BaseTreeView::ItemActivatedRole) { @@ -310,7 +317,7 @@ void ThreadsHandler::updateThread(const ThreadData &threadData) if (Thread thread = threadForId(threadData.id)) thread->mergeThreadData(threadData); else - rootItem()->appendChild(new ThreadItem(this, threadData)); + rootItem()->appendChild(new ThreadItem(threadData)); } void ThreadsHandler::removeThread(const QString &id) diff --git a/src/plugins/debugger/threadshandler.h b/src/plugins/debugger/threadshandler.h index d071d02fac1..1cae5cfc265 100644 --- a/src/plugins/debugger/threadshandler.h +++ b/src/plugins/debugger/threadshandler.h @@ -49,7 +49,7 @@ class ThreadItem : public QObject, public Utils::TreeItem Q_OBJECT public: - ThreadItem(const ThreadsHandler *handler, const ThreadData &data = ThreadData()); + ThreadItem(const ThreadData &data = ThreadData()); QVariant data(int column, int role) const override; Qt::ItemFlags flags(int column) const override; @@ -65,12 +65,12 @@ public: public: ThreadData threadData; - const ThreadsHandler * const handler; }; using Thread = QPointer; +using ThreadsHandlerModel = Utils::TreeModel, ThreadItem>; -class ThreadsHandler : public Utils::TreeModel, ThreadItem> +class ThreadsHandler : public ThreadsHandlerModel { Q_OBJECT @@ -102,6 +102,7 @@ public: private: void sort(int column, Qt::SortOrder order) override; + QVariant data(const QModelIndex &index, int role) const override; bool setData(const QModelIndex &idx, const QVariant &data, int role) override; DebuggerEngine *m_engine;