Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
sf::ConfigStore Class Referencefinal

Class to store application configuration. Uses the global application settings or a given ini-file. More...

#include <ConfigStore.h>

Inheritance diagram for sf::ConfigStore:
Collaboration diagram for sf::ConfigStore:

Classes

struct  Scope
 Begins and ends a scope of settings for a section. When create it calls beginGroup(...) and when out of scop it calls endGroup(). More...
 
class  Values
 Type to create a string list accessible by keys. More...
 

Public Member Functions

 ConfigStore (QObject *parent=nullptr)
 Qt constructor initializing the instance using ApplicationSettings::global().
 
 ConfigStore (const QString &path, QObject *parent=nullptr)
 Constructor creating a store from the given filepath.
 
 ConfigStore (const ConfigStore &cs)
 Copy constructor.
 
 ConfigStore (ConfigStore &&) noexcept
 Move constructor.
 
ConfigStoreoperator= (ConfigStore &) noexcept
 Copy operator.
 
ConfigStoreoperator= (ConfigStore &&) noexcept
 Move operator.
 
 ~ConfigStore () override
 Overridden destructor.
 
ConfigStoreassign (const ConfigStore &cfg_store)
 Initializes this store with the passed instance.
 
ConfigStoreassign (const QString &filepath)
 Initializes this store with the passed ini-filepath.
 
QSettings & operator() ()
 Operator to get access to underlying QSettings object of this instance.
 
QString getPath () const
 Gets the path of the current instance.
 
void setKeyPrefix (QAnyStringView prefix)
 Sets the prefix for key names.
 
QString getKeyPrefix () const
 Gets the prefix for key names.
 
QString getString (QAnyStringView section, QAnyStringView key, QAnyStringView def={}) const
 Gets a section value from the store.
 
void setString (QAnyStringView section, QAnyStringView key, QAnyStringView value)
 Sets a section value in the store.
 
std::string getStdString (const std::string &section, const std::string &key, const std::string &def) const
 Gets a section value from the store.
 
void setStdString (const std::string &section, const std::string &key, const std::string &value)
 Sets a section value in the store.
 
bool getBool (QAnyStringView section, QAnyStringView key, bool def) const
 Gets a section value from the store.
 
void setBool (QAnyStringView section, QAnyStringView key, bool value)
 Sets a section value in the store.
 
double getFloat (QAnyStringView section, QAnyStringView key, double def) const
 Gets a section value from the store.
 
void setFloat (QAnyStringView section, QAnyStringView key, double value)
 Sets a section value in the store.
 
int getInt (QAnyStringView section, QAnyStringView key, int def=0) const
 Gets a section value from the store.
 
void setInt (QAnyStringView section, QAnyStringView key, int value)
 Sets a section value in the store.
 
void getKeys (QAnyStringView section, QStringList &keys) const
 Gets all keys from the given section.
 
QStringList getKeys (QAnyStringView section) const
 Gets all keys from the given section.
 
void removeKeys (QAnyStringView section)
 Deletes the keys but keeps the group/section.
 
void removeSection (QAnyStringView section)
 Deletes all keys including the section.
 
bool isSection (QAnyStringView section) const
 Check if a section exists.
 
void removeKey (QAnyStringView section, QAnyStringView key)
 Removes the given key from the store.
 
void setSectionValues (QAnyStringView section, const Values &values)
 Replaces the section content with the given key-values.
 
void getSectionValues (QAnyStringView section, Values &values) const
 Gets the section content as mapped key-values.
 
QStringList getSections () const
 Gets all sections from the store in a list.
 
bool exists ()
 Checks if the path exists.
 
void setSectionDefault (QAnyStringView section)
 Default section when the section is empty '{}'.
 
QSettings & getSettings ()
 

Detailed Description

Class to store application configuration. Uses the global application settings or a given ini-file.

Constructor & Destructor Documentation

◆ ConfigStore() [1/4]

sf::ConfigStore::ConfigStore ( QObject *  parent = nullptr)
explicit

Qt constructor initializing the instance using ApplicationSettings::global().

Remarks
This could in Windows case also be the registry.
Parameters
parentOwner of the object.

◆ ConfigStore() [2/4]

sf::ConfigStore::ConfigStore ( const QString &  path,
QObject *  parent = nullptr 
)
explicit

Constructor creating a store from the given filepath.

Parameters
pathFile to use as ini format.
parentOwner of the object.

◆ ConfigStore() [3/4]

sf::ConfigStore::ConfigStore ( const ConfigStore cs)
explicit

Copy constructor.

◆ ConfigStore() [4/4]

sf::ConfigStore::ConfigStore ( ConfigStore &&  )
explicitnoexcept

Move constructor.

◆ ~ConfigStore()

sf::ConfigStore::~ConfigStore ( )
override

Overridden destructor.

Member Function Documentation

◆ assign() [1/2]

ConfigStore & sf::ConfigStore::assign ( const ConfigStore cfg_store)

Initializes this store with the passed instance.

◆ assign() [2/2]

ConfigStore & sf::ConfigStore::assign ( const QString &  filepath)

Initializes this store with the passed ini-filepath.

◆ exists()

bool sf::ConfigStore::exists ( )

Checks if the path exists.

Returns
True when it exists.

◆ getBool()

bool sf::ConfigStore::getBool ( QAnyStringView  section,
QAnyStringView  key,
bool  def 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
defDefault value when the key is not found in the store.
Returns
Value referenced by the given key.

◆ getFloat()

double sf::ConfigStore::getFloat ( QAnyStringView  section,
QAnyStringView  key,
double  def 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
defDefault value when the key is not found in the store.
Returns
Value referenced by the given key.

◆ getInt()

int sf::ConfigStore::getInt ( QAnyStringView  section,
QAnyStringView  key,
int  def = 0 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
defDefault value when the key is not found in the store.
Returns
Value referenced by the given key.

◆ getKeyPrefix()

QString sf::ConfigStore::getKeyPrefix ( ) const

Gets the prefix for key names.

◆ getKeys() [1/2]

QStringList sf::ConfigStore::getKeys ( QAnyStringView  section) const

Gets all keys from the given section.

Parameters
sectionSection containing the keys.
Returns
Keys as a string list.

◆ getKeys() [2/2]

void sf::ConfigStore::getKeys ( QAnyStringView  section,
QStringList &  keys 
) const

Gets all keys from the given section.

Parameters
sectionSection containing the keys.
keysReturn value.

◆ getPath()

QString sf::ConfigStore::getPath ( ) const

Gets the path of the current instance.

Returns
Filepath or a registry path.

◆ getSections()

QStringList sf::ConfigStore::getSections ( ) const

Gets all sections from the store in a list.

◆ getSectionValues()

void sf::ConfigStore::getSectionValues ( QAnyStringView  section,
Values values 
) const

Gets the section content as mapped key-values.

Parameters
sectionName of the section.
valuesKey and value map.

◆ getSettings()

QSettings & sf::ConfigStore::getSettings ( )
Returns

◆ getStdString()

std::string sf::ConfigStore::getStdString ( const std::string &  section,
const std::string &  key,
const std::string &  def 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
defDefault value when the key is not found in the store.
Returns
Value referenced by the given key.

◆ getString()

QString sf::ConfigStore::getString ( QAnyStringView  section,
QAnyStringView  key,
QAnyStringView  def = {} 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
defDefault value when the key is not found in the store.
Returns
Value referenced by the given key.

◆ isSection()

bool sf::ConfigStore::isSection ( QAnyStringView  section) const

Check if a section exists.

Parameters
sectionName of the section.
Returns
True, when the section exists.

◆ operator()()

QSettings & sf::ConfigStore::operator() ( )

Operator to get access to underlying QSettings object of this instance.

Remarks
Only use when really needed.

◆ operator=() [1/2]

ConfigStore & sf::ConfigStore::operator= ( ConfigStore &&  )
noexcept

Move operator.

◆ operator=() [2/2]

ConfigStore & sf::ConfigStore::operator= ( ConfigStore )
noexcept

Copy operator.

◆ removeKey()

void sf::ConfigStore::removeKey ( QAnyStringView  section,
QAnyStringView  key 
)

Removes the given key from the store.

Parameters
section
key

◆ removeKeys()

void sf::ConfigStore::removeKeys ( QAnyStringView  section)

Deletes the keys but keeps the group/section.

Parameters
section

◆ removeSection()

void sf::ConfigStore::removeSection ( QAnyStringView  section)

Deletes all keys including the section.

Parameters
section

◆ setBool()

void sf::ConfigStore::setBool ( QAnyStringView  section,
QAnyStringView  key,
bool  value 
)

Sets a section value in the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to set.
valueValue to set.

◆ setFloat()

void sf::ConfigStore::setFloat ( QAnyStringView  section,
QAnyStringView  key,
double  value 
)

Sets a section value in the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to set.
valueValue to set.

◆ setInt()

void sf::ConfigStore::setInt ( QAnyStringView  section,
QAnyStringView  key,
int  value 
)

Sets a section value in the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to set.
valueValue to set.

◆ setKeyPrefix()

void sf::ConfigStore::setKeyPrefix ( QAnyStringView  prefix)

Sets the prefix for key names.

Parameters
prefixNames used as prefix.

◆ setSectionDefault()

void sf::ConfigStore::setSectionDefault ( QAnyStringView  section)

Default section when the section is empty '{}'.

Parameters
section

◆ setSectionValues()

void sf::ConfigStore::setSectionValues ( QAnyStringView  section,
const Values values 
)

Replaces the section content with the given key-values.

Parameters
sectionName of the section.
valuesKey and value map.

◆ setStdString()

void sf::ConfigStore::setStdString ( const std::string &  section,
const std::string &  key,
const std::string &  value 
)

Sets a section value in the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to set.
valueValue to set.

◆ setString()

void sf::ConfigStore::setString ( QAnyStringView  section,
QAnyStringView  key,
QAnyStringView  value 
)

Sets a section value in the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to set.
valueValue to set.

The documentation for this class was generated from the following file: