Public Member Functions
Ini Class Reference

INI configuration files handler. More...

#include <ini.h>

List of all members.

Public Member Functions

 Ini (const QString &filename)
IniSection createSection (const QString &name)
IniVariable createSetting (const QString &sectionname, const QString &name, const QVariant &data)
void deleteSection (const QString &sectionname)
void deleteSetting (const QString &sectionname, 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 &sectionname, const QString &variablename)
bool save ()
IniSection section (const QString &name)
QVector< IniSectionsectionsArray (const QString &regexPattern)
IniVariable setting (const QString &sectionname, const QString &variablename)
void setValue (const QString &key, const QVariant &value)
QVariant value (const QString &key) const

Detailed Description

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"

Constructor & Destructor Documentation

Ini::Ini ( const QString &  filename)

Constructor that will load the file from a drive.


Member Function Documentation

IniSection Ini::createSection ( const QString &  name)

No change to the data will be made if section already exists.

Returns:
Newly created or existing section.
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.

Returns:
Newly created or existing setting.
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.

Parameters:
filePathFull path to the INI file.
Returns:
True if load was successful.
IniSection Ini::retrieveSection ( const QString &  name)

This method will not create a new section if it doesn't exist yet.

Returns:
NULL if section doesn't exist or a pointer to internally stored IniSection object. Do not delete this object.
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.

Returns:
A reference to the internally stored IniVariable if it does. Be sure to check if it isNull.
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").

Returns:
NULL if section doesn't exist or a pointer to internally stored IniSection object. Do not delete this object.
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:

See also:
retrieveSetting().
Returns:
Returns a pointer to a IniVariable object. Do not delete this object.

The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator