Debugger: Use a QPointer for the thread switcher

... and (re)create it on demand. That covers the case of a restart
of the debugger engine in which case the original switcher was
destroyed together with the toolbar of the original perspective.

Change-Id: I6180411a37aea46438809a5ff65e5526f9db2a03
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2018-11-07 09:23:16 +01:00
parent 70b466b7d9
commit 790a86d508
2 changed files with 21 additions and 9 deletions

View File

@@ -221,13 +221,11 @@ 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);
});
ThreadsHandler::~ThreadsHandler()
{
delete m_comboBox;
}
QVariant ThreadsHandler::data(const QModelIndex &index, int role) const
@@ -249,7 +247,7 @@ bool ThreadsHandler::setData(const QModelIndex &idx, const QVariant &data, int r
const Thread thread = itemForIndexAtLevel<1>(idx);
if (thread != m_currentThread) {
m_currentThread = thread;
m_comboBox->setCurrentIndex(idx.row());
threadSwitcher()->setCurrentIndex(idx.row());
m_engine->selectThread(thread);
}
return true;
@@ -364,6 +362,19 @@ void ThreadsHandler::notifyStopped(const QString &id)
thread->notifyStopped();
}
QPointer<QComboBox> ThreadsHandler::threadSwitcher()
{
if (!m_comboBox) {
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);
});
}
return m_comboBox;
}
void ThreadsHandler::setThreads(const GdbMi &data)
{
rootItem()->removeChildren();