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>

Classes

class  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 (bool app=false)
 Constructor initializing the instance using ApplicationSettings::global().getNewSettings().
 
 ConfigStore (const ConfigStore &cs)
 Copy constructor. Creates a duplicate instance of the passed config store.
 
 ConfigStore (const QString &filepath, QSettings::Format format)
 Constructor creating.
 
 ConfigStore (const QSettings &settings)
 Constructor creating a copy of a passed store.
 
 ConfigStore (ConfigStore &&) noexcept
 Move constructor.
 
ConfigStoreoperator= (const ConfigStore &) noexcept
 Copy operator.
 
ConfigStoreoperator= (ConfigStore &&) noexcept
 Move operator.
 
 ~ConfigStore ()
 Overridden destructor.
 
ConfigStoreassign (const ConfigStore &cs)
 Initializes this store with the passed instance.
 
ConfigStoresetPath (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.
 
QByteArray getByteArray (QAnyStringView section, QAnyStringView key, QByteArray def={}) const
 Gets a section's byte array value from the store.
 
void setByteArray (QAnyStringView section, QAnyStringView key, const QByteArray &value)
 Sets a section's byte array value in the store.
 
QString getString (QAnyStringView section, QAnyStringView key, QAnyStringView def={}) const
 Gets a section's string value from the store.
 
void setString (QAnyStringView section, QAnyStringView key, QAnyStringView value)
 Sets a section's string value in the store.
 
QStringList getStringList (QAnyStringView section, QAnyStringView key, const QStringList &def={}) const
 Gets a section's string-list value from the store.
 
void setStringList (QAnyStringView section, QAnyStringView key, const QStringList &value)
 Sets a section's string-list value in the store.
 
std::string getStdString (const std::string &section, const std::string &key, const std::string &def={}) const
 Gets a section's 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 integer value in the store.
 
QVariant getValue (QAnyStringView section, QAnyStringView key) const
 Gets a section value from the store.
 
QVariant getValue (QAnyStringView section, QAnyStringView key, const QVariant &def) const
 Gets a section value from the store.
 
void setValue (QAnyStringView section, QAnyStringView key, const QVariant &value)
 Sets a section QVariant value in the store.
 
void storeWindow (QAnyStringView section, QAnyStringView key, QWidget *widget, bool rd)
 Stores or restores the window position and size from the settings file onto the passed widget.
 
void storeTreeView (QAnyStringView section, QAnyStringView name, const QTreeView *tv, bool rd)
 Stores or restores column widths of a QTreeView.
 
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 setSectionOffset (QAnyStringView section)
 Sets a section offset call QSettings::beginGroup().
 
void setSectionDefault (QAnyStringView section)
 Sets default section when the given section is empty '{}'.
 
QString getSectionDefault ()
 Gets default section when the given section is empty '{}'.
 
QSettings & settings ()
 Gets a reference to the settings currently used by this instance.
 
Scope scope (QAnyStringView section)
 Adds a section onto the stack of section.
 

Detailed Description

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

Constructor & Destructor Documentation

◆ ConfigStore() [1/5]

sf::ConfigStore::ConfigStore ( bool  app = false)
explicit

Constructor initializing the instance using ApplicationSettings::global().getNewSettings().

Remarks
This could in Windows case also be the registry.

◆ ConfigStore() [2/5]

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

Copy constructor. Creates a duplicate instance of the passed config store.

◆ ConfigStore() [3/5]

sf::ConfigStore::ConfigStore ( const QString &  filepath,
QSettings::Format  format 
)
explicit

Constructor creating.

Parameters
filepathPath to the configuration file.
formatLike QSettings::IniFormat

◆ ConfigStore() [4/5]

sf::ConfigStore::ConfigStore ( const QSettings &  settings)
explicit

Constructor creating a copy of a passed store.

Parameters
settingsSettings instance to initialize with.

◆ ConfigStore() [5/5]

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

Move constructor.

◆ ~ConfigStore()

sf::ConfigStore::~ConfigStore ( )

Overridden destructor.

Member Function Documentation

◆ assign()

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

Initializes this store with the passed instance.

◆ 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.

◆ getByteArray()

QByteArray sf::ConfigStore::getByteArray ( QAnyStringView  section,
QAnyStringView  key,
QByteArray  def = {} 
) const

Gets a section's byte array 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.

◆ 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.

◆ getSectionDefault()

QString sf::ConfigStore::getSectionDefault ( )

Gets default section when the given section is empty '{}'.

◆ 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.

◆ getStdString()

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

Gets a section's 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's string 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.

◆ getStringList()

QStringList sf::ConfigStore::getStringList ( QAnyStringView  section,
QAnyStringView  key,
const QStringList &  def = {} 
) const

Gets a section's string-list 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.

◆ getValue() [1/2]

QVariant sf::ConfigStore::getValue ( QAnyStringView  section,
QAnyStringView  key 
) const

Gets a section value from the store.

Parameters
sectionWhen empty '{}' the default section is used.
keyName of the key to get.
Returns
Value referenced by the given key.

◆ getValue() [2/2]

QVariant sf::ConfigStore::getValue ( QAnyStringView  section,
QAnyStringView  key,
const QVariant &  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= ( const 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

◆ scope()

Scope sf::ConfigStore::scope ( QAnyStringView  section)

Adds a section onto the stack of section.

Parameters
sectionSection or group name added.
Returns

◆ 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.

◆ setByteArray()

void sf::ConfigStore::setByteArray ( QAnyStringView  section,
QAnyStringView  key,
const QByteArray &  value 
)

Sets a section's byte array 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 integer value in the store.

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

◆ setPath()

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

Initializes this store with the passed ini-filepath.

◆ setSectionDefault()

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

Sets default section when the given section is empty '{}'.

Parameters
section

◆ setSectionOffset()

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

Sets a section offset call QSettings::beginGroup().

Parameters
sectionWhen empty the only QSettings::endGroup() is called.

◆ 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's string value in the store.

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

◆ setStringList()

void sf::ConfigStore::setStringList ( QAnyStringView  section,
QAnyStringView  key,
const QStringList &  value 
)

Sets a section's string-list value in the store.

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

◆ settings()

QSettings & sf::ConfigStore::settings ( )

Gets a reference to the settings currently used by this instance.

◆ setValue()

void sf::ConfigStore::setValue ( QAnyStringView  section,
QAnyStringView  key,
const QVariant &  value 
)

Sets a section QVariant value in the store.

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

◆ storeTreeView()

void sf::ConfigStore::storeTreeView ( QAnyStringView  section,
QAnyStringView  name,
const QTreeView *  tv,
bool  rd 
)

Stores or restores column widths of a QTreeView.

Parameters
sectionSection containing the keys.
nameName of the treeview to use as a key prefix.
tvPointer to the tree view.
rdWhen true it reads and false it writes the storage location.

◆ storeWindow()

void sf::ConfigStore::storeWindow ( QAnyStringView  section,
QAnyStringView  key,
QWidget *  widget,
bool  rd 
)

Stores or restores the window position and size from the settings file onto the passed widget.

Parameters
sectionSection containing the keys.
keyName of the window to use a key prefix.
widgetWindow widget.
rdWhen true it read from the storage location.

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