subsurface/core/settings
Dirk Hohndel 2ede1a4563 cleanup: replace deprecated methods
Sadly the replacements are new in Qt6.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2022-03-12 08:28:32 -08:00
..
qPref.cpp core: remove location service preferences 2021-09-13 11:21:34 -07:00
qPref.h
qPrefCloudStorage.cpp cloudstorage: try to pick between multiple cloud servers 2021-04-19 12:51:01 -07:00
qPrefCloudStorage.h cloudstorage: add API to just update on-disk setting 2021-04-19 12:51:01 -07:00
qPrefDisplay.cpp revert preference settings for title color 2020-11-04 14:51:55 -08:00
qPrefDisplay.h revert preference settings for title color 2020-11-04 14:51:55 -08:00
qPrefDiveComputer.cpp Preferences UI: final cleanup 2019-12-25 02:57:42 +09:00
qPrefDiveComputer.h core/settings: make qPref* constructors private 2019-12-05 11:48:26 -08:00
qPrefDivePlanner.cpp core/settings: make qPref* constructors private 2019-12-05 11:48:26 -08:00
qPrefDivePlanner.h core/settings: remove Q_PROPERTY warning in qPref headers 2019-12-05 11:48:26 -08:00
qPrefEquipment.cpp prefs: add option to display only actually used tanks 2020-12-13 11:49:59 -08:00
qPrefEquipment.h prefs: add option to display only actually used tanks 2020-12-13 11:49:59 -08:00
qPrefGeneral.cpp mobile: remove filter settings 2020-03-01 10:21:44 -08:00
qPrefGeneral.h mobile: remove filter settings 2020-03-01 10:21:44 -08:00
qPrefGeocoding.cpp Preferences UI: final cleanup 2019-12-25 02:57:42 +09:00
qPrefGeocoding.h Preferences UI: final cleanup 2019-12-25 02:57:42 +09:00
qPrefLanguage.cpp core/settings: make qPref* constructors private 2019-12-05 11:48:26 -08:00
qPrefLanguage.h core/settings: remove Q_PROPERTY warning in qPref headers 2019-12-05 11:48:26 -08:00
qPrefLog.cpp desktop UI: add preference for making salinity editable 2020-01-06 07:00:34 +09:00
qPrefLog.h desktop UI: add preference for making salinity editable 2020-01-06 07:00:34 +09:00
qPrefMedia.cpp Preferences UI: final cleanup 2019-12-25 02:57:42 +09:00
qPrefMedia.h Pereferences UI: add media tab 2019-12-25 02:57:42 +09:00
qPrefPartialPressureGas.cpp core/settings: make qPref* constructors private 2019-12-05 11:48:26 -08:00
qPrefPartialPressureGas.h core/settings: remove Q_PROPERTY warning in qPref headers 2019-12-05 11:48:26 -08:00
qPrefPrivate.cpp cleanup: replace deprecated methods 2022-03-12 08:28:32 -08:00
qPrefPrivate.h
qPrefProxy.cpp core/settings: make qPref* constructors private 2019-12-05 11:48:26 -08:00
qPrefProxy.h core/settings: remove Q_PROPERTY warning in qPref headers 2019-12-05 11:48:26 -08:00
qPrefTechnicalDetails.cpp mobile: add GF fields for ceiling calculation 2021-01-19 12:34:46 -08:00
qPrefTechnicalDetails.h Preferences UI: final cleanup 2019-12-25 02:57:42 +09:00
qPrefUnit.cpp core/settings: removed unnecessary if 2020-01-20 09:55:57 -08:00
qPrefUnit.h core/settings:: remove string functions for units 2020-01-20 09:55:26 -08:00
qPrefUpdateManager.cpp preferences: remove pointless member 2021-01-06 10:18:23 -08:00
qPrefUpdateManager.h preferences: remove pointless member 2021-01-06 10:18:23 -08:00
README.md

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.