4 Settings *Settings::singleton = new Settings();
5 QSettings Settings::s(Settings::settingsfile(), QSettings::IniFormat);
6 const QString Settings::weightUnitKey = "WeightUnit";
7 const QString Settings::goalWeightMinKey = "GoalWeightMin";
8 const QString Settings::goalWeightMaxKey = "GoalWeightMax";
9 const QString Settings::grabZoomKeysKey = "GrabZoomKeys";
10 const QString Settings::graphSettingsGroupSuffix = "Graph";
11 const QString Settings::goalWeightEnabledKey = "GoalWeightEnabled";
12 const QString Settings::weightIntervalModeKey = "WeightIntervalMode";
13 const QString Settings::weightIntervalMinKey = "WeightIntervalMin";
14 const QString Settings::weightIntervalMaxKey = "WeightIntervalMax";
15 const QString Settings::defaultTimeIntervalKey = "DefaultTimeInterval";
17 QString Settings::weightUnit()
19 if(!s.contains(weightUnitKey))
21 return s.value(weightUnitKey).toString();
23 void Settings::setWeightUnit(QString wu)
25 s.setValue(weightUnitKey, wu);
27 void Settings::setWeightUnitAndSync(QString wu)
33 double Settings::goalWeightMin()
35 if(!s.contains(goalWeightMinKey))
36 setGoalWeightMin(0.0);
37 return s.value(goalWeightMinKey).toDouble();
39 void Settings::setGoalWeightMin(double min)
41 s.setValue(goalWeightMinKey, min);
43 void Settings::setGoalWeightMinAndSync(double min)
45 setGoalWeightMin(min);
49 double Settings::goalWeightMax()
51 if(!s.contains(goalWeightMaxKey))
52 setGoalWeightMax(0.0);
53 return s.value(goalWeightMaxKey).toDouble();
55 void Settings::setGoalWeightMax(double max)
57 s.setValue(goalWeightMaxKey, max);
59 void Settings::setGoalWeightMaxAndSync(double max)
61 setGoalWeightMax(max);
65 bool Settings::grabZoomKeys()
67 if(!s.contains(grabZoomKeysKey))
68 setGrabZoomKeys(true);
69 return s.value(grabZoomKeysKey).toBool();
71 void Settings::setGrabZoomKeys(bool grab)
73 s.setValue(grabZoomKeysKey, grab);
75 void Settings::setGrabZoomKeysAndSync(bool grab)
77 setGrabZoomKeys(grab);
81 GraphSettings Settings::graphSettings(const QString &graphId)
85 s.beginGroup(graphId+graphSettingsGroupSuffix);
87 if (!s.contains(goalWeightEnabledKey)) {
88 s.setValue(goalWeightEnabledKey, false);
91 ret.goalWeightEnabled = s.value(goalWeightEnabledKey).toBool();
93 if (!s.contains(weightIntervalModeKey)) {
94 s.setValue(weightIntervalModeKey, (int)GraphSettings::AutomaticWithoutGoalWeight);
97 ret.weightIntervalMode =
98 (GraphSettings::WeightIntervalMode)s.value(weightIntervalModeKey).toInt();
100 if (!s.contains(weightIntervalMinKey)) {
101 s.setValue(weightIntervalMinKey, 0.0);
104 ret.weightIntervalMin = s.value(weightIntervalMinKey).toDouble();
106 if (!s.contains(weightIntervalMaxKey)) {
107 s.setValue(weightIntervalMaxKey, 0.0);
110 ret.weightIntervalMax = s.value(weightIntervalMaxKey).toDouble();
112 if (!s.contains(defaultTimeIntervalKey)) {
113 s.setValue(defaultTimeIntervalKey, 0);
116 ret.defaultTimeInterval = s.value(defaultTimeIntervalKey).toInt();
123 void Settings::setGraphSettings(const QString &graphId, GraphSettings &gs)
125 s.beginGroup(graphId+graphSettingsGroupSuffix);
126 s.setValue(goalWeightEnabledKey, gs.goalWeightEnabled);
127 s.setValue(weightIntervalModeKey, (int)gs.weightIntervalMode);
128 s.setValue(weightIntervalMinKey, gs.weightIntervalMin);
129 s.setValue(weightIntervalMaxKey, gs.weightIntervalMax);
130 s.setValue(defaultTimeIntervalKey, gs.defaultTimeInterval);
133 void Settings::setGraphSettingsAndSync(const QString &graphId,
136 setGraphSettings(graphId, gs);
140 QStringList Settings::graphIds()
142 QStringList tmp = s.childGroups();
143 tmp = tmp.filter(QRegExp("^\\w+Graph$"));
144 return tmp.replaceInStrings(QRegExp("^(\\w+)Graph$"), "\\1");
146 void Settings::sync()
149 emit singleton->settingChanged();
152 QString Settings::datadir()
155 return QDir::home().path()+"/MyDocs/WeightGraph";
157 return QDir::home().path()+"/.weightgraph";
160 QString Settings::datafile()
162 return datadir()+"/weightdata.txt";
164 QString Settings::settingsfile()
166 return datadir()+"/config.ini";