subsurface/core/settings
Michael Keller 5fae7ce7a0 Equipment: Include Unused Tanks in Merge if Preference is Enabled.
Include unused tanks in merges of multiple logs into a single dive if
the 'Show unused cylinders' preference is enabled.
Also rename the preference (in code) to `include_unused_tanks` to
reflect the fact that it is already used in more places than just the
display (exporting, cloning dives).
Simplified the cylinder model to make forced inclusion of unused tanks
dependent on use of the model in planner.
Leaving the persisted name of the preference as `display_unused_tanks`
to avoid resetting this for all users - is there a good way to migrate
preference names?

Signed-off-by: Michael Keller <github@ike.ch>
2023-07-25 11:19:03 +12: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
qPrefDisplay.cpp core: move floating point functions to own header file 2022-08-30 22:34:38 +02:00
qPrefDisplay.h cleanup: fix compiler warnings in recently edited files. 2022-08-21 18:53:35 -07:00
qPrefDiveComputer.cpp Import: Add option to sync time on dive computer download 2023-04-17 07:56:02 -07:00
qPrefDiveComputer.h Import: Add option to sync time on dive computer download 2023-04-17 07:56:02 -07:00
qPrefDivePlanner.cpp
qPrefDivePlanner.h
qPrefEquipment.cpp Equipment: Include Unused Tanks in Merge if Preference is Enabled. 2023-07-25 11:19:03 +12:00
qPrefEquipment.h Equipment: Include Unused Tanks in Merge if Preference is Enabled. 2023-07-25 11:19:03 +12:00
qPrefGeneral.cpp
qPrefGeneral.h
qPrefGeocoding.cpp
qPrefGeocoding.h
qPrefLanguage.cpp
qPrefLanguage.h
qPrefLog.cpp
qPrefLog.h
qPrefMedia.cpp
qPrefMedia.h
qPrefPartialPressureGas.cpp
qPrefPartialPressureGas.h
qPrefPrivate.cpp core: move floating point functions to own header file 2022-08-30 22:34:38 +02:00
qPrefPrivate.h
qPrefProxy.cpp
qPrefProxy.h
qPrefTechnicalDetails.cpp Desktop: Add a Button to Hide the Infobox in the Dive Profile. 2023-06-25 14:40:23 +02:00
qPrefTechnicalDetails.h Desktop: Add a Button to Hide the Infobox in the Dive Profile. 2023-06-25 14:40:23 +02:00
qPrefUnit.cpp
qPrefUnit.h
qPrefUpdateManager.cpp
qPrefUpdateManager.h
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.