From 0dc3d101123c83413ede9ffbee8d19fabc155cdb Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Tue, 8 Dec 2015 09:56:42 +0100 Subject: [PATCH] some simplification --- apps/opencs/model/prefs/category.cpp | 9 ++----- apps/opencs/model/prefs/category.hpp | 4 +-- apps/opencs/model/prefs/state.cpp | 39 +++++++++++++--------------- apps/opencs/model/prefs/state.hpp | 18 +++++++++---- apps/opencs/view/prefs/dialogue.cpp | 8 +++--- apps/opencs/view/prefs/dialogue.hpp | 1 - 6 files changed, 38 insertions(+), 41 deletions(-) diff --git a/apps/opencs/model/prefs/category.cpp b/apps/opencs/model/prefs/category.cpp index 2f94c729b..8143a19e5 100644 --- a/apps/opencs/model/prefs/category.cpp +++ b/apps/opencs/model/prefs/category.cpp @@ -1,16 +1,11 @@ #include "category.hpp" -CSMPrefs::Category::Category (State *parent, const std::string& key, const std::string& name) -: mParent (parent), mKey (key), mName (name) +CSMPrefs::Category::Category (State *parent, const std::string& key) +: mParent (parent), mKey (key) {} const std::string& CSMPrefs::Category::getKey() const { return mKey; } - -const std::string& CSMPrefs::Category::getName() const -{ - return mName; -} diff --git a/apps/opencs/model/prefs/category.hpp b/apps/opencs/model/prefs/category.hpp index d80d5416f..43a6325ee 100644 --- a/apps/opencs/model/prefs/category.hpp +++ b/apps/opencs/model/prefs/category.hpp @@ -11,15 +11,13 @@ namespace CSMPrefs { State *mParent; std::string mKey; - std::string mName; public: - Category (State *parent, const std::string& key, const std::string& name); + Category (State *parent, const std::string& key); const std::string& getKey() const; - const std::string& getName() const; }; } diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 70e4c86c5..d8a0a5614 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -28,28 +28,28 @@ void CSMPrefs::State::load() void CSMPrefs::State::declare() { - declareCategory ("window", "Windows"); + declareCategory ("Windows"); - declareCategory ("records", "Records"); + declareCategory ("Records"); - declareCategory ("table-input", "ID Tables"); + declareCategory ("ID Tables"); - declareCategory ("dialogues", "ID Dialogues"); + declareCategory ("ID Dialogues"); - declareCategory ("report-input", "Reports"); + declareCategory ("Reports"); - declareCategory ("search", "Search & Replace"); + declareCategory ("Search & Replace"); - declareCategory ("script-editor", "Scripts"); + declareCategory ("Scripts"); - declareCategory ("general-input", "General Input"); + declareCategory ("General Input"); - declareCategory ("scene-input", "3D Scene Input"); + declareCategory ("3D Scene Input"); - declareCategory ("tooltips", "Tooltips"); + declareCategory ("Tooltips"); } -void CSMPrefs::State::declareCategory (const std::string& key, const std::string& name) +void CSMPrefs::State::declareCategory (const std::string& key) { std::map::iterator iter = mCategories.find (key); @@ -60,7 +60,7 @@ void CSMPrefs::State::declareCategory (const std::string& key, const std::string else { mCurrentCategory = - mCategories.insert (std::make_pair (key, Category (this, key, name))).first; + mCategories.insert (std::make_pair (key, Category (this, key))).first; } } @@ -88,17 +88,14 @@ void CSMPrefs::State::save() mSettings.saveUser (user.string()); } -std::vector > CSMPrefs::State::listCategories() const +CSMPrefs::State::Iterator CSMPrefs::State::begin() { - std::vector > list; - - for (std::map::const_iterator iter (mCategories.begin()); - iter!=mCategories.end(); ++iter) - list.push_back (std::make_pair (iter->second.getName(), iter->first)); - - std::sort (list.begin(), list.end()); + return mCategories.begin(); +} - return list; +CSMPrefs::State::Iterator CSMPrefs::State::end() +{ + return mCategories.end(); } CSMPrefs::State& CSMPrefs::State::get() diff --git a/apps/opencs/model/prefs/state.hpp b/apps/opencs/model/prefs/state.hpp index fd49db3ef..d643dfa4a 100644 --- a/apps/opencs/model/prefs/state.hpp +++ b/apps/opencs/model/prefs/state.hpp @@ -22,11 +22,18 @@ namespace CSMPrefs static State *sThis; + public: + + typedef std::map Collection; + typedef Collection::iterator Iterator; + + private: + const std::string mConfigFile; const Files::ConfigurationManager& mConfigurationManager; Settings::Manager mSettings; - std::map mCategories; - std::map::iterator mCurrentCategory; + Collection mCategories; + Iterator mCurrentCategory; // not implemented State (const State&); @@ -38,7 +45,7 @@ namespace CSMPrefs void declare(); - void declareCategory (const std::string& key, const std::string& name); + void declareCategory (const std::string& key); public: @@ -48,8 +55,9 @@ namespace CSMPrefs void save(); - /// \return collection of name, key pairs (sorted) - std::vector > listCategories() const; + Iterator begin(); + + Iterator end(); static State& get(); }; diff --git a/apps/opencs/view/prefs/dialogue.cpp b/apps/opencs/view/prefs/dialogue.cpp index cc794c286..ec43d853d 100644 --- a/apps/opencs/view/prefs/dialogue.cpp +++ b/apps/opencs/view/prefs/dialogue.cpp @@ -24,10 +24,10 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) int maxWidth = 1; - for (std::vector >::const_iterator iter (mCategories.begin()); - iter!=mCategories.end(); ++iter) + for (CSMPrefs::State::Iterator iter = CSMPrefs::get().begin(); iter!=CSMPrefs::get().end(); + ++iter) { - QString label = QString::fromUtf8 (iter->first.c_str()); + QString label = QString::fromUtf8 (iter->second.getKey().c_str()); maxWidth = std::max (maxWidth, metrics.width (label)); mList->addItem (label); @@ -46,7 +46,7 @@ void CSVPrefs::Dialogue::buildContentArea (QSplitter *main) main->addWidget (mContent); } -CSVPrefs::Dialogue::Dialogue() : mCategories (CSMPrefs::get().listCategories()) +CSVPrefs::Dialogue::Dialogue() { setWindowTitle ("User Settings"); diff --git a/apps/opencs/view/prefs/dialogue.hpp b/apps/opencs/view/prefs/dialogue.hpp index 2773bcccc..78c832c9f 100644 --- a/apps/opencs/view/prefs/dialogue.hpp +++ b/apps/opencs/view/prefs/dialogue.hpp @@ -15,7 +15,6 @@ namespace CSVPrefs QListWidget *mList; QStackedWidget *mContent; - std::vector > mCategories; private: