mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 12:40:04 +00:00
some simplification
This commit is contained in:
parent
b37a2ac09c
commit
0dc3d10112
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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<std::string, Category>::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<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()
|
||||
|
@ -22,11 +22,18 @@ namespace CSMPrefs
|
||||
|
||||
static State *sThis;
|
||||
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, Category> Collection;
|
||||
typedef Collection::iterator Iterator;
|
||||
|
||||
private:
|
||||
|
||||
const std::string mConfigFile;
|
||||
const Files::ConfigurationManager& mConfigurationManager;
|
||||
Settings::Manager mSettings;
|
||||
std::map<std::string, Category> mCategories;
|
||||
std::map<std::string, Category>::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<std::pair<std::string, std::string> > listCategories() const;
|
||||
Iterator begin();
|
||||
|
||||
Iterator end();
|
||||
|
||||
static State& get();
|
||||
};
|
||||
|
@ -24,10 +24,10 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
|
||||
|
||||
int maxWidth = 1;
|
||||
|
||||
for (std::vector<std::pair<std::string, std::string> >::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");
|
||||
|
||||
|
@ -15,7 +15,6 @@ namespace CSVPrefs
|
||||
|
||||
QListWidget *mList;
|
||||
QStackedWidget *mContent;
|
||||
std::vector<std::pair<std::string, std::string> > mCategories;
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user