1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : QAD_Settings.cxx
25 // Author : Nicolas REJNERI
29 #include "QAD_Settings.h"
37 #include <qtextstream.h>
41 Class QAD_Settings is a base class for different kind of settings
42 (identifying strings and values).
44 QAD_Settings::QAD_Settings(QString _sectionName,
45 QChar _nameStarter, QChar _nameStopper,
46 QChar _valueStarter, QChar _valueStopper)
48 sectionName = _sectionName;
49 nameStarter = _nameStarter;
50 nameStopper = _nameStopper;
51 valueStarter = _valueStarter;
52 valueStopper = _valueStopper;
53 settingList.setAutoDelete(true);
59 QAD_Settings::QAD_Settings(QString _sectionName,
64 sectionName = _sectionName;
65 nameStarter = _nameStarter;
66 nameStopper = _separator;
67 valueStopper = _valueStopper;
69 settingList.setAutoDelete(true);
74 QAD_Settings::QAD_Settings(QChar _nameStopper, QChar _valueStarter,
79 nameStopper = _nameStopper;
80 valueStarter = _valueStarter;
81 valueStopper = _valueStopper;
82 settingList.setAutoDelete(true);
89 QAD_Settings::~QAD_Settings()
97 void QAD_Settings::clear()
104 Adds a setting. If a setting with the given name is already defined it
107 void QAD_Settings::addSetting(QString _name, QString _value, bool _autoValue)
109 // Remove all settings with the same name:
110 removeSettings(_name.simplifyWhiteSpace());
113 QAD_Setting* newSetting = new QAD_Setting(_name.simplifyWhiteSpace(),
114 _value.simplifyWhiteSpace(),
116 settingList.append(newSetting);
121 Adds an int setting. If a setting with the given name is already defined it
124 void QAD_Settings::addSetting(QString _name, int _value, bool _autoValue)
127 strVal.setNum(_value);
129 addSetting(_name, strVal, _autoValue);
133 Adds a double setting. If a setting with the given name is already defined it
136 void QAD_Settings::addSetting(QString _name, double _value, bool _autoValue)
139 strVal.setNum(_value);
141 addSetting(_name, strVal, _autoValue);
146 Removes all setting with the given name (should be unique anyway).
148 bool QAD_Settings::removeSettings(QString name)
153 for(s=settingList.first(); s!=0;) {
154 if(s->getName()==name) {
155 settingList.remove(s);
156 s=settingList.current();
160 s=settingList.next();
169 Removes all setting which are not automatically generated.
171 void QAD_Settings::removeNonAutoSettings()
175 for(s=settingList.first(); s!=0;) {
176 if(!s->isAutoValue()) {
177 settingList.remove(s);
178 s=settingList.current();
181 s=settingList.next();
188 Gets the setting value of the given setting.
190 QString QAD_Settings::getSetting(QString name)
194 for(s=settingList.first(); s!=0; s=settingList.next()) {
195 if(s->getName()==name) return s->getValue();
202 Replaces variables in the given string by their values.
204 QString QAD_Settings::replace(QString str)
206 if(!str.contains('$')) return str;
209 QString result=str.copy();
213 // Replace until we have no occurences of variables or recursive counter>16:
216 for(t=settingList.first(); t!=0; t=settingList.next()) {
217 if(result.contains('$')) {
220 i = result.find(QRegExp("\\$" + t->getName() + "[^a-zA-z0-9_]"), i);
222 result.replace(i, (int)t->getName().length()+1, t->getValue());
237 Returns true if list contains given setting
239 bool QAD_Settings::hasSetting(QString name)
243 for(s=settingList.first(); s!=0; s=settingList.next()) {
244 if(s->getName()==name) return true;