summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2018-08-31 18:30:14 +0200
committerhjk <hjk@qt.io>2018-09-03 11:37:17 +0000
commit86cd29b13c5489e67dcbfa223ac3519a9c4c520c (patch)
tree4ff1b75a85c3f357681e0d2b895bd56ba3db445c
parent944aa963a8bf8b61828b6dc2ed268b8d8d10e7b7 (diff)
downloadqt-creator-86cd29b13c5489e67dcbfa223ac3519a9c4c520c.tar.gz
Debugger: Simplify thread switching more
This moves the thread switcher combobox, the only consumer of part of the threadhandler interface, into the threadhandler. Change-Id: Icafd72e7777fad9196ce8fb33a79cae26c29a521 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/debugger/cdb/cdbengine.cpp2
-rw-r--r--src/plugins/debugger/debuggerengine.cpp33
-rw-r--r--src/plugins/debugger/debuggerengine.h1
-rw-r--r--src/plugins/debugger/threadshandler.cpp19
-rw-r--r--src/plugins/debugger/threadshandler.h5
5 files changed, 21 insertions, 39 deletions
diff --git a/src/plugins/debugger/cdb/cdbengine.cpp b/src/plugins/debugger/cdb/cdbengine.cpp
index 10038fecd6..74a0339278 100644
--- a/src/plugins/debugger/cdb/cdbengine.cpp
+++ b/src/plugins/debugger/cdb/cdbengine.cpp
@@ -1496,7 +1496,7 @@ void CdbEngine::requestModuleSymbols(const QString &moduleName)
void CdbEngine::reloadRegisters()
{
- if (!(threadsHandler()->currentThreadIndex() >= 0))
+ if (!threadsHandler()->currentThread())
return;
runCommand({"registers", ExtensionCommand, CB(handleRegistersExt)});
}
diff --git a/src/plugins/debugger/debuggerengine.cpp b/src/plugins/debugger/debuggerengine.cpp
index 9fed9ac586..0b6a6d55f0 100644
--- a/src/plugins/debugger/debuggerengine.cpp
+++ b/src/plugins/debugger/debuggerengine.cpp
@@ -394,12 +394,6 @@ public:
m_toolTipManager.resetLocation();
}
- void selectThread(int index)
- {
- const Thread thread = m_engine->threadsHandler()->rootItem()->childAt(index);
- m_engine->doSelectThread(thread);
- }
-
void handleOperateByInstructionTriggered(bool on)
{
// Go to source only if we have the file.
@@ -485,7 +479,6 @@ public:
QPointer<LocalsAndInspectorWindow> m_localsAndInspectorWindow;
QPointer<QLabel> m_threadLabel;
- QPointer<QComboBox> m_threadBox;
bool m_busy = false;
bool m_isDying = false;
@@ -746,14 +739,7 @@ void DebuggerEnginePrivate::setupViews()
m_threadLabel = new QLabel(tr("Threads:"));
m_perspective->addToolBarWidget(m_threadLabel);
-
- m_threadBox = new QComboBox;
- m_threadBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
- m_threadBox->setModel(m_threadsHandler.model());
- connect(m_threadBox, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated),
- this, &DebuggerEnginePrivate::selectThread);
-
- m_perspective->addToolBarWidget(m_threadBox);
+ m_perspective->addToolBarWidget(m_threadsHandler.threadSwitcher());
connect(TextEditorSettings::instance(), &TextEditorSettings::fontSettingsChanged,
this, [this](const FontSettings &settings) {
@@ -1321,8 +1307,6 @@ void DebuggerEnginePrivate::updateState(bool alsoUpdateCompanion)
{
if (!m_perspective)
return;
- QTC_ASSERT(m_threadBox, return);
- m_threadBox->setCurrentIndex(m_threadsHandler.currentThreadIndex());
const DebuggerState state = m_state;
const bool companionPreventsAction = m_engine->companionPreventsActions();
@@ -1410,8 +1394,9 @@ void DebuggerEnginePrivate::updateState(bool alsoUpdateCompanion)
m_attachToCoreAction.setEnabled(true);
m_attachToRemoteServerAction.setEnabled(true);
- m_threadBox->setEnabled(state == InferiorStopOk || state == InferiorUnrunnable);
- m_threadLabel->setEnabled(m_threadBox->isEnabled());
+ const bool threadsEnabled = state == InferiorStopOk || state == InferiorUnrunnable;
+ m_threadsHandler.threadSwitcher()->setEnabled(threadsEnabled);
+ m_threadLabel->setEnabled(threadsEnabled);
const bool isCore = m_engine->runParameters().startMode == AttachCore;
const bool stopped = state == InferiorStopOk;
@@ -2078,16 +2063,6 @@ void DebuggerEngine::assignValueInDebugger(WatchItem *,
{
}
-void DebuggerEngine::doSelectThread(const Thread &thread)
-{
- QTC_ASSERT(thread, return);
- // For immediate visual feedback.
- d->m_threadsHandler.setCurrentThread(thread);
- d->m_threadBox->setCurrentIndex(d->m_threadsHandler.currentThreadIndex());
- // Initiate the actual switching in the debugger backend.
- selectThread(thread);
-}
-
void DebuggerEngine::handleRecordReverse(bool record)
{
executeRecordReverse(record);
diff --git a/src/plugins/debugger/debuggerengine.h b/src/plugins/debugger/debuggerengine.h
index def30d2c04..ec5ae85f0e 100644
--- a/src/plugins/debugger/debuggerengine.h
+++ b/src/plugins/debugger/debuggerengine.h
@@ -317,7 +317,6 @@ public:
virtual void assignValueInDebugger(WatchItem *item,
const QString &expr, const QVariant &value);
virtual void selectThread(const Internal::Thread &thread) = 0;
- void doSelectThread(const Internal::Thread &thread);
virtual void executeRecordReverse(bool) {}
virtual void executeReverse(bool) {}
diff --git a/src/plugins/debugger/threadshandler.cpp b/src/plugins/debugger/threadshandler.cpp
index e7b00fbbac..2770d02e9b 100644
--- a/src/plugins/debugger/threadshandler.cpp
+++ b/src/plugins/debugger/threadshandler.cpp
@@ -221,6 +221,13 @@ ThreadsHandler::ThreadsHandler(DebuggerEngine *engine)
tr("Address"), tr("Function"), tr("File"), tr("Line"), tr("State"),
tr("Name"), tr("Target ID"), tr("Details"), tr("Core"),
});
+
+ m_comboBox = new QComboBox;
+ m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+ m_comboBox->setModel(this);
+ connect(m_comboBox, QOverload<int>::of(&QComboBox::activated), this, [this](int row) {
+ setData(index(row, 0), {}, BaseTreeView::ItemActivatedRole);
+ });
}
QVariant ThreadsHandler::data(const QModelIndex &index, int role) const
@@ -240,8 +247,11 @@ bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int r
{
if (role == BaseTreeView::ItemActivatedRole) {
const Thread thread = itemForIndexAtLevel<1>(idx);
- if (thread != m_currentThread)
- m_engine->doSelectThread(thread);
+ if (thread != m_currentThread) {
+ m_currentThread = thread;
+ m_comboBox->setCurrentIndex(idx.row());
+ m_engine->selectThread(thread);
+ }
return true;
}
@@ -259,11 +269,6 @@ bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int r
return false;
}
-int ThreadsHandler::currentThreadIndex() const
-{
- return rootItem()->indexOf(m_currentThread);
-}
-
void ThreadsHandler::sort(int column, Qt::SortOrder order)
{
rootItem()->sortChildren([order, column](const ThreadItem *item1, const ThreadItem *item2) -> bool {
diff --git a/src/plugins/debugger/threadshandler.h b/src/plugins/debugger/threadshandler.h
index db20dd95c6..5c8cb189c4 100644
--- a/src/plugins/debugger/threadshandler.h
+++ b/src/plugins/debugger/threadshandler.h
@@ -29,6 +29,7 @@
#include <utils/treemodel.h>
+#include <QComboBox>
#include <QPointer>
////////////////////////////////////////////////////////////////////////
@@ -77,7 +78,6 @@ class ThreadsHandler : public ThreadsHandlerModel
public:
explicit ThreadsHandler(DebuggerEngine *engine);
- int currentThreadIndex() const;
Thread currentThread() const;
Thread threadForId(const QString &id) const;
void setCurrentThread(const Thread &thread);
@@ -95,6 +95,8 @@ public:
void notifyRunning(const QString &id);
void notifyStopped(const QString &id);
+ QComboBox *threadSwitcher() { return m_comboBox; }
+
private:
void sort(int column, Qt::SortOrder order) override;
QVariant data(const QModelIndex &index, int role) const override;
@@ -103,6 +105,7 @@ private:
DebuggerEngine *m_engine;
Thread m_currentThread;
QHash<QString, QString> m_pidForGroupId;
+ QComboBox *m_comboBox;
};
} // namespace Internal