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 <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-08-30 09:56:51 +02:00
parent cc198547e9
commit a93760c789
2 changed files with 20 additions and 12 deletions

View File

@@ -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)

View File

@@ -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<ThreadItem>;
using ThreadsHandlerModel = Utils::TreeModel<Utils::TypedTreeItem<ThreadItem>, ThreadItem>;
class ThreadsHandler : public Utils::TreeModel<Utils::TypedTreeItem<ThreadItem>, 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;