INI configuration files handler. More...
#include <ini.h>
Public Member Functions | |
Ini (const QString &filename) | |
IniSection | createSection (const QString &name) |
IniVariable | createSetting (const QString §ionname, const QString &name, const QVariant &data) |
void | deleteSection (const QString §ionname) |
void | deleteSetting (const QString §ionname, const QString &settingname) |
bool | loadIniFile (const QString &filePath) |
Loads .ini file from drive. | |
void | removeKey (const QString &key) |
IniSection | retrieveSection (const QString &name) |
IniVariable | retrieveSetting (const QString §ionname, const QString &variablename) |
bool | save () |
IniSection | section (const QString &name) |
QVector< IniSection > | sectionsArray (const QString ®exPattern) |
IniVariable | setting (const QString §ionname, const QString &variablename) |
void | setValue (const QString &key, const QVariant &value) |
QVariant | value (const QString &key) const |
INI configuration files handler.
This class can read INI files from a disk.
This is a wrapper for QSettings class that provides a hierarchical access to the INI file. The hierarchy is resolved through the use of IniSection and IniVariable classes. The Ini class provides methods necessary to obtain valid instances of these objects.
Objects of IniSection and IniVariable classes can be copied over as they hold no actual data. They are used to generate valid paths and internally use methods provided by the Ini class objects that are associated with them. However, Ini object must remain valid when associated IniSection and IniVariable objects are in use or segmentation fault will occur.
Names of sections and variables are case sensitive.
The currently supported file format is:
[ section1 ] var1=1 var2="Exit game" [ section2 ] var1=10 var2="New Game"
Ini::Ini | ( | const QString & | filename | ) |
Constructor that will load the file from a drive.
IniSection Ini::createSection | ( | const QString & | name | ) |
No change to the data will be made if section already exists.
IniVariable Ini::createSetting | ( | const QString & | sectionname, |
const QString & | name, | ||
const QVariant & | data | ||
) |
Value of data parameter will be ignored and no changes will be performed if setting already exists.
void Ini::deleteSection | ( | const QString & | sectionname | ) |
Completely removes a given section.
void Ini::deleteSetting | ( | const QString & | sectionname, |
const QString & | settingname | ||
) |
Completely removes a given setting. This will not erase the section even if it's completely empty.
bool Ini::loadIniFile | ( | const QString & | filePath | ) |
Loads .ini file from drive.
filePath | Full path to the INI file. |
IniSection Ini::retrieveSection | ( | const QString & | name | ) |
This method will not create a new section if it doesn't exist yet.
IniVariable Ini::retrieveSetting | ( | const QString & | sectionname, |
const QString & | variablename | ||
) |
This won't create a variable if it doesn't exist and return NULL in such case.
bool Ini::save | ( | ) |
This will only work if dataSource() == Drive. If the data source is from memory there's really nowhere to save to and this will return false.
IniSection Ini::section | ( | const QString & | name | ) |
This method will attempt to retrieve an existing section. If this section does not exist a new section will be created.
This is in fact an alias to createSection() and it has been introduced to fit the IniVariable create/retrieve/setting set of methods and to avoid further confusion (ie. "why does this crash").
QVector< IniSection > Ini::sectionsArray | ( | const QString & | regexPattern | ) |
Retrieves references to all sections whose names fit a certain pattern. Please remember that internally all sections are stored as lower-case strings. The regex pattern will be instructed to ignore the case size.
IniVariable Ini::setting | ( | const QString & | sectionname, |
const QString & | variablename | ||
) |
This method will create a variable if it doesn't exist. To avoid this behavior see: