From 6ab4adabf3923630bdd98e4a39ba6615ed79ee4d Mon Sep 17 00:00:00 2001 From: hjk <hjk121@nokiamail.com> Date: Wed, 27 Nov 2013 12:32:43 +0100 Subject: [PATCH] Debugger: Prevent overwriting of pre-defined Abi values Todo: Add a button to rescan ABIs to UI after UI freeze. Currently you have to change the debugger command and then change it back when replacing a debugger with a debugger for something else in place. Task-number: QTCREATORBUG-10755 Change-Id: Id3cf1da3f198b60e6c538e5478b11f1d6d379ff9 Reviewed-by: hjk <hjk121@nokiamail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com> --- src/plugins/debugger/debuggeritem.h | 4 +- src/plugins/debugger/debuggeritemmanager.cpp | 16 +++-- src/plugins/debugger/debuggeroptionspage.cpp | 72 ++++++++++++-------- src/plugins/debugger/debuggeroptionspage.h | 42 +++++++++++- 4 files changed, 99 insertions(+), 35 deletions(-) diff --git a/src/plugins/debugger/debuggeritem.h b/src/plugins/debugger/debuggeritem.h index 5802b23f81b..c7d9d707771 100644 --- a/src/plugins/debugger/debuggeritem.h +++ b/src/plugins/debugger/debuggeritem.h @@ -42,6 +42,7 @@ namespace Debugger { +class DebuggerItemManager; namespace Internal { class DebuggerItemConfigWidget; class DebuggerItemModel; @@ -63,7 +64,6 @@ public: QString engineTypeName() const; QVariantMap toMap() const; - void reinitializeFromFile(); QVariant id() const { return m_id; } @@ -92,6 +92,7 @@ public: private: DebuggerItem(const QVariant &id); + void reinitializeFromFile(); QVariant m_id; QString m_displayName; @@ -102,6 +103,7 @@ private: friend class Internal::DebuggerItemConfigWidget; friend class Internal::DebuggerItemModel; + friend class DebuggerItemManager; }; } // namespace Debugger diff --git a/src/plugins/debugger/debuggeritemmanager.cpp b/src/plugins/debugger/debuggeritemmanager.cpp index cef2fd529a3..552018bd98b 100644 --- a/src/plugins/debugger/debuggeritemmanager.cpp +++ b/src/plugins/debugger/debuggeritemmanager.cpp @@ -433,10 +433,18 @@ void DebuggerItemManager::setItemData(const QVariant &id, const QString &display for (int i = 0, n = m_debuggers.size(); i != n; ++i) { DebuggerItem &item = m_debuggers[i]; if (item.id() == id) { - item.setDisplayName(displayName); - item.setCommand(fileName); - item.reinitializeFromFile(); - emit m_instance->debuggerUpdated(id); + bool changed = false; + if (item.displayName() != displayName) { + item.setDisplayName(displayName); + changed = true; + } + if (item.command() != fileName) { + item.setCommand(fileName); + item.reinitializeFromFile(); + changed = true; + } + if (changed) + emit m_instance->debuggerUpdated(id); break; } } diff --git a/src/plugins/debugger/debuggeroptionspage.cpp b/src/plugins/debugger/debuggeroptionspage.cpp index da42957d65a..ef89a2d35d3 100644 --- a/src/plugins/debugger/debuggeroptionspage.cpp +++ b/src/plugins/debugger/debuggeroptionspage.cpp @@ -39,6 +39,7 @@ #include <utils/qtcassert.h> #include <utils/winutils.h> +#include <QFileInfo> #include <QFormLayout> #include <QHeaderView> #include <QLabel> @@ -59,26 +60,6 @@ static const char debuggingToolsWikiLinkC[] = "http://qt-project.org/wiki/Qt_Cre // DebuggerItemConfigWidget // ----------------------------------------------------------------------- -class DebuggerItemConfigWidget : public QWidget -{ - Q_DECLARE_TR_FUNCTIONS(Debugger::Internal::DebuggerItemConfigWidget) - -public: - explicit DebuggerItemConfigWidget(DebuggerItemModel *model); - DebuggerItem store() const; - void setItem(const DebuggerItem &item); - void apply(); - -private: - QLineEdit *m_displayNameLineEdit; - QLabel *m_cdbLabel; - PathChooser *m_binaryChooser; - QLineEdit *m_abis; - DebuggerItemModel *m_model; - bool m_autodetected; - QVariant m_id; -}; - DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) : m_model(model) { @@ -90,6 +71,7 @@ DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) : m_binaryChooser->setExpectedKind(PathChooser::ExistingCommand); m_binaryChooser->setMinimumWidth(400); m_binaryChooser->setHistoryCompleter(QLatin1String("DebuggerPaths")); + connect(m_binaryChooser, SIGNAL(changed(QString)), this, SLOT(commandWasChanged())); m_cdbLabel = new QLabel(this); m_cdbLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); @@ -107,7 +89,7 @@ DebuggerItemConfigWidget::DebuggerItemConfigWidget(DebuggerItemModel *model) : formLayout->addRow(new QLabel(tr("ABIs:")), m_abis); } -DebuggerItem DebuggerItemConfigWidget::store() const +DebuggerItem DebuggerItemConfigWidget::item() const { DebuggerItem item(m_id); if (m_id.isNull()) @@ -116,11 +98,28 @@ DebuggerItem DebuggerItemConfigWidget::store() const item.setDisplayName(m_displayNameLineEdit->text()); item.setCommand(m_binaryChooser->fileName()); item.setAutoDetected(m_autodetected); - item.reinitializeFromFile(); - m_model->updateDebugger(item); + QList<ProjectExplorer::Abi> abiList; + foreach (const QString &a, m_abis->text().split(QRegExp(QLatin1String("[^A-Za-z0-9-_]+")))) { + ProjectExplorer::Abi abi(a); + if (a.isNull()) + continue; + abiList << a; + } + item.setAbis(abiList); return item; } + +void DebuggerItemConfigWidget::store() const +{ + m_model->updateDebugger(item()); +} + +void DebuggerItemConfigWidget::setAbis(const QStringList &abiNames) +{ + m_abis->setText(abiNames.join(QLatin1String(", "))); +} + void DebuggerItemConfigWidget::setItem(const DebuggerItem &item) { store(); // store away the (changed) settings for future use @@ -157,17 +156,34 @@ void DebuggerItemConfigWidget::setItem(const DebuggerItem &item) m_cdbLabel->setVisible(!text.isEmpty()); m_binaryChooser->setCommandVersionArguments(QStringList(versionCommand)); - m_abis->setText(item.abiNames().join(QLatin1String(", "))); + setAbis(item.abiNames()); } void DebuggerItemConfigWidget::apply() { - DebuggerItem item = m_model->currentDebugger(); - if (!item.isValid()) + DebuggerItem current = m_model->currentDebugger(); + if (!current.isValid()) return; // Nothing was selected here. - item = store(); - setItem(item); + store(); + setItem(item()); +} + +void DebuggerItemConfigWidget::commandWasChanged() +{ + // Use DebuggerItemManager as a cache: + const DebuggerItem *existing + = DebuggerItemManager::findByCommand(m_binaryChooser->fileName()); + if (existing) { + setAbis(existing->abiNames()); + } else { + QFileInfo fi = QFileInfo(m_binaryChooser->path()); + if (fi.isExecutable()) { + DebuggerItem tmp = item(); + tmp.reinitializeFromFile(); + setAbis(tmp.abiNames()); + } + } } // -------------------------------------------------------------------------- diff --git a/src/plugins/debugger/debuggeroptionspage.h b/src/plugins/debugger/debuggeroptionspage.h index fd1782f4b47..9eff612759a 100644 --- a/src/plugins/debugger/debuggeroptionspage.h +++ b/src/plugins/debugger/debuggeroptionspage.h @@ -30,15 +30,23 @@ #ifndef DEBUGGER_DEBUGGEROPTIONSPAGE_H #define DEBUGGER_DEBUGGEROPTIONSPAGE_H +#include "debuggeritem.h" + #include <coreplugin/dialogs/ioptionspage.h> +#include <QWidget> + QT_BEGIN_NAMESPACE +class QLabel; +class QLineEdit; class QPushButton; class QTreeView; -class QWidget; QT_END_NAMESPACE -namespace Utils { class DetailsWidget; } +namespace Utils { +class DetailsWidget; +class PathChooser; +} // namespace Utils namespace Debugger { namespace Internal { @@ -47,6 +55,36 @@ class DebuggerItemModel; class DebuggerItemConfigWidget; class DebuggerKitConfigWidget; +// ----------------------------------------------------------------------- +// DebuggerItemConfigWidget +// ----------------------------------------------------------------------- + +class DebuggerItemConfigWidget : public QWidget +{ + Q_OBJECT + +public: + explicit DebuggerItemConfigWidget(DebuggerItemModel *model); + void setItem(const DebuggerItem &item); + void apply(); + +private slots: + void commandWasChanged(); + +private: + DebuggerItem item() const; + void store() const; + void setAbis(const QStringList &abiNames); + + QLineEdit *m_displayNameLineEdit; + QLabel *m_cdbLabel; + Utils::PathChooser *m_binaryChooser; + QLineEdit *m_abis; + DebuggerItemModel *m_model; + bool m_autodetected; + QVariant m_id; +}; + // -------------------------------------------------------------------------- // DebuggerOptionsPage // -------------------------------------------------------------------------- -- GitLab