Mercurial > hg > forks > UniversalIndentGUI
comparison src/UiGuiIniFileParser.cpp @ 751:ac165b6ae67e
Done some refactoring:
- Moved includes into the cpp files where possible and using class pre-declarations if possible
- Made class member variable names begin with an underscore
- Made by uic created header files be used as class members instead of inherting them
- Renamed some variables to reflect their purpose better
- Added some NULL initializations and added some comments
- Rearranged some include and declaration code parts to be consistent and better readable
- Updated for QScintilla 2.4.5
- Made UiGuiSettings be accessed via a shared pointer only
git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1028 59b1889a-e5ac-428c-b0c7-476e01d41282
author | thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282> |
---|---|
date | Thu, 14 Oct 2010 19:52:47 +0000 |
parents | 3ee67782b40a |
children | 302411a51c00 |
comparison
equal
deleted
inserted
replaced
750:a884b5861e93 | 751:ac165b6ae67e |
---|---|
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
18 ***************************************************************************/ | 18 ***************************************************************************/ |
19 | 19 |
20 #include "UiGuiIniFileParser.h" | 20 #include "UiGuiIniFileParser.h" |
21 | 21 |
22 #include <QFile> | |
23 #include <QStringList> | |
24 #include <QVariant> | |
22 #include <QTextStream> | 25 #include <QTextStream> |
23 | 26 |
24 //! \defgroup grp_Settings All concerning applications settings. | 27 //! \defgroup grp_Settings All concerning applications settings. |
25 | 28 |
26 /*! | 29 /*! |
39 | 42 |
40 /*! | 43 /*! |
41 \brief Init and empty all needed lists and strings. | 44 \brief Init and empty all needed lists and strings. |
42 */ | 45 */ |
43 UiGuiIniFileParser::UiGuiIniFileParser(void) { | 46 UiGuiIniFileParser::UiGuiIniFileParser(void) { |
44 sections.clear(); | 47 _sections.clear(); |
45 keyValueMap.clear(); | 48 _keyValueMap.clear(); |
46 iniFileName = ""; | 49 _iniFileName = ""; |
47 } | 50 } |
48 | 51 |
49 | 52 |
50 /*! | 53 /*! |
51 \brief Directly loads and parses the file with name \a iniFileName. | 54 \brief Directly loads and parses the file with name \a iniFileName. |
52 */ | 55 */ |
53 UiGuiIniFileParser::UiGuiIniFileParser(const QString &iniFileName) { | 56 UiGuiIniFileParser::UiGuiIniFileParser(const QString &iniFileName) { |
54 UiGuiIniFileParser(); | 57 UiGuiIniFileParser(); |
55 this->iniFileName = iniFileName; | 58 _iniFileName = iniFileName; |
56 parseIniFile(); | 59 parseIniFile(); |
57 } | 60 } |
58 | 61 |
59 | 62 |
60 UiGuiIniFileParser::~UiGuiIniFileParser(void) { | 63 UiGuiIniFileParser::~UiGuiIniFileParser(void) { |
65 \brief Returns the group/section names in the same order as they occurr in the ini file as QStringList. | 68 \brief Returns the group/section names in the same order as they occurr in the ini file as QStringList. |
66 */ | 69 */ |
67 QStringList UiGuiIniFileParser::childGroups() { | 70 QStringList UiGuiIniFileParser::childGroups() { |
68 QStringList sectionsStringList; | 71 QStringList sectionsStringList; |
69 | 72 |
70 for( unsigned int i = 0; i < sections.size(); i++ ) { | 73 for( unsigned int i = 0; i < _sections.size(); i++ ) { |
71 sectionsStringList << sections[i]; | 74 sectionsStringList << _sections[i]; |
72 } | 75 } |
73 | 76 |
74 return sectionsStringList; | 77 return sectionsStringList; |
75 } | 78 } |
76 | 79 |
82 For example if you wish to access the value of the following setting: | 85 For example if you wish to access the value of the following setting: |
83 <code>[NiceSection]</br>niceKeyName=2</code> you would have to call | 86 <code>[NiceSection]</br>niceKeyName=2</code> you would have to call |
84 value("NiceSection/niceKeyName"). | 87 value("NiceSection/niceKeyName"). |
85 */ | 88 */ |
86 QVariant UiGuiIniFileParser::value(const QString &keyName, const QString &defaultValue) { | 89 QVariant UiGuiIniFileParser::value(const QString &keyName, const QString &defaultValue) { |
87 return keyValueMap.value( keyName, defaultValue ); | 90 return _keyValueMap.value( keyName, defaultValue ); |
88 } | 91 } |
89 | 92 |
90 | 93 |
91 /*! | 94 /*! |
92 \brief Parses the ini file and stores the key value pairs in the internal vectors \a keys and \a values. | 95 \brief Parses the ini file and stores the key value pairs in the internal vectors \a keys and \a values. |
93 */ | 96 */ |
94 void UiGuiIniFileParser::parseIniFile() { | 97 void UiGuiIniFileParser::parseIniFile() { |
95 QFile iniFile(iniFileName); | 98 QFile iniFile(_iniFileName); |
96 | 99 |
97 if ( iniFile.open(QFile::ReadOnly) ) { | 100 if ( iniFile.open(QFile::ReadOnly) ) { |
98 // Clear the vectors holding the keys and values. | 101 // Clear the vectors holding the keys and values. |
99 sections.clear(); | 102 _sections.clear(); |
100 keyValueMap.clear(); | 103 _keyValueMap.clear(); |
101 | 104 |
102 QTextStream iniFileStream( &iniFile ); | 105 QTextStream iniFileStream( &iniFile ); |
103 QString line; | 106 QString line; |
104 QString currentSectionName = ""; | 107 QString currentSectionName = ""; |
105 QString keyName = ""; | 108 QString keyName = ""; |
112 if ( line.startsWith("[") && line.endsWith("]") ) { | 115 if ( line.startsWith("[") && line.endsWith("]") ) { |
113 currentSectionName = line.remove(0, 1); | 116 currentSectionName = line.remove(0, 1); |
114 currentSectionName.chop(1); | 117 currentSectionName.chop(1); |
115 | 118 |
116 // Store the section name. | 119 // Store the section name. |
117 sections.push_back( currentSectionName ); | 120 _sections.push_back( currentSectionName ); |
118 } | 121 } |
119 // Otherwise test whether the line has a assign char | 122 // Otherwise test whether the line has a assign char |
120 else if ( line.contains("=") ) { | 123 else if ( line.contains("=") ) { |
121 int indexOfFirstAssign = line.indexOf("="); | 124 int indexOfFirstAssign = line.indexOf("="); |
122 keyName = line.left(indexOfFirstAssign); | 125 keyName = line.left(indexOfFirstAssign); |
133 if ( !currentSectionName.isEmpty() ) { | 136 if ( !currentSectionName.isEmpty() ) { |
134 keyName = currentSectionName + "/" + keyName; | 137 keyName = currentSectionName + "/" + keyName; |
135 } | 138 } |
136 | 139 |
137 // Store the key and value in the map. | 140 // Store the key and value in the map. |
138 keyValueMap.insert(keyName, valueAsString ); | 141 _keyValueMap.insert(keyName, valueAsString ); |
139 } | 142 } |
140 } | 143 } |
141 } | 144 } |
142 } | 145 } |
143 } | 146 } |