mkRPG
src/editor/GUI/options.h
Go to the documentation of this file.
00001 #ifndef OPTIONS_H
00002 #define OPTIONS_H
00003 
00004 #include <QSettings>
00005 #include <QDir>
00006 #include <QSize>
00007 #include <QPoint>
00008 #include <QColor>
00009 
00021 // TODO vérifier que les noms existent !
00022 
00023 const QString ADAPT = "Adjustable";
00024 const QString VAL = "Value";
00025 
00026 #define WIN "Window" 
00029 #define DIR "Directories" 
00032 #define MAP "MapsEditor" 
00038 #define DefaultF(group, opt, val) defaultValues[group][opt] = QPair<QVariant, bool>(val, false) 
00041 #define Default(group, opt, val) defaultValues[group][opt] = QPair<QVariant, bool>(val, true) 
00099 struct Options{
00100     template<class T>
00101     T load(QString group, QString opt){
00102         a.beginGroup(group);
00103         T val = a.value(opt+VAL,defaultValues[group][opt].first).template value<T>();
00104         a.endGroup();
00105         return val;
00106     } 
00116     template<class T>
00117     void save(QString group, QString opt, T val){
00118         a.beginGroup(group);
00119         if(a.value(opt+ADAPT, defaultValues[group][opt].second).toBool())
00120             a.setValue(opt+VAL, val);
00121         a.endGroup();
00122     } 
00130     template<class T>
00131     void setDefault(QString group, QString opt, T val){
00132         a.beginGroup(group);
00133         a.setValue(opt+VAL,val);
00134         a.endGroup();
00135     } 
00143     bool isAdjustable(QString group, QString opt, bool adjust = true); 
00149     void setAdjustable(QString group, QString opt, bool adjust); 
00156     void reinitialise(QString group = ""); 
00159     static Options &options(); 
00163 private:
00164     QSettings a;
00165     QMap<QString, QMap<QString, QPair<QVariant, bool>>> defaultValues;
00166     Options();
00167     ~Options();
00168     static Options *instance;
00169 };
00170 
00171 
00172 
00173 
00174 
00175 #endif // OPTIONS_H
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Defines