From c94c1adaf34d3b5b4afd8319a64b0427d4e062da Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Thu, 16 Oct 2014 13:48:07 +0200 Subject: [PATCH] split off settings page label from internal section name --- apps/opencs/model/settings/usersettings.cpp | 34 +++++++++++++++------ apps/opencs/model/settings/usersettings.hpp | 9 ++++-- apps/opencs/view/settings/dialog.cpp | 6 ++-- apps/opencs/view/settings/page.cpp | 12 +++++--- apps/opencs/view/settings/page.hpp | 8 +++-- apps/opencs/view/settings/settingwindow.cpp | 4 +-- 6 files changed, 48 insertions(+), 25 deletions(-) diff --git a/apps/opencs/model/settings/usersettings.cpp b/apps/opencs/model/settings/usersettings.cpp index cb4003afa..3729ed6cc 100644 --- a/apps/opencs/model/settings/usersettings.cpp +++ b/apps/opencs/model/settings/usersettings.cpp @@ -50,7 +50,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() { QString section; - declareSection ("Objects"); + declareSection ("Objects", "Objects"); { Setting *numLights = createSetting (Type_SpinBox, "num_lights", "num_lights"); numLights->setDefaultValue(8); @@ -58,10 +58,9 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() Setting *shaders = createSetting (Type_CheckBox, "shaders", "Enable Shaders"); shaders->setDefaultValue("true"); -// shaders->setSpecialValueText("Enable Shaders"); } - declareSection ("Scene"); + declareSection ("Scene", "Scene"); { Setting *fastFactor = createSetting (Type_SpinBox, "fast factor", "fast factor"); fastFactor->setDefaultValue(4); @@ -76,7 +75,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() timerStart->setRange (1, 100); } - declareSection ("SubView"); + declareSection ("SubView", "SubView"); { Setting *maxSubView = createSetting (Type_SpinBox, "max subviews", "max subviews"); maxSubView->setDefaultValue(256); @@ -91,7 +90,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() // reuse->setSpecialValueText("Reuse SubView"); } - declareSection ("Window Size"); + declareSection ("Window Size", "Window Size"); { Setting *width = createSetting (Type_LineEdit, "Width", "Width"); Setting *height = createSetting (Type_LineEdit, "Height", "Height"); @@ -124,7 +123,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() ); } - declareSection ("Display Format"); + declareSection ("Display Format", "Display Format"); { QString defaultValue = "Icon and Text"; @@ -139,7 +138,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults() ritd->setDeclaredValues (values); } - declareSection ("Video"); + declareSection ("Video", "Video"); { QString defaultValue = "None"; QStringList values = QStringList() @@ -480,7 +479,23 @@ CSMSettings::SettingPageMap CSMSettings::UserSettings::settingPageMap() const SettingPageMap pageMap; foreach (Setting *setting, mSettings) - pageMap[setting->page()].append (setting); + { + SettingPageMap::iterator iter = pageMap.find (setting->page()); + + if (iter==pageMap.end()) + { + QPair > value; + + std::map::const_iterator iter2 = + mSectionLabels.find (setting->page()); + + value.first = iter2!=mSectionLabels.end() ? iter2->second : ""; + + iter = pageMap.insert (setting->page(), value); + } + + iter->second.append (setting); + } return pageMap; } @@ -532,9 +547,10 @@ CSMSettings::Setting *CSMSettings::UserSettings::createSetting return setting; } -void CSMSettings::UserSettings::declareSection (const QString& page) +void CSMSettings::UserSettings::declareSection (const QString& page, const QString& label) { mSection = page; + mSectionLabels[page] = label; } QStringList CSMSettings::UserSettings::definitions (const QString &viewKey) const diff --git a/apps/opencs/model/settings/usersettings.hpp b/apps/opencs/model/settings/usersettings.hpp index 9629f6cb5..ef5c61438 100644 --- a/apps/opencs/model/settings/usersettings.hpp +++ b/apps/opencs/model/settings/usersettings.hpp @@ -1,10 +1,13 @@ #ifndef USERSETTINGS_HPP #define USERSETTINGS_HPP +#include + #include #include #include #include +#include #include #include "support.hpp" @@ -22,7 +25,7 @@ class QSettings; namespace CSMSettings { class Setting; - typedef QMap > SettingPageMap; + typedef QMap > > SettingPageMap; class UserSettings: public QObject { @@ -36,7 +39,7 @@ namespace CSMSettings { QSettings *mSettingCfgDefinitions; QList mSettings; QString mSection; - + std::map mSectionLabels; public: @@ -91,7 +94,7 @@ namespace CSMSettings { /// Set the section for createSetting calls. /// /// Sections can be declared multiple times. - void declareSection (const QString& page); + void declareSection (const QString& page, const QString& label); signals: diff --git a/apps/opencs/view/settings/dialog.cpp b/apps/opencs/view/settings/dialog.cpp index 9018a454c..e66da8571 100644 --- a/apps/opencs/view/settings/dialog.cpp +++ b/apps/opencs/view/settings/dialog.cpp @@ -67,11 +67,9 @@ void CSVSettings::Dialog::buildPages() foreach (Page *page, SettingWindow::pages()) { - QString pageName = page->objectName(); + maxWidth = std::max (maxWidth, fm.width(page->getLabel())); - maxWidth = std::max (maxWidth, fm.width(pageName)); - - new QListWidgetItem (pageName, mPageListWidget); + new QListWidgetItem (page->getLabel(), mPageListWidget); mStackedWidget->addWidget (page); } diff --git a/apps/opencs/view/settings/page.cpp b/apps/opencs/view/settings/page.cpp index ed4cdd6bc..e846840b8 100644 --- a/apps/opencs/view/settings/page.cpp +++ b/apps/opencs/view/settings/page.cpp @@ -17,10 +17,9 @@ QMap CSVSettings::Page::mViewFactories; -CSVSettings::Page::Page(const QString &pageName, - QList settingList, - SettingWindow *parent) : - mParent(parent), mIsEditorPage (false), Frame(false, "", parent) +CSVSettings::Page::Page (const QString &pageName, QList settingList, + SettingWindow *parent, const QString& label) +: mParent(parent), mIsEditorPage (false), Frame(false, "", parent), mLabel (label) { setObjectName (pageName); @@ -104,3 +103,8 @@ void CSVSettings::Page::buildFactories() mViewFactories[ViewType_List] = new ListViewFactory (this); mViewFactories[ViewType_Range] = new RangeViewFactory (this); } + +QString CSVSettings::Page::getLabel() const +{ + return mLabel; +} diff --git a/apps/opencs/view/settings/page.hpp b/apps/opencs/view/settings/page.hpp index 877d4bef8..caf2eec3f 100644 --- a/apps/opencs/view/settings/page.hpp +++ b/apps/opencs/view/settings/page.hpp @@ -25,11 +25,11 @@ namespace CSVSettings SettingWindow *mParent; static QMap mViewFactories; bool mIsEditorPage; + QString mLabel; public: - explicit Page(const QString &pageName, - QList settingList, - SettingWindow *parent); + Page (const QString &pageName, QList settingList, + SettingWindow *parent, const QString& label); ///Creates a new view based on the passed setting and adds it to ///the page. @@ -42,6 +42,8 @@ namespace CSVSettings ///returns the list of views associated with the page const QList &views () const { return mViews; } + QString getLabel() const; + private: ///Creates views based on the passed setting list diff --git a/apps/opencs/view/settings/settingwindow.cpp b/apps/opencs/view/settings/settingwindow.cpp index 4570a96db..76ea9dc4f 100644 --- a/apps/opencs/view/settings/settingwindow.cpp +++ b/apps/opencs/view/settings/settingwindow.cpp @@ -20,9 +20,9 @@ void CSVSettings::SettingWindow::createPages() foreach (const QString &pageName, pageMap.keys()) { - QList pageSettings = pageMap.value (pageName); + QList pageSettings = pageMap.value (pageName).second; - mPages.append (new Page (pageName, pageSettings, this)); + mPages.append (new Page (pageName, pageSettings, this, pageMap.value (pageName).first)); for (int i = 0; i < pageSettings.size(); i++) {