forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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)});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user