some simplification

openmw-38
Marc Zinnschlag 9 years ago
parent b37a2ac09c
commit 0dc3d10112

@ -1,16 +1,11 @@
#include "category.hpp" #include "category.hpp"
CSMPrefs::Category::Category (State *parent, const std::string& key, const std::string& name) CSMPrefs::Category::Category (State *parent, const std::string& key)
: mParent (parent), mKey (key), mName (name) : mParent (parent), mKey (key)
{} {}
const std::string& CSMPrefs::Category::getKey() const const std::string& CSMPrefs::Category::getKey() const
{ {
return mKey; return mKey;
} }
const std::string& CSMPrefs::Category::getName() const
{
return mName;
}

@ -11,15 +11,13 @@ namespace CSMPrefs
{ {
State *mParent; State *mParent;
std::string mKey; std::string mKey;
std::string mName;
public: 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& getKey() const;
const std::string& getName() const;
}; };
} }

@ -28,28 +28,28 @@ void CSMPrefs::State::load()
void CSMPrefs::State::declare() 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<std::string, Category>::iterator iter = mCategories.find (key); std::map<std::string, Category>::iterator iter = mCategories.find (key);
@ -60,7 +60,7 @@ void CSMPrefs::State::declareCategory (const std::string& key, const std::string
else else
{ {
mCurrentCategory = 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()); mSettings.saveUser (user.string());
} }
std::vector<std::pair<std::string, std::string> > CSMPrefs::State::listCategories() const CSMPrefs::State::Iterator CSMPrefs::State::begin()
{ {
std::vector<std::pair<std::string, std::string> > list; return mCategories.begin();
}
for (std::map<std::string, Category>::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 list; CSMPrefs::State::Iterator CSMPrefs::State::end()
{
return mCategories.end();
} }
CSMPrefs::State& CSMPrefs::State::get() CSMPrefs::State& CSMPrefs::State::get()

@ -22,11 +22,18 @@ namespace CSMPrefs
static State *sThis; static State *sThis;
public:
typedef std::map<std::string, Category> Collection;
typedef Collection::iterator Iterator;
private:
const std::string mConfigFile; const std::string mConfigFile;
const Files::ConfigurationManager& mConfigurationManager; const Files::ConfigurationManager& mConfigurationManager;
Settings::Manager mSettings; Settings::Manager mSettings;
std::map<std::string, Category> mCategories; Collection mCategories;
std::map<std::string, Category>::iterator mCurrentCategory; Iterator mCurrentCategory;
// not implemented // not implemented
State (const State&); State (const State&);
@ -38,7 +45,7 @@ namespace CSMPrefs
void declare(); void declare();
void declareCategory (const std::string& key, const std::string& name); void declareCategory (const std::string& key);
public: public:
@ -48,8 +55,9 @@ namespace CSMPrefs
void save(); void save();
/// \return collection of name, key pairs (sorted) Iterator begin();
std::vector<std::pair<std::string, std::string> > listCategories() const;
Iterator end();
static State& get(); static State& get();
}; };

@ -24,10 +24,10 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
int maxWidth = 1; int maxWidth = 1;
for (std::vector<std::pair<std::string, std::string> >::const_iterator iter (mCategories.begin()); for (CSMPrefs::State::Iterator iter = CSMPrefs::get().begin(); iter!=CSMPrefs::get().end();
iter!=mCategories.end(); ++iter) ++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)); maxWidth = std::max (maxWidth, metrics.width (label));
mList->addItem (label); mList->addItem (label);
@ -46,7 +46,7 @@ void CSVPrefs::Dialogue::buildContentArea (QSplitter *main)
main->addWidget (mContent); main->addWidget (mContent);
} }
CSVPrefs::Dialogue::Dialogue() : mCategories (CSMPrefs::get().listCategories()) CSVPrefs::Dialogue::Dialogue()
{ {
setWindowTitle ("User Settings"); setWindowTitle ("User Settings");

@ -15,7 +15,6 @@ namespace CSVPrefs
QListWidget *mList; QListWidget *mList;
QStackedWidget *mContent; QStackedWidget *mContent;
std::vector<std::pair<std::string, std::string> > mCategories;
private: private:

Loading…
Cancel
Save