Toolbox Qt
|
Class used to manage INI configuration file. More...
Public Types | |
using | CbHook = std::function< bool(const QFileInfo &fileInfo)> |
Custom callback hook use to implement custom behaviour. | |
Public Member Functions | |
bool | loadSettings (const QFileInfo &fileInfo) |
Load settings from INI configuration file. | |
QFileInfo | getPath () const |
void | groupBegin (TB_QTCOMPAT_STR_VIEW keyGroup) |
void | groupEnd () |
void | setValue (TB_QTCOMPAT_STR_VIEW key, const QVariant &value) |
QVariant | getValue (TB_QTCOMPAT_STR_VIEW key, const QVariant &defaultValue=QVariant()) const |
void | setHooksPreLoadSettings (CbHook hookPreload) |
Use to set custom behaviour before loading settings. | |
void | setHooksPostLoadSettings (CbHook hookPostload) |
Use to set custom behaviour after loading settings. | |
Static Public Member Functions | |
static SettingsIni & | instance () |
Class used to manage INI configuration file.
This class allow to easily manage settings depending on a .ini file.
It will allow for example to not have to remember path of configuration file each time we need it !
This class used the singleton pattern, to use it, we can use:
tbq::Settings::instance()
mSettings
QSettings
already provide a way to manage other format without settings parameters each time at: https://doc.qt.io/qt-6/qsettings.html#basic-usageTo use this class in a project, we only have to initialize it in main
method:
Then we can use it anywhere with:
This class also allow to have a custom behaviour for pre and post load operations of the configuration file via setHooksPreLoadSettings() and setHooksPostLoadSettings().
We can defines custom ones like this:
Custom callback hook use to implement custom behaviour.
[in] | fileInfo | Path to configuration file used with loadSettings() |
true
).true
if succeed.bool tbq::SettingsIni::loadSettings | ( | const QFileInfo & | fileInfo | ) |
Load settings from INI configuration file.
fileInfo | INI configuration file to use |
true
if loading succeed.void tbq::SettingsIni::setHooksPostLoadSettings | ( | CbHook | hookPostload | ) |
Use to set custom behaviour after loading settings.
hookPostload | Custom callback to use |
void tbq::SettingsIni::setHooksPreLoadSettings | ( | CbHook | hookPreload | ) |
Use to set custom behaviour before loading settings.
hookPreload | Custom callback to use |