subsurface/core/settings
Berthold Stoeger a89b36c661 Cleanup: don't instantiate a QPref object
QPref has only static functions. There seems to be no point in
instantiating a singleton of this object. Remove the instance()
method and remove the Q_OBJECT macro.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-04 09:29:45 -07:00
..
qPref.cpp Cleanup: don't instantiate a QPref object 2019-04-04 09:29:45 -07:00
qPref.h Cleanup: don't instantiate a QPref object 2019-04-04 09:29:45 -07:00
qPrefCloudStorage.cpp Prefs: add bool preference cloud_auto_sync [1/3] 2018-10-09 10:03:21 -07:00
qPrefCloudStorage.h Prefs: add bool preference cloud_auto_sync [1/3] 2018-10-09 10:03:21 -07:00
qPrefDisplay.cpp cleanup: do not compare doubles like this 2018-09-25 16:01:39 +02:00
qPrefDisplay.h qPref: add mobile_scale preference 2018-09-25 15:58:17 +02:00
qPrefDiveComputer.cpp Bluetooth cleanup: remove pointless download_mode 2018-10-15 19:46:18 +02:00
qPrefDiveComputer.h Bluetooth cleanup: remove pointless download_mode 2018-10-15 19:46:18 +02:00
qPrefDivePlanner.cpp Add UI element for final surface segment in planner 2019-03-29 06:51:12 -07:00
qPrefDivePlanner.h Add UI element for final surface segment in planner 2019-03-29 06:51:12 -07:00
qPrefGeneral.cpp Mobile/filtering: add two preferences for filtering 2018-10-23 22:45:30 +01:00
qPrefGeneral.h Mobile/filtering: add two preferences for filtering 2018-10-23 22:45:30 +01:00
qPrefGeocoding.cpp core/settings: add missing empty line. 2018-09-11 17:22:58 -07:00
qPrefGeocoding.h core/settings: add missing empty line. 2018-09-11 17:22:58 -07:00
qPrefLanguage.cpp qPref: use helper function to ensure key/name grouping 2018-09-07 14:37:18 -07:00
qPrefLanguage.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefLocationService.cpp core/settings: add missing empty line. 2018-09-11 17:22:58 -07:00
qPrefLocationService.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefPartialPressureGas.cpp core/settings: add missing empty line. 2018-09-11 17:22:58 -07:00
qPrefPartialPressureGas.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefPrivate.cpp qPref: don't compare doubles for equality 2018-09-25 15:58:17 +02:00
qPrefPrivate.h qPref: add ability to remember recently used dive computers 2018-09-23 11:49:30 -07:00
qPrefProxy.cpp core/settings: add missing empty line. 2018-09-11 17:22:58 -07:00
qPrefProxy.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefTechnicalDetails.cpp Add button to toggle deco info in info box 2019-02-05 14:18:14 +01:00
qPrefTechnicalDetails.h Add button to toggle deco info in info box 2019-02-05 14:18:14 +01:00
qPrefUnit.cpp Mobile: always update the preferences when set_unit_system is called 2018-09-19 14:41:34 -07:00
qPrefUnit.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefUpdateManager.cpp core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
qPrefUpdateManager.h core/setting: change *_changed to *Changed for the sake of QML. 2018-09-11 17:22:58 -07:00
README.md core/settings: add README 2018-08-30 05:36:36 -07:00

Short explanation of how qPref works

System startup:

core/qt-init.cpp init_qt_late()

does

qPref::load();

to load all properties from all qPref* classes

System shutdown:

subsurface-mobile-main.cpp and subsurface-desktop-main.cpp main()

calls

call qPref::sync()

to save all changes to disk, this is needed because part of the program modifies struct preferences instead of calling the set method.

EXCEPTION:

Variables not present in struct preferences (local static variables in the class are not written, see later.

System startup/shutdown common handling:

qPref::load() calls qPref::doSync(false)
qPref::sync() calls qPref::doSync(true)

qPrefDoSync()

qPref::doSync() calls qPref::doSync() for all qPref* classes Meaning qPref knows which classes exist, but not which variables

qPref*::doSync() calls

disk_<variable name>() for each variable

EXCEPTION:

some variables are not in struct preferences, but local static variables which can only be accessed through the set/get functions, therefore there are no need to sync them

	if (!doSync) // meaining load
		load_<variable_name>()

qPref*::disk_*()

qPref*::disk_*() calls qPrefPrivate::propSetValue to save a property, and qPrefPrivate::propValue() to read a property. The function also keeps struct preferences in sync.

qPrefPrivate::propSetValue()

qPrefPrivate::propSetValue() is static and calls QSettings to write property

qPrefPrivate::propValue()

qPrefPrivate::propValue() is static and calls QSettings to read property

macros

the macros are defined in qPrefPrivate.h

the macros are used in qPref*cpp

Reading properties

Reading a property is done through an inline function, and thus no more expensive than accessing the variable directly.

qPref*::<variable_name>()

Setting properties

Setting a property is done through a dedicated set function which are static to simplify the call:

qPref<class>::set_<variable_name>(value)

like:

qPrefDisplay::animation_speed(500);

the set function updates struct preferences (if not a local variable), and saves the property to disk, however save is only done if the variable is changed.

Updating struct preferences

When a program part updates struct preferences directly, changes are NOT saved to disk if the programm crashes, otherwise all variables are saved to disk with the program exists.