mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 23:26:43 +00:00 
			
		
		
		
	user settings categories
This commit is contained in:
		
							parent
							
								
									36ce8f97d7
								
							
						
					
					
						commit
						b37a2ac09c
					
				
					 7 changed files with 125 additions and 2 deletions
				
			
		|  | @ -141,6 +141,10 @@ opencs_units (model/prefs | |||
|     state | ||||
|     ) | ||||
| 
 | ||||
| opencs_units_noqt (model/prefs | ||||
|     category | ||||
|     ) | ||||
| 
 | ||||
| opencs_units_noqt (model/filter | ||||
|     node unarynode narynode leafnode booleannode parser andnode ornode notnode textnode valuenode | ||||
|     ) | ||||
|  |  | |||
							
								
								
									
										16
									
								
								apps/opencs/model/prefs/category.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								apps/opencs/model/prefs/category.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,16 @@ | |||
| 
 | ||||
| #include "category.hpp" | ||||
| 
 | ||||
| CSMPrefs::Category::Category (State *parent, const std::string& key, const std::string& name) | ||||
| : mParent (parent), mKey (key), mName (name) | ||||
| {} | ||||
| 
 | ||||
| const std::string& CSMPrefs::Category::getKey() const | ||||
| { | ||||
|     return mKey; | ||||
| } | ||||
| 
 | ||||
| const std::string& CSMPrefs::Category::getName() const | ||||
| { | ||||
|     return mName; | ||||
| } | ||||
							
								
								
									
										26
									
								
								apps/opencs/model/prefs/category.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								apps/opencs/model/prefs/category.hpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| #ifndef CSV_PREFS_CATEGORY_H | ||||
| #define CSM_PREFS_CATEGORY_H | ||||
| 
 | ||||
| #include <iostream> | ||||
| 
 | ||||
| namespace CSMPrefs | ||||
| { | ||||
|     class State; | ||||
| 
 | ||||
|     class Category | ||||
|     { | ||||
|             State *mParent; | ||||
|             std::string mKey; | ||||
|             std::string mName; | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             Category (State *parent, const std::string& key, const std::string& name); | ||||
| 
 | ||||
|             const std::string& getKey() const; | ||||
| 
 | ||||
|             const std::string& getName() const; | ||||
|     }; | ||||
| } | ||||
| 
 | ||||
| #endif | ||||
|  | @ -2,6 +2,7 @@ | |||
| #include "state.hpp" | ||||
| 
 | ||||
| #include <stdexcept> | ||||
| #include <algorithm> | ||||
| 
 | ||||
| CSMPrefs::State *CSMPrefs::State::sThis = 0; | ||||
| 
 | ||||
|  | @ -27,11 +28,45 @@ void CSMPrefs::State::load() | |||
| 
 | ||||
| void CSMPrefs::State::declare() | ||||
| { | ||||
|     declareCategory ("window", "Windows"); | ||||
| 
 | ||||
|     declareCategory ("records", "Records"); | ||||
| 
 | ||||
|     declareCategory ("table-input", "ID Tables"); | ||||
| 
 | ||||
|     declareCategory ("dialogues", "ID Dialogues"); | ||||
| 
 | ||||
|     declareCategory ("report-input", "Reports"); | ||||
| 
 | ||||
|     declareCategory ("search", "Search & Replace"); | ||||
| 
 | ||||
|     declareCategory ("script-editor", "Scripts"); | ||||
| 
 | ||||
|     declareCategory ("general-input", "General Input"); | ||||
| 
 | ||||
|     declareCategory ("scene-input", "3D Scene Input"); | ||||
| 
 | ||||
|     declareCategory ("tooltips", "Tooltips"); | ||||
| } | ||||
| 
 | ||||
| void CSMPrefs::State::declareCategory (const std::string& key, const std::string& name) | ||||
| { | ||||
|     std::map<std::string, Category>::iterator iter = mCategories.find (key); | ||||
| 
 | ||||
|     if (iter!=mCategories.end()) | ||||
|     { | ||||
|         mCurrentCategory = iter; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         mCurrentCategory = | ||||
|             mCategories.insert (std::make_pair (key, Category (this, key, name))).first; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| CSMPrefs::State::State (const Files::ConfigurationManager& configurationManager) | ||||
| : mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager) | ||||
| : mConfigFile ("opencs.ini"), mConfigurationManager (configurationManager), | ||||
|   mCurrentCategory (mCategories.end()) | ||||
| { | ||||
|     if (sThis) | ||||
|         throw std::logic_error ("An instance of CSMPRefs::State already exists"); | ||||
|  | @ -53,6 +88,19 @@ void CSMPrefs::State::save() | |||
|     mSettings.saveUser (user.string()); | ||||
| } | ||||
| 
 | ||||
| std::vector<std::pair<std::string, std::string> > CSMPrefs::State::listCategories() const | ||||
| { | ||||
|     std::vector<std::pair<std::string, std::string> > list; | ||||
| 
 | ||||
|     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& CSMPrefs::State::get() | ||||
| { | ||||
|     if (!sThis) | ||||
|  |  | |||
|  | @ -1,6 +1,9 @@ | |||
| #ifndef CSV_PREFS_STATE_H | ||||
| #define CSM_PREFS_STATE_H | ||||
| 
 | ||||
| #include <map> | ||||
| #include <string> | ||||
| 
 | ||||
| #include <QObject> | ||||
| 
 | ||||
| #ifndef Q_MOC_RUN | ||||
|  | @ -9,6 +12,8 @@ | |||
| 
 | ||||
| #include <components/settings/settings.hpp> | ||||
| 
 | ||||
| #include "category.hpp" | ||||
| 
 | ||||
| namespace CSMPrefs | ||||
| { | ||||
|     class State : public QObject | ||||
|  | @ -20,6 +25,8 @@ namespace CSMPrefs | |||
|             const std::string mConfigFile; | ||||
|             const Files::ConfigurationManager& mConfigurationManager; | ||||
|             Settings::Manager mSettings; | ||||
|             std::map<std::string, Category> mCategories; | ||||
|             std::map<std::string, Category>::iterator mCurrentCategory; | ||||
| 
 | ||||
|             // not implemented
 | ||||
|             State (const State&); | ||||
|  | @ -31,6 +38,8 @@ namespace CSMPrefs | |||
| 
 | ||||
|             void declare(); | ||||
| 
 | ||||
|             void declareCategory (const std::string& key, const std::string& name); | ||||
| 
 | ||||
|         public: | ||||
| 
 | ||||
|             State (const Files::ConfigurationManager& configurationManager); | ||||
|  | @ -39,6 +48,9 @@ namespace CSMPrefs | |||
| 
 | ||||
|             void save(); | ||||
| 
 | ||||
|             /// \return collection of name, key pairs (sorted)
 | ||||
|             std::vector<std::pair<std::string, std::string> > listCategories() const; | ||||
| 
 | ||||
|             static State& get(); | ||||
|     }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -6,6 +6,7 @@ | |||
| #include <QSplitter> | ||||
| #include <QListWidget> | ||||
| #include <QStackedWidget> | ||||
| #include <QListWidgetItem> | ||||
| 
 | ||||
| #include "../../model/prefs/state.hpp" | ||||
| 
 | ||||
|  | @ -19,6 +20,21 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main) | |||
| 
 | ||||
|     main->addWidget (mList); | ||||
| 
 | ||||
|     QFontMetrics metrics (QApplication::font()); | ||||
| 
 | ||||
|     int maxWidth = 1; | ||||
| 
 | ||||
|     for (std::vector<std::pair<std::string, std::string> >::const_iterator iter (mCategories.begin()); | ||||
|         iter!=mCategories.end(); ++iter) | ||||
|     { | ||||
|         QString label = QString::fromUtf8 (iter->first.c_str()); | ||||
|         maxWidth = std::max (maxWidth, metrics.width (label)); | ||||
| 
 | ||||
|         mList->addItem (label); | ||||
|     } | ||||
| 
 | ||||
|     mList->setMaximumWidth (maxWidth + 10); | ||||
| 
 | ||||
|     /// \todo connect to selection signal
 | ||||
| } | ||||
| 
 | ||||
|  | @ -30,7 +46,7 @@ void CSVPrefs::Dialogue::buildContentArea (QSplitter *main) | |||
|     main->addWidget (mContent); | ||||
| } | ||||
| 
 | ||||
| CSVPrefs::Dialogue::Dialogue() | ||||
| CSVPrefs::Dialogue::Dialogue() : mCategories (CSMPrefs::get().listCategories()) | ||||
| { | ||||
|     setWindowTitle ("User Settings"); | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,6 +15,7 @@ namespace CSVPrefs | |||
| 
 | ||||
|             QListWidget *mList; | ||||
|             QStackedWidget *mContent; | ||||
|             std::vector<std::pair<std::string, std::string> > mCategories; | ||||
| 
 | ||||
|         private: | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue