From: Enar Väikene Date: Wed, 5 Oct 2011 11:26:01 +0000 (+0300) Subject: More work with the IniFile class: X-Git-Url: https://vaikene.ee/gitweb/pswgen11.html?a=commitdiff_plain;h=555fa9e86134fda6e631e9178e50b444b1079e4f;p=evaf More work with the IniFile class: * Uses the last '/' character to separate section names from key names. 'extensions/about/module' means now section name 'extensions/about' and key name 'module'. * Fixed reading platform-specific parameters where we forgot to store the thisOsOnly flag. * Fixed writing parameters where we forgot to update the internal cache. --- diff --git a/src/libs/Common/IniFile b/src/libs/Common/IniFile new file mode 100644 index 0000000..f1ae13e --- /dev/null +++ b/src/libs/Common/IniFile @@ -0,0 +1 @@ +#include "inifile.h" diff --git a/src/libs/Common/inifile.cpp b/src/libs/Common/inifile.cpp index 28e700f..2b21d55 100644 --- a/src/libs/Common/inifile.cpp +++ b/src/libs/Common/inifile.cpp @@ -231,6 +231,7 @@ QExplicitlySharedDataPointer IniFileImpl::getParameter(QFile & fil valueObject = new IniFileValue(currentPos); valueObject->name = name; valueObject->paramValue = value; + valueObject->thisOsOnly = thisOsOnly; section.values.insert(name, valueObject); } else { @@ -238,6 +239,7 @@ QExplicitlySharedDataPointer IniFileImpl::getParameter(QFile & fil valueObject = *it; valueObject->name = name; valueObject->paramValue = value; + valueObject->thisOsOnly = thisOsOnly; } // Is this the parameter vwe are looking for? @@ -257,7 +259,7 @@ QExplicitlySharedDataPointer IniFileImpl::getParameter(QFile & fil QVariant IniFileImpl::getValue(QString const & paramName, QVariant const & defaultValue) { // Locate the '/' character that separates section names from key names - int idx = paramName.indexOf('/'); + int idx = paramName.lastIndexOf('/'); if (idx < 0) return defaultValue; @@ -293,7 +295,7 @@ QVariant IniFileImpl::getValue(QString const & paramName, QVariant const & defau bool IniFileImpl::setValue(QString const & paramName, QVariant const & value) { // Locate the '/' character that separates section names from key names - int idx = paramName.indexOf('/'); + int idx = paramName.lastIndexOf('/', -1); if (idx < 0) return false; @@ -455,6 +457,9 @@ bool IniFileImpl::setValue(QString const & paramName, QVariant const & value) if (diff) updateCache(currentPos, diff); + // Update the parameter value in the internal cache + valueObject->paramValue = valueString; + } f.close(); diff --git a/src/libs/Common/inifile.h b/src/libs/Common/inifile.h index b795e6a..705bd9b 100644 --- a/src/libs/Common/inifile.h +++ b/src/libs/Common/inifile.h @@ -35,12 +35,25 @@ namespace Internal { /** * Class for reading and writing parameter values in INI files. * - * The IniFile class provides access to parameter values in a standard INI file. Every parameter value is - * identified by a section/key name pair. Key names can be prefixed with 'windows:' or 'linux:' if the - * parameter value is specific for the given platform. This allows entering platform-specific parameter - * values to the INI file. INI files can contain comment lines that start with ';' or '#'. Comments are + * The IniFile class provides access to parameter values in a standard INI file. + * Every parameter value is identified by a section/key name pair. Key names can be prefixed with + * 'windows:' or 'linux:' if the parameter value is specific for the given platform. + * This allows entering platform-specific parameter values to the INI file. + * + * INI files can contain comment lines that start with ';' or '#'. Comments are * preserved when new values are written to the INI file. * + * This is a sample INI file: + * @code + * [main] + * # The full name of this parameter is 'main/name' + * name = MyApplication + * + * [extensions/about] + * # The full name of this parameter is 'extensions/about/module' + * module = libabout.so + * @endcode + * * Values in INI files are stored as strings and the IniFile class expects them to use specific formats if * the returned value is supposed to be of a different data type. The following list shows the expected format * of different data types: