Fix for segfault when deleting MCO (invalid QModelIndex needs to be returned in index(TreeItem*) )
6 /////////////////////////////////////////////////////////////////
8 /////////////////////////////////////////////////////////////////
9 SimpleSettings::SimpleSettings()
14 SimpleSettings::~SimpleSettings()
18 void SimpleSettings::clear()
24 void SimpleSettings::readSettings (const QString &path)
27 if (!loadStringFromDisk(path,s))
29 qWarning ("SimpleSettings::readSettings() Couldn't read "+path);
33 lines=QStringList::split (QRegExp("\n"),s,false);
35 QStringList::Iterator it=lines.begin();
36 while (it !=lines.end() )
39 keylist.append((*it).left(i));
40 valuelist.append((*it).right((*it).length()-i-1));
45 void SimpleSettings::writeSettings (const QString &path)
48 QStringList::Iterator itk=keylist.begin();
49 QStringList::Iterator itv=valuelist.begin();
51 // First search for value in settings saved in map
52 while (itk !=keylist.end() )
54 s+=*itk+"="+*itv+"\n";
58 if (!saveStringToDisk(path,s))
59 qWarning ("SimpleSettings::writeSettings() Couldn't write "+path);
63 QString SimpleSettings::readEntry (const QString &key)
65 QStringList::Iterator itk=keylist.begin();
66 QStringList::Iterator itv=valuelist.begin();
68 // First search for value in settings saved in map
69 while (itk !=keylist.end() )
76 qWarning ("SimpleSettings::readEntry() Couldn't find key "+key);
81 QString SimpleSettings::readEntry (const QString &key, const QString &def)
83 QStringList::Iterator itk=keylist.begin();
84 QStringList::Iterator itv=valuelist.begin();
86 // First search for value in settings saved in map
87 while (itk !=keylist.end() )
97 int SimpleSettings::readNumEntry (const QString &key, const int &def)
99 QStringList::Iterator itk=keylist.begin();
100 QStringList::Iterator itv=valuelist.begin();
102 // First search for value in settings saved in map
103 while (itk !=keylist.end() )
108 int i=(*itv).toInt(&ok,10);
120 void SimpleSettings::setEntry (const QString &key, const QString &value)
122 QStringList::Iterator itk=keylist.begin();
123 QStringList::Iterator itv=valuelist.begin();
127 // Search for existing entry first
128 while (itk !=keylist.end() )
132 if (!value.isEmpty())
143 // If no entry exists, append a new one
144 keylist.append (key);
145 valuelist.append (value);
151 /////////////////////////////////////////////////////////////////
153 /////////////////////////////////////////////////////////////////
159 Settings::Settings(const QString & organization, const QString & application ):QSettings (organization,application)
164 Settings::~Settings()
168 void Settings::clear()
175 void Settings::clearLocal(const QString &s)
177 QStringList::Iterator itp=pathlist.begin();
178 QStringList::Iterator itk=keylist.begin();
179 QStringList::Iterator itv=valuelist.begin();
181 while (itp !=pathlist.end() )
183 if ((*itk).startsWith (s))
185 itp=pathlist.remove (itp);
186 itk=keylist.remove (itk);
187 itv=valuelist.remove (itv);
197 QString Settings::readLocalEntry ( const QString &fpath, const QString & key, const QString & def = QString::null )
199 QStringList::Iterator itp=pathlist.begin();
200 QStringList::Iterator itk=keylist.begin();
201 QStringList::Iterator itv=valuelist.begin();
203 // First search for value in settings saved in map
204 while (itp !=pathlist.end() )
206 if (*itp == fpath && *itk == key)
213 // Fall back to global vym settings
215 return readEntry (key,def, &ok);
218 void Settings::setLocalEntry (const QString &fpath, const QString &key, const QString &value)
220 QStringList::Iterator itp=pathlist.begin();
221 QStringList::Iterator itk=keylist.begin();
222 QStringList::Iterator itv=valuelist.begin();
224 if (!fpath.isEmpty() && !key.isEmpty() && !value.isEmpty() )
226 // Search for existing entry first
227 while (itp !=pathlist.end() )
229 if (*itp == fpath && *itk == key)
239 // If no entry exists, append a new one
240 pathlist.append (fpath);
241 keylist.append (key);
242 valuelist.append (value);
246 QString Settings::getDataXML (const QString &fpath)
249 QStringList::Iterator itp=pathlist.begin();
250 QStringList::Iterator itk=keylist.begin();
251 QStringList::Iterator itv=valuelist.begin();
253 while (itp !=pathlist.end() )
256 if (!(*itv).isEmpty())
259 attribut ("key",*itk)
260 +attribut ("value",*itv)