forked from qt-creator/qt-creator
Debugger: Rewrite logic to use signals on DebuggerItemManager
Change-Id: I82e1cd3cca9cc2d79366e1af054640dadebf7871 Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
@@ -101,7 +101,6 @@ static void readDebuggers(const FileName &fileName, bool isSystem)
|
||||
}
|
||||
|
||||
QList<DebuggerItem> DebuggerItemManager::m_debuggers;
|
||||
Internal::DebuggerItemModel* DebuggerItemManager::m_model = 0;
|
||||
PersistentSettingsWriter * DebuggerItemManager::m_writer = 0;
|
||||
|
||||
DebuggerItemManager::DebuggerItemManager(QObject *parent)
|
||||
@@ -109,7 +108,6 @@ DebuggerItemManager::DebuggerItemManager(QObject *parent)
|
||||
{
|
||||
m_instance = this;
|
||||
m_writer = new PersistentSettingsWriter(userSettingsFileName(), QLatin1String("QtCreatorDebugger"));
|
||||
m_model = new Debugger::Internal::DebuggerItemModel(this);
|
||||
connect(Core::ICore::instance(), SIGNAL(saveSettingsRequested()),
|
||||
this, SLOT(saveDebuggers()));
|
||||
}
|
||||
@@ -131,11 +129,6 @@ QList<DebuggerItem> DebuggerItemManager::debuggers()
|
||||
return m_debuggers;
|
||||
}
|
||||
|
||||
Internal::DebuggerItemModel *DebuggerItemManager::model()
|
||||
{
|
||||
return m_model;
|
||||
}
|
||||
|
||||
void DebuggerItemManager::autoDetectCdbDebuggers()
|
||||
{
|
||||
QList<FileName> cdbs;
|
||||
@@ -344,39 +337,28 @@ void DebuggerItemManager::saveDebuggers()
|
||||
|
||||
QVariant DebuggerItemManager::registerDebugger(const DebuggerItem &item)
|
||||
{
|
||||
if (const DebuggerItem *orig = findById(item.id())) {
|
||||
QVariant id = orig->id();
|
||||
if (*orig == item)
|
||||
return id;
|
||||
removeDebugger(id);
|
||||
addDebugger(item);
|
||||
emit m_instance->debuggerUpdated(id);
|
||||
return id;
|
||||
}
|
||||
QTC_ASSERT(!findById(item.id()), return item.id());
|
||||
|
||||
QVariant id = addDebugger(item);
|
||||
emit m_instance->debuggerAdded(id);
|
||||
return id;
|
||||
return addDebugger(item);
|
||||
}
|
||||
|
||||
void DebuggerItemManager::deregisterDebugger(const DebuggerItem &item)
|
||||
{
|
||||
if (findById(item.id())) {
|
||||
emit m_instance->aboutToRemoveDebugger(item.id());
|
||||
QTC_ASSERT(!item.command().isEmpty(), return);
|
||||
QTC_ASSERT(!item.displayName().isEmpty(), return);
|
||||
QTC_ASSERT(item.engineType() != NoEngineType, return);
|
||||
|
||||
if (findById(item.id()))
|
||||
removeDebugger(item.id());
|
||||
emit m_instance->removeDebugger(item.id());
|
||||
}
|
||||
}
|
||||
|
||||
QVariant DebuggerItemManager::addDebugger(const DebuggerItem &item)
|
||||
{
|
||||
QTC_ASSERT(!item.command().isEmpty(), return QVariant());
|
||||
QTC_ASSERT(!item.displayName().isEmpty(), return QVariant());
|
||||
QTC_ASSERT(item.engineType() != NoEngineType, return QVariant());
|
||||
QTC_ASSERT(item.id().isValid(), return QVariant());
|
||||
m_debuggers.append(item);
|
||||
m_model->addDebugger(item);
|
||||
return item.id();
|
||||
QVariant id = item.id();
|
||||
emit m_instance->debuggerAdded(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
void DebuggerItemManager::removeDebugger(const QVariant &id)
|
||||
@@ -384,14 +366,15 @@ void DebuggerItemManager::removeDebugger(const QVariant &id)
|
||||
bool ok = false;
|
||||
for (int i = 0, n = m_debuggers.size(); i != n; ++i) {
|
||||
if (m_debuggers.at(i).id() == id) {
|
||||
emit m_instance->aboutToRemoveDebugger(id);
|
||||
m_debuggers.removeAt(i);
|
||||
emit m_instance->debuggerRemoved(id);
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QTC_ASSERT(ok, return);
|
||||
m_model->removeDebugger(id);
|
||||
}
|
||||
|
||||
QString DebuggerItemManager::uniqueDisplayName(const QString &base)
|
||||
@@ -411,7 +394,7 @@ void DebuggerItemManager::setItemData(const QVariant &id, const QString &display
|
||||
item.setDisplayName(displayName);
|
||||
item.setCommand(fileName);
|
||||
item.reinitializeFromFile();
|
||||
emit m_model->updateDebugger(item.id());
|
||||
emit m_instance->debuggerUpdated(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,17 +55,16 @@ public:
|
||||
~DebuggerItemManager();
|
||||
|
||||
static QList<DebuggerItem> debuggers();
|
||||
static Debugger::Internal::DebuggerItemModel *model();
|
||||
|
||||
static QVariant registerDebugger(const DebuggerItem &item);
|
||||
static void deregisterDebugger(const DebuggerItem &item);
|
||||
static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName);
|
||||
|
||||
static const DebuggerItem *findByCommand(const Utils::FileName &command);
|
||||
static const DebuggerItem *findById(const QVariant &id);
|
||||
|
||||
static void restoreDebuggers();
|
||||
static QString uniqueDisplayName(const QString &base);
|
||||
static void setItemData(const QVariant &id, const QString& displayName, const Utils::FileName &fileName);
|
||||
|
||||
static void removeDebugger(const QVariant &id);
|
||||
static QVariant addDebugger(const DebuggerItem &item);
|
||||
@@ -87,7 +86,6 @@ private:
|
||||
|
||||
static Utils::PersistentSettingsWriter *m_writer;
|
||||
static QList<DebuggerItem> m_debuggers;
|
||||
static Debugger::Internal::DebuggerItemModel *m_model;
|
||||
|
||||
friend class Internal::DebuggerItemModel;
|
||||
friend class DebuggerPlugin; // Enable constrcutor for DebuggerPlugin
|
||||
|
||||
@@ -84,6 +84,17 @@ DebuggerItemModel::DebuggerItemModel(QObject *parent)
|
||||
row = createRow(tr("Manual"));
|
||||
m_manualRoot = row.at(0);
|
||||
appendRow(row);
|
||||
|
||||
foreach (const DebuggerItem &item, DebuggerItemManager::debuggers())
|
||||
addDebugger(item);
|
||||
|
||||
QObject *manager = DebuggerItemManager::instance();
|
||||
connect(manager, SIGNAL(debuggerAdded(QVariant)),
|
||||
this, SLOT(onDebuggerAdded(QVariant)));
|
||||
connect(manager, SIGNAL(debuggerUpdated(QVariant)),
|
||||
this, SLOT(onDebuggerUpdate(QVariant)));
|
||||
connect(manager, SIGNAL(debuggerRemoved(QVariant)),
|
||||
this, SLOT(onDebuggerRemoval(QVariant)));
|
||||
}
|
||||
|
||||
QVariant DebuggerItemModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
@@ -143,12 +154,28 @@ void DebuggerItemModel::markCurrentDirty()
|
||||
sitem->setFont(font);
|
||||
}
|
||||
|
||||
void DebuggerItemModel::onDebuggerAdded(const QVariant &id)
|
||||
{
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(id);
|
||||
QTC_ASSERT(item, return);
|
||||
addDebugger(*item);
|
||||
}
|
||||
|
||||
void DebuggerItemModel::onDebuggerUpdate(const QVariant &id)
|
||||
{
|
||||
updateDebugger(id);
|
||||
}
|
||||
|
||||
void DebuggerItemModel::onDebuggerRemoval(const QVariant &id)
|
||||
{
|
||||
removeDebugger(id);
|
||||
}
|
||||
|
||||
void DebuggerItemModel::addDebugger(const DebuggerItem &item)
|
||||
{
|
||||
QTC_ASSERT(item.id().isValid(), return);
|
||||
QList<QStandardItem *> row = describeItem(item);
|
||||
(item.isAutoDetected() ? m_autoRoot : m_manualRoot)->appendRow(row);
|
||||
emit debuggerAdded(item.id(), item.displayName());
|
||||
}
|
||||
|
||||
void DebuggerItemModel::removeDebugger(const QVariant &id)
|
||||
@@ -160,7 +187,6 @@ void DebuggerItemModel::removeDebugger(const QVariant &id)
|
||||
// This will trigger a change of m_currentDebugger via changing the
|
||||
// view selection.
|
||||
parent->removeRow(sitem->row());
|
||||
emit debuggerRemoved(id);
|
||||
}
|
||||
|
||||
void DebuggerItemModel::updateDebugger(const QVariant &id)
|
||||
@@ -182,7 +208,6 @@ void DebuggerItemModel::updateDebugger(const QVariant &id)
|
||||
parent->child(row, 1)->setFont(font);
|
||||
parent->child(row, 2)->setData(item.engineTypeName(), Qt::DisplayRole);
|
||||
parent->child(row, 2)->setFont(font);
|
||||
emit debuggerUpdated(id, item.displayName());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class DebuggerItemModel : public QStandardItemModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DebuggerItemModel(QObject *parent);
|
||||
DebuggerItemModel(QObject *parent = 0);
|
||||
|
||||
QModelIndex currentIndex() const;
|
||||
QModelIndex lastIndex() const;
|
||||
@@ -60,19 +60,12 @@ public:
|
||||
public slots:
|
||||
void markCurrentDirty();
|
||||
|
||||
signals:
|
||||
void debuggerAdded(const QVariant &id, const QString &display);
|
||||
void debuggerUpdated(const QVariant &id, const QString &display);
|
||||
void debuggerRemoved(const QVariant &id);
|
||||
private slots:
|
||||
void onDebuggerAdded(const QVariant &id);
|
||||
void onDebuggerUpdate(const QVariant &id);
|
||||
void onDebuggerRemoval(const QVariant &id);
|
||||
|
||||
private:
|
||||
// <debug>
|
||||
// friend class Debugger::DebuggerKitInformation;
|
||||
// friend class DebuggerKitConfigWidget;
|
||||
// friend class DebuggerItemConfigWidget;
|
||||
// friend class DebuggerOptionsPage;
|
||||
// </debug>
|
||||
|
||||
QStandardItem *currentStandardItem() const;
|
||||
QStandardItem *findStandardItemById(const QVariant &id) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
#include "debuggeritemmanager.h"
|
||||
#include "debuggeritemmodel.h"
|
||||
#include "debuggerkitinformation.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
@@ -78,9 +79,6 @@ class DebuggerItemConfigWidget;
|
||||
DebuggerKitConfigWidget::DebuggerKitConfigWidget(Kit *workingCopy, const KitInformation *ki)
|
||||
: KitConfigWidget(workingCopy, ki)
|
||||
{
|
||||
DebuggerItemModel *model = DebuggerItemManager::model();
|
||||
QTC_CHECK(model);
|
||||
|
||||
m_comboBox = new QComboBox;
|
||||
m_comboBox->setEnabled(true);
|
||||
m_comboBox->setToolTip(toolTip());
|
||||
@@ -95,11 +93,12 @@ DebuggerKitConfigWidget::DebuggerKitConfigWidget(Kit *workingCopy, const KitInfo
|
||||
m_manageButton->setContentsMargins(0, 0, 0, 0);
|
||||
connect(m_manageButton, SIGNAL(clicked()), this, SLOT(manageDebuggers()));
|
||||
|
||||
connect(model, SIGNAL(debuggerAdded(QVariant,QString)),
|
||||
this, SLOT(onDebuggerAdded(QVariant,QString)));
|
||||
connect(model, SIGNAL(debuggerUpdated(QVariant,QString)),
|
||||
this, SLOT(onDebuggerUpdated(QVariant,QString)));
|
||||
connect(model, SIGNAL(debuggerRemoved(QVariant)),
|
||||
QObject *manager = DebuggerItemManager::instance();
|
||||
connect(manager, SIGNAL(debuggerAdded(QVariant)),
|
||||
this, SLOT(onDebuggerAdded(QVariant)));
|
||||
connect(manager, SIGNAL(debuggerUpdated(QVariant)),
|
||||
this, SLOT(onDebuggerUpdated(QVariant)));
|
||||
connect(manager, SIGNAL(debuggerRemoved(QVariant)),
|
||||
this, SLOT(onDebuggerRemoved(QVariant)));
|
||||
}
|
||||
|
||||
@@ -154,20 +153,22 @@ void DebuggerKitConfigWidget::currentDebuggerChanged(int)
|
||||
m_kit->setValue(DebuggerKitInformation::id(), id);
|
||||
}
|
||||
|
||||
void DebuggerKitConfigWidget::onDebuggerAdded(const QVariant &id, const QString &displayName)
|
||||
void DebuggerKitConfigWidget::onDebuggerAdded(const QVariant &id)
|
||||
{
|
||||
m_comboBox->setEnabled(true);
|
||||
m_comboBox->addItem(displayName, id);
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(id);
|
||||
QTC_ASSERT(item, return);
|
||||
m_comboBox->addItem(item->displayName(), id);
|
||||
updateComboBox(id);
|
||||
}
|
||||
|
||||
void DebuggerKitConfigWidget::onDebuggerUpdated(const QVariant &id, const QString &displayName)
|
||||
void DebuggerKitConfigWidget::onDebuggerUpdated(const QVariant &id)
|
||||
{
|
||||
m_comboBox->setEnabled(true);
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(id);
|
||||
QTC_ASSERT(item, return);
|
||||
const int pos = indexOf(id);
|
||||
if (pos < 0)
|
||||
return;
|
||||
m_comboBox->setItemText(pos, displayName);
|
||||
m_comboBox->setItemText(pos, item->displayName());
|
||||
}
|
||||
|
||||
void DebuggerKitConfigWidget::onDebuggerRemoved(const QVariant &id)
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#ifndef DEBUGGER_DEBUGGERKITCONFIGWIDGET_H
|
||||
#define DEBUGGER_DEBUGGERKITCONFIGWIDGET_H
|
||||
|
||||
#include "debuggerkitinformation.h"
|
||||
#include "debuggeritemmodel.h"
|
||||
|
||||
#include <coreplugin/dialogs/ioptionspage.h>
|
||||
#include <projectexplorer/kitconfigwidget.h>
|
||||
@@ -75,8 +75,8 @@ public:
|
||||
private slots:
|
||||
void manageDebuggers();
|
||||
void currentDebuggerChanged(int idx);
|
||||
void onDebuggerAdded(const QVariant &id, const QString &displayName);
|
||||
void onDebuggerUpdated(const QVariant &id, const QString &displayName);
|
||||
void onDebuggerAdded(const QVariant &id);
|
||||
void onDebuggerUpdated(const QVariant &id);
|
||||
void onDebuggerRemoved(const QVariant &id);
|
||||
|
||||
private:
|
||||
|
||||
@@ -63,7 +63,7 @@ class DebuggerItemConfigWidget : public QWidget
|
||||
Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::DebuggerItemConfigWidget)
|
||||
|
||||
public:
|
||||
explicit DebuggerItemConfigWidget();
|
||||
explicit DebuggerItemConfigWidget(DebuggerItemModel *model);
|
||||
void loadItem();
|
||||
void saveItem();
|
||||
void connectDirty();
|
||||
@@ -74,10 +74,14 @@ private:
|
||||
QLabel *m_cdbLabel;
|
||||
PathChooser *m_binaryChooser;
|
||||
QLineEdit *m_abis;
|
||||
DebuggerItemModel *m_model;
|
||||
};
|
||||
|
||||
DebuggerItemConfigWidget::DebuggerItemConfigWidget()
|
||||
DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) :
|
||||
m_model(model)
|
||||
{
|
||||
QTC_CHECK(model);
|
||||
|
||||
m_displayNameLineEdit = new QLineEdit(this);
|
||||
|
||||
m_binaryChooser = new PathChooser(this);
|
||||
@@ -104,26 +108,23 @@ DebuggerItemConfigWidget::DebuggerItemConfigWidget()
|
||||
|
||||
void DebuggerItemConfigWidget::connectDirty()
|
||||
{
|
||||
DebuggerItemModel *model = DebuggerItemManager::model();
|
||||
connect(m_displayNameLineEdit, SIGNAL(textChanged(QString)),
|
||||
model, SLOT(markCurrentDirty()));
|
||||
m_model, SLOT(markCurrentDirty()));
|
||||
connect(m_binaryChooser, SIGNAL(changed(QString)),
|
||||
model, SLOT(markCurrentDirty()));
|
||||
m_model, SLOT(markCurrentDirty()));
|
||||
}
|
||||
|
||||
void DebuggerItemConfigWidget::disconnectDirty()
|
||||
{
|
||||
DebuggerItemModel *model = DebuggerItemManager::model();
|
||||
disconnect(m_displayNameLineEdit, SIGNAL(textChanged(QString)),
|
||||
model, SLOT(markCurrentDirty()));
|
||||
m_model, SLOT(markCurrentDirty()));
|
||||
disconnect(m_binaryChooser, SIGNAL(changed(QString)),
|
||||
model, SLOT(markCurrentDirty()));
|
||||
m_model, SLOT(markCurrentDirty()));
|
||||
}
|
||||
|
||||
void DebuggerItemConfigWidget::loadItem()
|
||||
{
|
||||
DebuggerItemModel *model = DebuggerItemManager::model();
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(model->currentDebugger());
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger());
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
@@ -163,8 +164,7 @@ void DebuggerItemConfigWidget::loadItem()
|
||||
|
||||
void DebuggerItemConfigWidget::saveItem()
|
||||
{
|
||||
DebuggerItemModel *model = DebuggerItemManager::model();
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(model->currentDebugger());
|
||||
const DebuggerItem *item = DebuggerItemManager::findById(m_model->currentDebugger());
|
||||
QTC_ASSERT(item, return);
|
||||
DebuggerItemManager::setItemData(item->id(), m_displayNameLineEdit->text(),
|
||||
m_binaryChooser->fileName());
|
||||
@@ -203,7 +203,7 @@ QWidget *DebuggerOptionsPage::createPage(QWidget *parent)
|
||||
m_container->setState(DetailsWidget::NoSummary);
|
||||
m_container->setVisible(false);
|
||||
|
||||
m_model = DebuggerItemManager::model();
|
||||
m_model = new DebuggerItemModel(parent);
|
||||
|
||||
m_debuggerView = new QTreeView(m_configWidget);
|
||||
m_debuggerView->setModel(m_model);
|
||||
@@ -243,7 +243,7 @@ QWidget *DebuggerOptionsPage::createPage(QWidget *parent)
|
||||
|
||||
m_searchKeywords = tr("Debuggers");
|
||||
|
||||
m_itemConfigWidget = new DebuggerItemConfigWidget;
|
||||
m_itemConfigWidget = new DebuggerItemConfigWidget(m_model);
|
||||
m_container->setWidget(m_itemConfigWidget);
|
||||
|
||||
updateState();
|
||||
|
||||
Reference in New Issue
Block a user