Commit 5e5d840b authored by hjk's avatar hjk
Browse files

Debugger: Streamline settings access pattern



Change-Id: Ie73b8d9fa945ee9dcbab67177410cc782979c8ad
Reviewed-by: default avatarDavid Schulz <david.schulz@digia.com>
parent cd17a0e4
......@@ -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<QVariant> list = value.toList();
//clear();
foreach (const QVariant &var, list) {
......
......@@ -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();
}
}
......
......@@ -33,6 +33,7 @@
#include "registerpostmortemaction.h"
#endif
#include <coreplugin/icore.h>
#include <utils/savedaction.h>
#include <utils/qtcassert.h>
......@@ -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
......
......@@ -34,13 +34,7 @@
#include <QHash>
#include <QMap>
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<QString, QString> 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<int, Utils::SavedAction *> m_items;
QSettings *m_settings;
};
///////////////////////////////////////////////////////////
......
......@@ -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;
......
......@@ -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<StartApplicationParameters> history;
QSettings *settings = ICore::settings();
settings->beginGroup(settingsGroup);
if (const int arraySize = settings->beginReadArray(arrayName)) {
for (int i = 0; i < arraySize; ++i) {
......
......@@ -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);
......
......@@ -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);
......
......@@ -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()
......
......@@ -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<QString, QVariant> typeFormats = value.toMap();
QMapIterator<QString, QVariant> 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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment