Commit e6d3e34

derdilla <82763757+NobodyForNothing@users.noreply.github.com>
2024-06-11 19:34:06
add reset to settings classes
Signed-off-by: derdilla <82763757+NobodyForNothing@users.noreply.github.com>
1 parent daf212f
app/lib/model/storage/export_columns_store.dart
@@ -39,6 +39,11 @@ class ExportColumnsManager extends ChangeNotifier {
   /// It will be filled with the default columns but won't contain initial user columns.
   ExportColumnsManager();
 
+  /// Reset all fields to their default values.
+  void reset() {
+    _userColumns.clear();
+  }
+
   /// Namespaces that may not lead a user columns internal identifier.
   static const List<String> reservedNamespaces = ['buildIn', 'myHeart'];
 
app/lib/model/storage/export_csv_settings_store.dart
@@ -40,7 +40,6 @@ class CsvExportSettings extends ChangeNotifier implements CustomFieldsSettings {
         ),
       );
     }
-
   }
 
   factory CsvExportSettings.fromJson(String json) {
@@ -59,8 +58,18 @@ class CsvExportSettings extends ChangeNotifier implements CustomFieldsSettings {
     'exportFieldsConfiguration': exportFieldsConfiguration.toJson(),
   };
 
+  /// Serializes the object to json string.
   String toJson() => jsonEncode(toMap());
 
+  /// Reset all fields to their default values.
+  void reset() {
+    final d = CsvExportSettings();
+    _fieldDelimiter = d.fieldDelimiter;
+    _textDelimiter = d._textDelimiter;
+    _exportHeadline = d._exportHeadline;
+    _exportFieldsConfiguration = d._exportFieldsConfiguration;
+  }
+
   String _fieldDelimiter = ',';
   String get fieldDelimiter => _fieldDelimiter;
   set fieldDelimiter(String value) {
@@ -87,4 +96,4 @@ class CsvExportSettings extends ChangeNotifier implements CustomFieldsSettings {
   ActiveExportColumnConfiguration get exportFieldsConfiguration => _exportFieldsConfiguration;
 
   // Procedure for adding more entries described in the settings_store.dart doc comment
-}
\ No newline at end of file
+}
app/lib/model/storage/export_pdf_settings_store.dart
@@ -63,6 +63,19 @@ class PdfExportSettings extends ChangeNotifier implements CustomFieldsSettings {
 
   String toJson() => jsonEncode(toMap());
 
+  /// Reset all fields to their default values.
+  void reset() {
+    final d = PdfExportSettings();
+    _exportTitle = d._exportTitle;
+    _exportStatistics = d._exportStatistics;
+    _exportData = d._exportData;
+    _headerHeight = d._headerHeight;
+    _cellHeight = d._cellHeight;
+    _headerFontSize = d._headerFontSize;
+    _cellFontSize = d._cellFontSize;
+    _exportFieldsConfiguration = d._exportFieldsConfiguration;
+  }
+
   bool _exportTitle = true;
   bool get exportTitle => _exportTitle;
   set exportTitle(bool value) {
app/lib/model/storage/export_settings_store.dart
@@ -37,6 +37,14 @@ class ExportSettings extends ChangeNotifier {
 
   String toJson() => jsonEncode(toMap());
 
+  /// Reset all fields to their default values.
+  void reset() {
+    final d = ExportSettings();
+    _exportFormat = d._exportFormat;
+    _defaultExportDir = d._defaultExportDir;
+    _exportAfterEveryEntry = d._exportAfterEveryEntry;
+  }
+
   ExportFormat _exportFormat = ExportFormat.csv;
   ExportFormat get exportFormat => _exportFormat;
   set exportFormat(ExportFormat value) {
app/lib/model/storage/intervall_store.dart
@@ -248,11 +248,11 @@ class IntervallStoreManager extends ChangeNotifier {
   }
 
   static Future<IntervallStoreManager> load(ConfigDao configDao, int profileID) async =>
-      IntervallStoreManager(
-          await configDao.loadIntervallStorage(profileID, 0),
-          await configDao.loadIntervallStorage(profileID, 1),
-          await configDao.loadIntervallStorage(profileID, 2),
-      );
+    IntervallStoreManager(
+      await configDao.loadIntervallStorage(profileID, 0),
+      await configDao.loadIntervallStorage(profileID, 1),
+      await configDao.loadIntervallStorage(profileID, 2),
+    );
 
   IntervallStorage get(IntervallStoreManagerLocation type) {
     switch (type) {
@@ -264,9 +264,21 @@ class IntervallStoreManager extends ChangeNotifier {
         return statsPage;
     }
   }
-  
+
+  /// Reset all fields to their default values.
+  void reset() {
+    mainPage = IntervallStorage();
+    exportPage = IntervallStorage();
+    statsPage = IntervallStorage();
+  }
+
+  /// Intervall for the page with graph and list.
   IntervallStorage mainPage;
+
+  /// Intervall for all exports.
   IntervallStorage exportPage;
+
+  /// Intervall to display statistics in.
   IntervallStorage statsPage;
 
   @override
@@ -278,7 +290,7 @@ class IntervallStoreManager extends ChangeNotifier {
   }
 }
 
-/// enum of all locations supported by IntervallStoreManager
+/// Locations supported by [IntervallStoreManager].
 enum IntervallStoreManagerLocation {
   mainPage,
   exportPage,
app/lib/model/storage/settings_store.dart
@@ -123,36 +123,66 @@ class Settings extends ChangeNotifier {
 
   /// Serialize the object to a restoreable map.
   Map<String, dynamic> toMap() => <String, dynamic>{
-      'accentColor': accentColor.value,
-      'sysColor': sysColor.value,
-      'diaColor': diaColor.value,
-      'pulColor': pulColor.value,
-      'dateFormatString': dateFormatString,
-      'graphLineThickness': graphLineThickness,
-      'animationSpeed': animationSpeed,
-      'sysWarn': sysWarn,
-      'diaWarn': diaWarn,
-      'allowManualTimeInput': allowManualTimeInput,
-      'confirmDeletion': confirmDeletion,
-      'themeMode': themeMode.serialize(),
-      'validateInputs': validateInputs,
-      'allowMissingValues': allowMissingValues,
-      'drawRegressionLines': drawRegressionLines,
-      'startWithAddMeasurementPage': startWithAddMeasurementPage,
-      'useLegacyList': useLegacyList,
-      'language': ConvertUtil.serializeLocale(language),
-      'horizontalGraphLines': horizontalGraphLines.map(jsonEncode).toList(),
-      'needlePinBarWidth': _needlePinBarWidth,
-      'lastVersion': lastVersion,
-      'bottomAppBars': bottomAppBars,
-      'medications': medications.map(jsonEncode).toList(),
-      'highestMedIndex': highestMedIndex,
-      'preferredPressureUnit': preferredPressureUnit.encode(),
+    'accentColor': accentColor.value,
+    'sysColor': sysColor.value,
+    'diaColor': diaColor.value,
+    'pulColor': pulColor.value,
+    'dateFormatString': dateFormatString,
+    'graphLineThickness': graphLineThickness,
+    'animationSpeed': animationSpeed,
+    'sysWarn': sysWarn,
+    'diaWarn': diaWarn,
+    'allowManualTimeInput': allowManualTimeInput,
+    'confirmDeletion': confirmDeletion,
+    'themeMode': themeMode.serialize(),
+    'validateInputs': validateInputs,
+    'allowMissingValues': allowMissingValues,
+    'drawRegressionLines': drawRegressionLines,
+    'startWithAddMeasurementPage': startWithAddMeasurementPage,
+    'useLegacyList': useLegacyList,
+    'language': ConvertUtil.serializeLocale(language),
+    'horizontalGraphLines': horizontalGraphLines.map(jsonEncode).toList(),
+    'needlePinBarWidth': _needlePinBarWidth,
+    'lastVersion': lastVersion,
+    'bottomAppBars': bottomAppBars,
+    'medications': medications.map(jsonEncode).toList(),
+    'highestMedIndex': highestMedIndex,
+    'preferredPressureUnit': preferredPressureUnit.encode(),
     };
 
   /// Serialize the object to a restoreable string.
   String toJson() => jsonEncode(toMap());
 
+  /// Reset all fields to their default values.
+  void reset() {
+    final d = Settings();
+    _language = d._language;
+    _accentColor = d._accentColor;
+    _sysColor = d._sysColor;
+    _diaColor = d._diaColor;
+    _pulColor = d._pulColor;
+    _horizontalGraphLines = d._horizontalGraphLines;
+    _dateFormatString = d._dateFormatString;
+    _graphLineThickness = d._graphLineThickness;
+    _needlePinBarWidth = d._needlePinBarWidth;
+    _animationSpeed = d._animationSpeed;
+    _sysWarn = d._sysWarn;
+    _diaWarn = d._diaWarn;
+    _lastVersion = d._lastVersion;
+    _allowManualTimeInput = d._allowManualTimeInput;
+    _confirmDeletion = d._confirmDeletion;
+    _themeMode = d._themeMode;
+    _validateInputs = d._validateInputs;
+    _allowMissingValues = d._allowMissingValues;
+    _drawRegressionLines = d._drawRegressionLines;
+    _startWithAddMeasurementPage = d._startWithAddMeasurementPage;
+    _useLegacyList = d._useLegacyList;
+    _bottomAppBars = d._bottomAppBars;
+    _medications.clear();
+    _highestMedIndex = d._highestMedIndex;
+    _preferredPressureUnit = d._preferredPressureUnit;
+  }
+
   Locale? _language;
   /// Language to use the app in.
   ///
app/lib/model/storage/storage.dart
@@ -7,6 +7,7 @@
 /// - Add private variable with default value
 /// - Add getter and setter, where setter calls `notifyListeners()`
 /// - Add as nullable to constructor definition and if != null assign it to the private variable in the body
+/// - Reset the value to default in a `reset` method
 /// - Add parsable representation (string, boolean or integer) to the .toMap
 /// - Parse it in the .fromMap factory method
 /// - Make sure edge cases are handled in .fromMap (does not exist (update), not parsable (user))