QString Settings::weightUnit()
{
- if(!s.contains(weightUnitKey))
- setWeightUnit("kg");
- return s.value(weightUnitKey).toString();
+ return s.value(weightUnitKey, "kg").toString();
}
void Settings::setWeightUnit(QString wu)
{
double Settings::goalWeightMin()
{
- if(!s.contains(goalWeightMinKey))
- setGoalWeightMin(0.0);
- return s.value(goalWeightMinKey).toDouble();
+ return s.value(goalWeightMinKey, 0.0).toDouble();
}
void Settings::setGoalWeightMin(double min)
{
double Settings::goalWeightMax()
{
- if(!s.contains(goalWeightMaxKey))
- setGoalWeightMax(0.0);
- return s.value(goalWeightMaxKey).toDouble();
+ return s.value(goalWeightMaxKey, 0.0).toDouble();
}
void Settings::setGoalWeightMax(double max)
{
bool Settings::grabZoomKeys()
{
- if(!s.contains(grabZoomKeysKey))
- setGrabZoomKeys(true);
- return s.value(grabZoomKeysKey).toBool();
+ return s.value(grabZoomKeysKey, true).toBool();
}
void Settings::setGrabZoomKeys(bool grab)
{
GraphSettings Settings::graphSettings(const QString &graphId)
{
GraphSettings ret;
- bool changed = false;
- s.beginGroup(graphId+graphSettingsGroupSuffix);
-
- if (!s.contains(goalWeightEnabledKey)) {
- s.setValue(goalWeightEnabledKey, false);
- changed = true;
- }
- ret.goalWeightEnabled = s.value(goalWeightEnabledKey).toBool();
-
- if (!s.contains(weightIntervalModeKey)) {
- s.setValue(weightIntervalModeKey, (int)GraphSettings::AutomaticWithoutGoalWeight);
- changed = true;
- }
- ret.weightIntervalMode =
- (GraphSettings::WeightIntervalMode)s.value(weightIntervalModeKey).toInt();
-
- if (!s.contains(weightIntervalMinKey)) {
- s.setValue(weightIntervalMinKey, 0.0);
- changed = true;
- }
- ret.weightIntervalMin = s.value(weightIntervalMinKey).toDouble();
-
- if (!s.contains(weightIntervalMaxKey)) {
- s.setValue(weightIntervalMaxKey, 0.0);
- changed = true;
- }
- ret.weightIntervalMax = s.value(weightIntervalMaxKey).toDouble();
-
- if (!s.contains(defaultTimeIntervalKey)) {
- s.setValue(defaultTimeIntervalKey, 0);
- changed = true;
- }
- ret.defaultTimeInterval = s.value(defaultTimeIntervalKey).toInt();
+ s.beginGroup(graphId+graphSettingsGroupSuffix);
+ ret.goalWeightEnabled = s.value(goalWeightEnabledKey, false).toBool();
+ ret.weightIntervalMode = (GraphSettings::WeightIntervalMode)s.value(
+ weightIntervalModeKey, (int)GraphSettings::AutomaticWithoutGoalWeight).toInt();
+ ret.weightIntervalMin = s.value(weightIntervalMinKey, 0.0).toDouble();
+ ret.weightIntervalMax = s.value(weightIntervalMaxKey, 0.0).toDouble();
+ ret.defaultTimeInterval = s.value(defaultTimeIntervalKey, 0).toInt();
s.endGroup();
- if (changed)
- sync();
+
return ret;
}
void Settings::setGraphSettings(const QString &graphId, GraphSettings &gs)