summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2014-12-09 11:12:17 +0100
committerKai Koehne <kai.koehne@theqtcompany.com>2015-01-13 16:43:16 +0100
commit32fa850a6d12718f7c9fa07c4cd7f6d5f6b60224 (patch)
tree16a89ce006876b454ee1de50e44c075270b92cb3 /src/plugins/texteditor
parent036f4f00eb4e1a8983e986da427e11c3d46b8c60 (diff)
downloadqt-creator-32fa850a6d12718f7c9fa07c4cd7f6d5f6b60224.tar.gz
Outline: Redo save/restore of settings
The OutlineStackWidget stored its position in the outline to be able to save/restore settings specific to the sub-widget (IOutlineWidget). However, the index can get out sync if another NavigationWidget with a lower index number is split, and the relative position changes. The change therefore avoids saving an index, and rather keeps the sum of all sub-widget settings in a QVariantMap, only reading and writing to the global settings object if necessary. The settings are also not stored in the [General] section anymore, but in a subgroup [Sidebar.Outline.X], where X is the index of the outline in the view. This avoids having to always iterate over all keys. No effort has been made to take over the old settings. I doubt anyone will notice, though. Change-Id: I85017cbb3e32b0a16da43ce6339deb7a053d6b09 Task-number: QTCREATORBUG-13614 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/ioutlinewidget.h5
-rw-r--r--src/plugins/texteditor/outlinefactory.cpp46
-rw-r--r--src/plugins/texteditor/outlinefactory.h2
3 files changed, 29 insertions, 24 deletions
diff --git a/src/plugins/texteditor/ioutlinewidget.h b/src/plugins/texteditor/ioutlinewidget.h
index 2113745624..242723f622 100644
--- a/src/plugins/texteditor/ioutlinewidget.h
+++ b/src/plugins/texteditor/ioutlinewidget.h
@@ -33,6 +33,7 @@
#include <texteditor/texteditor_global.h>
#include <QWidget>
+#include <QVariantMap>
namespace Core { class IEditor; }
@@ -47,8 +48,8 @@ public:
virtual QList<QAction*> filterMenuActions() const = 0;
virtual void setCursorSynchronization(bool syncWithCursor) = 0;
- virtual void restoreSettings(int position) { Q_UNUSED(position); }
- virtual void saveSettings(int position) { Q_UNUSED(position); }
+ virtual void restoreSettings(const QVariantMap & /*map*/) { }
+ virtual QVariantMap settings() const { return QVariantMap(); }
};
class TEXTEDITOR_EXPORT IOutlineWidgetFactory : public QObject {
diff --git a/src/plugins/texteditor/outlinefactory.cpp b/src/plugins/texteditor/outlinefactory.cpp
index 59a6d3010f..aefe43377e 100644
--- a/src/plugins/texteditor/outlinefactory.cpp
+++ b/src/plugins/texteditor/outlinefactory.cpp
@@ -45,8 +45,7 @@ namespace Internal {
OutlineWidgetStack::OutlineWidgetStack(OutlineFactory *factory) :
QStackedWidget(),
m_factory(factory),
- m_syncWithEditor(true),
- m_position(-1)
+ m_syncWithEditor(true)
{
QLabel *label = new QLabel(tr("No outline available"), this);
label->setAlignment(Qt::AlignCenter);
@@ -91,32 +90,37 @@ QToolButton *OutlineWidgetStack::filterButton()
return m_filterButton;
}
-static inline QString outLineKey(int position)
-{
- return QLatin1String("Outline.") + QString::number(position) + QLatin1String(".SyncWithEditor");
-}
-
void OutlineWidgetStack::restoreSettings(int position)
{
- m_position = position; // save it so that we can save/restore in updateCurrentEditor
-
QSettings *settings = Core::ICore::settings();
- const bool toggleSync = settings->value(outLineKey(position), true).toBool();
- toggleSyncButton()->setChecked(toggleSync);
+ settings->beginGroup(QLatin1String("Sidebar.Outline.") + QString::number(position));
+
+ bool syncWithEditor = true;
+ m_widgetSettings.clear();
+ foreach (const QString &key, settings->allKeys()) {
+ if (key == QLatin1String("SyncWithEditor")) {
+ syncWithEditor = settings->value(key).toBool();
+ continue;
+ }
+ m_widgetSettings.insert(key, settings->value(key));
+ }
+ settings->endGroup();
+ toggleSyncButton()->setChecked(syncWithEditor);
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
- outlineWidget->restoreSettings(position);
+ outlineWidget->restoreSettings(m_widgetSettings);
}
void OutlineWidgetStack::saveSettings(int position)
{
- Q_ASSERT(position == m_position);
-
QSettings *settings = Core::ICore::settings();
- settings->setValue(outLineKey(position), toggleSyncButton()->isEnabled());
+ settings->beginGroup(QLatin1String("Sidebar.Outline.") + QString::number(position));
- if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget()))
- outlineWidget->saveSettings(position);
+ settings->setValue(QLatin1String("SyncWithEditor"), toggleSyncButton()->isChecked());
+ for (auto iter = m_widgetSettings.constBegin(); iter != m_widgetSettings.constEnd(); ++iter)
+ settings->setValue(iter.key(), iter.value());
+
+ settings->endGroup();
}
bool OutlineWidgetStack::isCursorSynchronized() const
@@ -158,14 +162,14 @@ void OutlineWidgetStack::updateCurrentEditor(Core::IEditor *editor)
if (newWidget != currentWidget()) {
// delete old widget
if (IOutlineWidget *outlineWidget = qobject_cast<IOutlineWidget*>(currentWidget())) {
- if (m_position > -1)
- outlineWidget->saveSettings(m_position);
+ QVariantMap widgetSettings = outlineWidget->settings();
+ for (auto iter = widgetSettings.constBegin(); iter != widgetSettings.constEnd(); ++iter)
+ m_widgetSettings.insert(iter.key(), iter.value());
removeWidget(outlineWidget);
delete outlineWidget;
}
if (newWidget) {
- if (m_position > -1)
- newWidget->restoreSettings(m_position);
+ newWidget->restoreSettings(m_widgetSettings);
newWidget->setCursorSynchronization(m_syncWithEditor);
addWidget(newWidget);
setCurrentWidget(newWidget);
diff --git a/src/plugins/texteditor/outlinefactory.h b/src/plugins/texteditor/outlinefactory.h
index 1f282f0cda..a78ab6a0b0 100644
--- a/src/plugins/texteditor/outlinefactory.h
+++ b/src/plugins/texteditor/outlinefactory.h
@@ -71,8 +71,8 @@ private:
QToolButton *m_toggleSync;
QToolButton *m_filterButton;
QMenu *m_filterMenu;
+ QVariantMap m_widgetSettings;
bool m_syncWithEditor;
- int m_position;
};
class OutlineFactory : public Core::INavigationWidgetFactory