From 5e5d840b53945697a6d7201452a4da446e6749f4 Mon Sep 17 00:00:00 2001 From: hjk Date: Wed, 4 Sep 2013 18:39:43 +0200 Subject: [PATCH] Debugger: Streamline settings access pattern Change-Id: Ie73b8d9fa945ee9dcbab67177410cc782979c8ad Reviewed-by: David Schulz --- src/plugins/debugger/breakhandler.cpp | 4 +- src/plugins/debugger/commonoptionspage.cpp | 5 +- src/plugins/debugger/debuggeractions.cpp | 16 ++-- src/plugins/debugger/debuggeractions.h | 15 +--- src/plugins/debugger/debuggercore.h | 9 ++- src/plugins/debugger/debuggerdialogs.cpp | 3 +- src/plugins/debugger/debuggerdialogs.h | 3 +- src/plugins/debugger/debuggerplugin.cpp | 73 ++++++++----------- .../debugger/debuggertooltipmanager.cpp | 4 +- src/plugins/debugger/watchhandler.cpp | 17 ++--- 10 files changed, 64 insertions(+), 85 deletions(-) diff --git a/src/plugins/debugger/breakhandler.cpp b/src/plugins/debugger/breakhandler.cpp index df1b121116d..2e37685a7db 100644 --- a/src/plugins/debugger/breakhandler.cpp +++ b/src/plugins/debugger/breakhandler.cpp @@ -335,7 +335,7 @@ void BreakHandler::saveBreakpoints() map.insert(_("message"), data.message); list.append(map); } - debuggerCore()->setSessionValue(QLatin1String("Breakpoints"), list); + DebuggerCore::setSessionValue("Breakpoints", list); //qDebug() << "SAVED BREAKPOINTS" << this << list.size(); } @@ -343,7 +343,7 @@ void BreakHandler::loadBreakpoints() { QTC_ASSERT(debuggerCore(), return); //qDebug() << "LOADING BREAKPOINTS..."; - QVariant value = debuggerCore()->sessionValue(QLatin1String("Breakpoints")); + QVariant value = DebuggerCore::sessionValue("Breakpoints"); QList list = value.toList(); //clear(); foreach (const QVariant &var, list) { diff --git a/src/plugins/debugger/commonoptionspage.cpp b/src/plugins/debugger/commonoptionspage.cpp index 8b6efe5ee64..9a0f1c834a1 100644 --- a/src/plugins/debugger/commonoptionspage.cpp +++ b/src/plugins/debugger/commonoptionspage.cpp @@ -260,13 +260,12 @@ void CommonOptionsPage::apply() { QTC_ASSERT(!m_widget.isNull() && !m_group.isNull(), return); - QSettings *settings = ICore::settings(); - m_group->apply(settings); + m_group->apply(ICore::settings()); const GlobalDebuggerOptions newGlobalOptions = m_widget->globalOptions(); if (newGlobalOptions != *m_options) { *m_options = newGlobalOptions; - m_options->toSettings(settings); + m_options->toSettings(); } } diff --git a/src/plugins/debugger/debuggeractions.cpp b/src/plugins/debugger/debuggeractions.cpp index c0422178856..e3b5549b7e7 100644 --- a/src/plugins/debugger/debuggeractions.cpp +++ b/src/plugins/debugger/debuggeractions.cpp @@ -33,6 +33,7 @@ #include "registerpostmortemaction.h" #endif +#include #include #include @@ -50,8 +51,9 @@ static const char sourcePathMappingTargetKeyC[] = "Target"; namespace Debugger { namespace Internal { -void GlobalDebuggerOptions::toSettings(QSettings *s) const +void GlobalDebuggerOptions::toSettings() const { + QSettings *s = Core::ICore::settings(); s->beginWriteArray(QLatin1String(sourcePathMappingArrayNameC)); if (!sourcePathMap.isEmpty()) { const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC); @@ -67,8 +69,9 @@ void GlobalDebuggerOptions::toSettings(QSettings *s) const s->endArray(); } -void GlobalDebuggerOptions::fromSettings(QSettings *s) +void GlobalDebuggerOptions::fromSettings() { + QSettings *s = Core::ICore::settings(); sourcePathMap.clear(); if (const int count = s->beginReadArray(QLatin1String(sourcePathMappingArrayNameC))) { const QString sourcePathMappingSourceKey = QLatin1String(sourcePathMappingSourceKeyC); @@ -88,9 +91,8 @@ void GlobalDebuggerOptions::fromSettings(QSettings *s) // ////////////////////////////////////////////////////////////////////////// -DebuggerSettings::DebuggerSettings(QSettings *settings) +DebuggerSettings::DebuggerSettings() { - m_settings = settings; const QString debugModeGroup = QLatin1String(debugModeSettingsGroupC); const QString cdbSettingsGroup = QLatin1String(cdbSettingsGroupC); @@ -667,14 +669,16 @@ void DebuggerSettings::insertItem(int code, SavedAction *item) void DebuggerSettings::readSettings() { + QSettings *settings = Core::ICore::settings(); foreach (SavedAction *item, m_items) - item->readSettings(m_settings); + item->readSettings(settings); } void DebuggerSettings::writeSettings() const { + QSettings *settings = Core::ICore::settings(); foreach (SavedAction *item, m_items) - item->writeSettings(m_settings); + item->writeSettings(settings); } SavedAction *DebuggerSettings::item(int code) const diff --git a/src/plugins/debugger/debuggeractions.h b/src/plugins/debugger/debuggeractions.h index 2abc5dddf40..f4398c5645c 100644 --- a/src/plugins/debugger/debuggeractions.h +++ b/src/plugins/debugger/debuggeractions.h @@ -34,13 +34,7 @@ #include #include -QT_BEGIN_NAMESPACE -class QSettings; -QT_END_NAMESPACE - -namespace Utils { -class SavedAction; -} +namespace Utils { class SavedAction; } namespace Debugger { namespace Internal { @@ -51,8 +45,8 @@ class GlobalDebuggerOptions public: typedef QMap SourcePathMap; - void toSettings(QSettings *) const; - void fromSettings(QSettings *); + void toSettings() const; + void fromSettings(); bool operator==(const GlobalDebuggerOptions &rhs) const { return sourcePathMap == rhs.sourcePathMap; } bool operator!=(const GlobalDebuggerOptions &rhs) const @@ -66,7 +60,7 @@ class DebuggerSettings : public QObject Q_OBJECT // For tr(). public: - explicit DebuggerSettings(QSettings *setting); + explicit DebuggerSettings(); ~DebuggerSettings(); void insertItem(int code, Utils::SavedAction *item); @@ -79,7 +73,6 @@ public: private: QHash m_items; - QSettings *m_settings; }; /////////////////////////////////////////////////////////// diff --git a/src/plugins/debugger/debuggercore.h b/src/plugins/debugger/debuggercore.h index c613f4c63df..d8119edea8b 100644 --- a/src/plugins/debugger/debuggercore.h +++ b/src/plugins/debugger/debuggercore.h @@ -81,10 +81,11 @@ class DebuggerCore : public QObject public: DebuggerCore() {} - virtual QVariant sessionValue(const QString &name) = 0; - virtual void setSessionValue(const QString &name, const QVariant &value) = 0; - virtual QVariant configValue(const QString &name) const = 0; - virtual void setConfigValue(const QString &name, const QVariant &value) = 0; + static QVariant sessionValue(const QByteArray &name); + static void setSessionValue(const QByteArray &name, const QVariant &value); + static QVariant configValue(const QByteArray &name); + static void setConfigValue(const QByteArray &name, const QVariant &value); + virtual void updateState(DebuggerEngine *engine) = 0; virtual void updateWatchersWindow(bool showWatch, bool showReturn) = 0; virtual QIcon locationMarkIcon() const = 0; diff --git a/src/plugins/debugger/debuggerdialogs.cpp b/src/plugins/debugger/debuggerdialogs.cpp index a81be93629c..5cc5d89dcf3 100644 --- a/src/plugins/debugger/debuggerdialogs.cpp +++ b/src/plugins/debugger/debuggerdialogs.cpp @@ -343,13 +343,14 @@ void StartApplicationDialog::updateState() d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(okEnabled); } -bool StartApplicationDialog::run(QWidget *parent, QSettings *settings, DebuggerStartParameters *sp) +bool StartApplicationDialog::run(QWidget *parent, DebuggerStartParameters *sp) { const bool attachRemote = sp->startMode == AttachToRemoteServer; const QString settingsGroup = QLatin1String("DebugMode"); const QString arrayName = QLatin1String("StartApplication"); QList history; + QSettings *settings = ICore::settings(); settings->beginGroup(settingsGroup); if (const int arraySize = settings->beginReadArray(arrayName)) { for (int i = 0; i < arraySize; ++i) { diff --git a/src/plugins/debugger/debuggerdialogs.h b/src/plugins/debugger/debuggerdialogs.h index df3887c2eae..385462bc3ec 100644 --- a/src/plugins/debugger/debuggerdialogs.h +++ b/src/plugins/debugger/debuggerdialogs.h @@ -82,8 +82,7 @@ public: explicit StartApplicationDialog(QWidget *parent); ~StartApplicationDialog(); - static bool run(QWidget *parent, QSettings *settings, - DebuggerStartParameters *sp); + static bool run(QWidget *parent, DebuggerStartParameters *sp); private slots: void historyIndexChanged(int); diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index e054e0e1418..b133e2594dd 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -922,9 +922,6 @@ public slots: BreakHandler *breakHandler() const { return m_breakHandler; } SnapshotHandler *snapshotHandler() const { return m_snapshotHandler; } - void setConfigValue(const QString &name, const QVariant &value); - QVariant configValue(const QString &name) const; - void displayDebugger(DebuggerEngine *engine, bool updateEngine = true); void dumpLog(); @@ -1181,8 +1178,6 @@ public slots: return m_mainWindow->activeDebugLanguages() & lang; } - QVariant sessionValue(const QString &name); - void setSessionValue(const QString &name, const QVariant &value); QIcon locationMarkIcon() const { return m_locationMarkIcon; } void openTextEditor(const QString &titlePattern0, const QString &contents); @@ -1283,7 +1278,6 @@ public: bool m_shuttingDown; DebuggerEngine *m_currentEngine; DebuggerSettings *m_debuggerSettings; - QSettings *m_coreSettings; QStringList m_arguments; DebuggerToolTipManager *m_toolTipManager; CommonOptionsPage *m_commonOptionsPage; @@ -1516,18 +1510,14 @@ bool DebuggerPluginPrivate::initialize(const QStringList &arguments, return true; } -void DebuggerPluginPrivate::setConfigValue(const QString &name, const QVariant &value) +void DebuggerCore::setConfigValue(const QByteArray &name, const QVariant &value) { - m_coreSettings->setValue(_("DebugMode/") + name, value); + ICore::settings()->setValue(_("DebugMode/" + name), value); } -QVariant DebuggerPluginPrivate::configValue(const QString &name) const +QVariant DebuggerCore::configValue(const QByteArray &name) { - const QVariant value = m_coreSettings->value(_("DebugMode/") + name); - if (value.isValid()) - return value; - // Legacy (pre-2.1): Check old un-namespaced-settings. - return m_coreSettings->value(name); + return ICore::settings()->value(_("DebugMode/" + name)); } void DebuggerPluginPrivate::onCurrentProjectChanged(Project *project) @@ -1597,7 +1587,7 @@ void DebuggerPluginPrivate::debugProjectBreakMain() void DebuggerPluginPrivate::startAndDebugApplication() { DebuggerStartParameters sp; - if (StartApplicationDialog::run(mainWindow(), m_coreSettings, &sp)) + if (StartApplicationDialog::run(mainWindow(), &sp)) DebuggerRunControlFactory::createAndScheduleRun(sp); } @@ -1605,24 +1595,24 @@ void DebuggerPluginPrivate::attachCore() { AttachCoreDialog dlg(mainWindow()); - const QString lastExternalKit = configValue(_("LastExternalKit")).toString(); + const QString lastExternalKit = configValue("LastExternalKit").toString(); if (!lastExternalKit.isEmpty()) dlg.setKitId(Id::fromString(lastExternalKit)); - dlg.setLocalExecutableFile(configValue(_("LastExternalExecutableFile")).toString()); - dlg.setLocalCoreFile(configValue(_("LastLocalCoreFile")).toString()); - dlg.setRemoteCoreFile(configValue(_("LastRemoteCoreFile")).toString()); - dlg.setOverrideStartScript(configValue(_("LastExternalStartScript")).toString()); - dlg.setForceLocalCoreFile(configValue(_("LastForceLocalCoreFile")).toBool()); + dlg.setLocalExecutableFile(configValue("LastExternalExecutableFile").toString()); + dlg.setLocalCoreFile(configValue("LastLocalCoreFile").toString()); + dlg.setRemoteCoreFile(configValue("LastRemoteCoreFile").toString()); + dlg.setOverrideStartScript(configValue("LastExternalStartScript").toString()); + dlg.setForceLocalCoreFile(configValue("LastForceLocalCoreFile").toBool()); if (dlg.exec() != QDialog::Accepted) return; - setConfigValue(_("LastExternalExecutableFile"), dlg.localExecutableFile()); - setConfigValue(_("LastLocalCoreFile"), dlg.localCoreFile()); - setConfigValue(_("LastRemoteCoreFile"), dlg.remoteCoreFile()); - setConfigValue(_("LastExternalKit"), dlg.kit()->id().toSetting()); - setConfigValue(_("LastExternalStartScript"), dlg.overrideStartScript()); - setConfigValue(_("LastForceLocalCoreFile"), dlg.forcesLocalCoreFile()); + setConfigValue("LastExternalExecutableFile", dlg.localExecutableFile()); + setConfigValue("LastLocalCoreFile", dlg.localCoreFile()); + setConfigValue("LastRemoteCoreFile", dlg.remoteCoreFile()); + setConfigValue("LastExternalKit", dlg.kit()->id().toSetting()); + setConfigValue("LastExternalStartScript", dlg.overrideStartScript()); + setConfigValue("LastForceLocalCoreFile", dlg.forcesLocalCoreFile()); DebuggerStartParameters sp; QString display = dlg.useLocalCoreFile() ? dlg.localCoreFile() : dlg.remoteCoreFile(); @@ -1639,7 +1629,7 @@ void DebuggerPluginPrivate::attachCore() void DebuggerPluginPrivate::startRemoteCdbSession() { - const QString connectionKey = _("CdbRemoteConnection"); + const QByteArray connectionKey = "CdbRemoteConnection"; DebuggerStartParameters sp; Kit *kit = CdbMatcher::findUniversalCdbKit(); QTC_ASSERT(kit && fillParameters(&sp, kit), return); @@ -1661,7 +1651,7 @@ void DebuggerPluginPrivate::attachToRemoteServer() { DebuggerStartParameters sp; sp.startMode = AttachToRemoteServer; - if (StartApplicationDialog::run(mainWindow(), m_coreSettings, &sp)) { + if (StartApplicationDialog::run(mainWindow(), &sp)) { sp.closeMode = KillAtClose; sp.serverStartScript.clear(); DebuggerRunControlFactory::createAndScheduleRun(sp); @@ -1749,13 +1739,13 @@ void DebuggerPluginPrivate::attachToQmlPort() DebuggerStartParameters sp; AttachToQmlPortDialog dlg(mainWindow()); - const QVariant qmlServerPort = configValue(_("LastQmlServerPort")); + const QVariant qmlServerPort = configValue("LastQmlServerPort"); if (qmlServerPort.isValid()) dlg.setPort(qmlServerPort.toInt()); else dlg.setPort(sp.qmlServerPort); - const Id kitId = Id::fromSetting(configValue(_("LastProfile"))); + const Id kitId = Id::fromSetting(configValue("LastProfile")); if (kitId.isValid()) dlg.setKitId(kitId); @@ -1764,8 +1754,8 @@ void DebuggerPluginPrivate::attachToQmlPort() Kit *kit = dlg.kit(); QTC_ASSERT(kit && fillParameters(&sp, kit), return); - setConfigValue(_("LastQmlServerPort"), dlg.port()); - setConfigValue(_("LastProfile"), kit->id().toSetting()); + setConfigValue("LastQmlServerPort", dlg.port()); + setConfigValue("LastProfile", kit->id().toSetting()); IDevice::ConstPtr device = DeviceKitInformation::device(kit); if (device) { @@ -2515,18 +2505,16 @@ const CPlusPlus::Snapshot &DebuggerPluginPrivate::cppCodeModelSnapshot() const return m_codeModelSnapshot; } -void DebuggerPluginPrivate::setSessionValue(const QString &name, const QVariant &value) +void DebuggerCore::setSessionValue(const QByteArray &key, const QVariant &value) { QTC_ASSERT(sessionManager(), return); - sessionManager()->setValue(name, value); - //qDebug() << "SET SESSION VALUE: " << name; + sessionManager()->setValue(QString::fromUtf8(key), value); } -QVariant DebuggerPluginPrivate::sessionValue(const QString &name) +QVariant DebuggerCore::sessionValue(const QByteArray &key) { QTC_ASSERT(sessionManager(), return QVariant()); - //qDebug() << "GET SESSION VALUE: " << name; - return sessionManager()->value(name); + return sessionManager()->value(QString::fromUtf8(key)); } void DebuggerPluginPrivate::openTextEditor(const QString &titlePattern0, @@ -2708,9 +2696,7 @@ void DebuggerPluginPrivate::extensionsInitialized() { const QKeySequence debugKey = QKeySequence(UseMacShortcuts ? tr("Ctrl+Y") : tr("F5")); - m_coreSettings = ICore::settings(); - - m_debuggerSettings = new DebuggerSettings(m_coreSettings); + m_debuggerSettings = new DebuggerSettings; m_debuggerSettings->readSettings(); connect(ICore::instance(), SIGNAL(coreAboutToClose()), this, SLOT(coreShutdown())); @@ -3294,8 +3280,7 @@ void DebuggerPluginPrivate::extensionsInitialized() m_commonOptionsPage = new CommonOptionsPage(m_globalDebuggerOptions); m_plugin->addAutoReleasedObject(m_commonOptionsPage); - QTC_CHECK(m_coreSettings); - m_globalDebuggerOptions->fromSettings(m_coreSettings); + m_globalDebuggerOptions->fromSettings(); m_watchersWindow->setVisible(false); m_returnWindow->setVisible(false); diff --git a/src/plugins/debugger/debuggertooltipmanager.cpp b/src/plugins/debugger/debuggertooltipmanager.cpp index 0650fddd1a7..00144510bb0 100644 --- a/src/plugins/debugger/debuggertooltipmanager.cpp +++ b/src/plugins/debugger/debuggertooltipmanager.cpp @@ -1176,7 +1176,7 @@ void DebuggerToolTipManager::sessionAboutToChange() void DebuggerToolTipManager::loadSessionData() { - const QString data = debuggerCore()->sessionValue(QLatin1String(sessionSettingsKeyC)).toString(); + const QString data = DebuggerCore::sessionValue(sessionSettingsKeyC).toString(); if (data.isEmpty()) return; QXmlStreamReader r(data); @@ -1209,7 +1209,7 @@ void DebuggerToolTipManager::saveSessionData() } if (debugToolTips) qDebug() << "DebuggerToolTipManager::saveSessionData" << m_tooltips.size() << data ; - debuggerCore()->setSessionValue(QLatin1String(sessionSettingsKeyC), QVariant(data)); + DebuggerCore::setSessionValue(sessionSettingsKeyC, QVariant(data)); } void DebuggerToolTipManager::closeAllToolTips() diff --git a/src/plugins/debugger/watchhandler.cpp b/src/plugins/debugger/watchhandler.cpp index 3f1f7d116d8..3003083e5cd 100644 --- a/src/plugins/debugger/watchhandler.cpp +++ b/src/plugins/debugger/watchhandler.cpp @@ -1442,8 +1442,7 @@ WatchHandler::WatchHandler(DebuggerEngine *engine) { m_separateWindow = 0; m_engine = engine; - m_watcherCounter = debuggerCore()->sessionValue(QLatin1String("Watchers")) - .toStringList().count(); + m_watcherCounter = DebuggerCore::sessionValue("Watchers").toStringList().count(); m_model = new WatchModel(this); m_contentsValid = false; m_contentsValid = true; // FIXME @@ -1453,7 +1452,7 @@ WatchHandler::WatchHandler(DebuggerEngine *engine) WatchHandler::~WatchHandler() { if (m_separateWindow) { - debuggerCore()->setSessionValue(QLatin1String("DebuggerSeparateWidgetGeometry"), + DebuggerCore::setSessionValue("DebuggerSeparateWidgetGeometry", m_separateWindow->geometry()); delete m_separateWindow; m_separateWindow = 0; @@ -1644,8 +1643,7 @@ void WatchHandler::showSeparateWidget(QWidget *w) { if (m_separateWindow.isNull()) { m_separateWindow = new SeparateViewWidget(debuggerCore()->mainWindow()); - QVariant geometry = debuggerCore()-> - sessionValue(QLatin1String("DebuggerSeparateWidgetGeometry")); + QVariant geometry = DebuggerCore::sessionValue("DebuggerSeparateWidgetGeometry"); if (geometry.isValid()) m_separateWindow->setGeometry(geometry.toRect()); } @@ -1803,12 +1801,12 @@ QStringList WatchHandler::watchedExpressions() void WatchHandler::saveWatchers() { - debuggerCore()->setSessionValue(QLatin1String("Watchers"), QVariant(watchedExpressions())); + DebuggerCore::setSessionValue("Watchers", watchedExpressions()); } void WatchHandler::loadTypeFormats() { - QVariant value = debuggerCore()->sessionValue(QLatin1String("DefaultFormats")); + QVariant value = DebuggerCore::sessionValue("DefaultFormats"); QMap typeFormats = value.toMap(); QMapIterator it(typeFormats); while (it.hasNext()) { @@ -1831,8 +1829,7 @@ void WatchHandler::saveTypeFormats() typeFormats.insert(QLatin1String(key), format); } } - debuggerCore()->setSessionValue(QLatin1String("DefaultFormats"), - QVariant(typeFormats)); + DebuggerCore::setSessionValue("DefaultFormats", typeFormats); } void WatchHandler::saveSessionData() @@ -1846,7 +1843,7 @@ void WatchHandler::loadSessionData() loadTypeFormats(); theWatcherNames.clear(); m_watcherCounter = 0; - QVariant value = debuggerCore()->sessionValue(QLatin1String("Watchers")); + QVariant value = DebuggerCore::sessionValue("Watchers"); m_model->destroyChildren(m_model->m_watchRoot); foreach (const QString &exp, value.toStringList()) watchExpression(exp);