changeset 479:4f7041de0d0e

Replaced QSettings by UiguiIniFileParser to handle the uigui ini files. By this the indenter parameters no longer appear alphabetically ordered but in the same order as they occur in the uigui ini file. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@719 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Fri, 06 Jun 2008 10:41:35 +0000
parents 5417f9e5f6e5
children e9038a8e8e1f
files src/indenthandler.cpp src/indenthandler.h src/main.cpp src/uiguiIniFileParser.cpp src/uiguiIniFileParser.h
diffstat 5 files changed, 14 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/indenthandler.cpp	Fri Jun 06 10:20:44 2008 +0000
+++ b/src/indenthandler.cpp	Fri Jun 06 10:41:35 2008 +0000
@@ -101,8 +101,6 @@
 
 
 IndentHandler::~IndentHandler() {
-    //writeParameterWidgetValues2IniSettings();
-
     // Generate the parameter string that will be saved to the indenters config file.
     QString parameterString = getParameterString();
     if ( !indenterFileName.isEmpty() ) {
@@ -465,41 +463,6 @@
 
 
 /*!
-    \brief Writes all the values from the controls that influence the indenter parameters to the
-    ini file settings.
- */
-void IndentHandler::writeParameterWidgetValues2IniSettings() {
-    // Write all boolean values.
-    foreach (ParamBoolean pBoolean, paramBooleans) {
-        if ( pBoolean.checkBox->isChecked() ) {
-            indenterSettings->setValue( pBoolean.paramName + "/Value", 1);
-        }
-        else {
-            indenterSettings->setValue( pBoolean.paramName + "/Value", 0);
-        }
-    }
-
-    // Write all numeric values.
-    foreach (ParamNumeric pNumeric, paramNumerics) {
-        indenterSettings->setValue( pNumeric.paramName + "/Value", pNumeric.spinBox->value() );
-        indenterSettings->setValue( pNumeric.paramName + "/Enabled", pNumeric.valueEnabledChkBox->isChecked() );
-    }
-
-    // Write all string values.
-    foreach (ParamString pString, paramStrings) {
-        indenterSettings->setValue( pString.paramName + "/Value", pString.lineEdit->text() );
-        indenterSettings->setValue( pString.paramName + "/Enabled", pString.valueEnabledChkBox->isChecked() );
-    }
-
-    // Write all multiple choice values
-    foreach (ParamMultiple pMultiple, paramMultiples) {
-        indenterSettings->setValue( pMultiple.paramName + "/Value", pMultiple.comboBox->currentIndex () );
-        indenterSettings->setValue( pMultiple.paramName + "/Enabled", pMultiple.valueEnabledChkBox->isChecked() );
-    }
-}
-
-
-/*!
     \brief Write settings for the indenter to a config file.
  */
 void IndentHandler::writeConfigFile(QString filePathName, QString paramString) {
@@ -691,7 +654,7 @@
     Q_ASSERT_X( !iniFilePath.isEmpty(), "readIndentIniFile", "iniFilePath is empty" );
 
     // open the ini-file that contains all available indenter settings with their additional infos
-    indenterSettings = new QSettings(iniFilePath, QSettings::IniFormat, this);
+    indenterSettings = new UiguiIniFileParser(iniFilePath);
 
     QStringList categories;
     //QString indenterGroupString = "";
--- a/src/indenthandler.h	Fri Jun 06 10:20:44 2008 +0000
+++ b/src/indenthandler.h	Fri Jun 06 10:41:35 2008 +0000
@@ -43,6 +43,7 @@
 
 #include "uiguierrormessage.h"
 #include "templateBatchScript.h"
+#include "uiguiIniFileParser.h"
 
 
 class IndentHandler : public QWidget
@@ -74,7 +75,6 @@
     void writeConfigFile(QString filePathName, QString parameterString);
     void readIndentIniFile(QString iniFilePath);
     bool createIndenterCallString();
-    void writeParameterWidgetValues2IniSettings();
 
     //! Holds a reference to all created pages of the toolbox and the pages boxlayout
     struct ToolBoxPage {
@@ -125,7 +125,7 @@
 
     QVBoxLayout *vboxLayout;
     QToolBox *toolBox;
-    QSettings *indenterSettings;
+    UiguiIniFileParser *indenterSettings;
     QStringList indenterParameters;
     QByteArray cfgFileData;
     //! The indenters name in a descriptive form
--- a/src/main.cpp	Fri Jun 06 10:20:44 2008 +0000
+++ b/src/main.cpp	Fri Jun 06 10:41:35 2008 +0000
@@ -30,9 +30,6 @@
     QApplication app(argc, argv);
     QString file2OpenOnStart = "";
 
-    //UiguiIniFileParser iniParser("C:/Dokumente und Einstellungen/ts/Eigene Dateien/Visual Studio 2005/Projects/UiGui/indenters/uigui_astyle.ini");
-    //iniParser.childGroups();
-
     if ( argc > 1 ) {
         file2OpenOnStart = argv[1];
     }
--- a/src/uiguiIniFileParser.cpp	Fri Jun 06 10:20:44 2008 +0000
+++ b/src/uiguiIniFileParser.cpp	Fri Jun 06 10:41:35 2008 +0000
@@ -65,9 +65,9 @@
     <code>[NiceSection]</br>niceKeyName=2</code> you would have to call
     value("NiceSection/niceKeyName").
  */
-QVariant UiguiIniFileParser::value(const QString &keyName)
+QVariant UiguiIniFileParser::value(const QString &keyName, const QString &defaultValue)
 {
-    return keyValueMap.value(keyName, QVariant("error") );   
+    return keyValueMap.value( keyName, defaultValue );   
 }
 
 
@@ -87,7 +87,7 @@
         QString line;
         QString currentSectionName = "";
         QString keyName = "";
-        QString keyValueAsString = "";
+        QString valueAsString = "";
 
         while ( !iniFileStream.atEnd() ) {
             line = iniFileStream.readLine().trimmed();
@@ -106,7 +106,12 @@
                 keyName = line.left(indexOfFirstAssign);
 
                 if ( !keyName.isEmpty() ) {
-                    keyValueAsString = line.remove(0, indexOfFirstAssign+1);
+                    valueAsString = line.remove(0, indexOfFirstAssign+1);
+                    // Remove any existing double quotes from the value.
+                    if ( valueAsString.startsWith("\"") && valueAsString.endsWith("\"") ) {
+                        valueAsString = valueAsString.remove(0, 1);
+                        valueAsString.chop(1);
+                    }
 
                     // Prepend an eventually section name to the key name.
                     if ( !currentSectionName.isEmpty() ) {
@@ -114,7 +119,7 @@
                     }
 
                     // Store the key and value in the map.
-                    keyValueMap.insert(keyName, keyValueAsString );
+                    keyValueMap.insert(keyName, valueAsString );
                 }
             }
         }
--- a/src/uiguiIniFileParser.h	Fri Jun 06 10:20:44 2008 +0000
+++ b/src/uiguiIniFileParser.h	Fri Jun 06 10:41:35 2008 +0000
@@ -38,7 +38,7 @@
     UiguiIniFileParser(void);
     UiguiIniFileParser(const QString &iniFileName);
     ~UiguiIniFileParser(void);
-    QVariant value(const QString &keyName);
+    QVariant value(const QString &keyName, const QString &defaultValue="");
     QStringList childGroups();
 
 private: