@@ -146,24 +146,44 @@ void CQPreferenceDialog::initTabsFromSettings(QSettings& settings)
146146 auto tooltip = settings.value (" tooltip" ).toString ();
147147
148148 if (type == " string" )
149- {
150- auto edit = new QLineEdit (value.toString ());
151- edit->setToolTip (tooltip);
152-
153- if (pNode)
154- edit->setText (FROM_UTF8 (pNode->getValue <std::string>()));
155- layout->addRow (name, edit);
156- connect (edit, &QLineEdit::textChanged, this , &CQPreferenceDialog::slotPropertyChanged);
157- mWidgetToParameter [edit] = pNode;
158- }
149+ {
150+ // If the parameter has valid values, we should use a combo box instead of a line edit
151+ if (pNode && pNode->hasValidValues ())
152+ {
153+ auto edit = new QComboBox ();
154+ edit->setToolTip (tooltip);
155+
156+ for (const auto & validValue : pNode->getValidValues < std::string >())
157+ edit->addItem (FROM_UTF8 (validValue.second ));
158+
159+ if (pNode)
160+ edit->setCurrentText (FROM_UTF8 (pNode->getValue < std::string >()));
161+
162+ layout->addRow (name, edit);
163+ connect (edit, &QComboBox::currentTextChanged, this , &CQPreferenceDialog::slotPropertyChanged);
164+ mWidgetToParameter [edit] = pNode;
165+ }
166+ else
167+ {
168+ auto edit = new QLineEdit (value.toString ());
169+ edit->setToolTip (tooltip);
170+
171+ if (pNode)
172+ edit->setText (FROM_UTF8 (pNode->getValue < std::string >()));
173+
174+ layout->addRow (name, edit);
175+ connect (edit, &QLineEdit::textChanged, this , &CQPreferenceDialog::slotPropertyChanged);
176+ mWidgetToParameter [edit] = pNode;
177+ }
178+ }
159179 else if (type == " bool" )
160- {
161- auto edit = new QCheckBox (name);
162- edit->setChecked (value.toBool ());
163- if (pNode)
164- edit->setChecked (pNode->getValue < bool >());
165- edit->setToolTip (tooltip);
166- layout->addRow (edit);
180+ {
181+ auto edit = new QCheckBox (name);
182+ edit->setChecked (value.toBool ());
183+ if (pNode)
184+ edit->setChecked (pNode->getValue < bool >());
185+ edit->setToolTip (tooltip);
186+ layout->addRow (edit);
167187
168188#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
169189 connect (edit, &QCheckBox::stateChanged, this , &CQPreferenceDialog::slotPropertyChanged);
@@ -211,28 +231,9 @@ void CQPreferenceDialog::init()
211231 mpTreeView->setAdvanced (false );
212232 mpTreeView->pushGroup (mpConfiguration);
213233
214- // initialize other tabs from config file
215- auto copasiDir = COptions::getConfigDir ();
216- auto preferenceConfigFile = copasiDir + " /preferences.ini" ;
217- if (!CDirEntry::exist (preferenceConfigFile))
218- {
219- // load default preference.ini from resource
220- Q_INIT_RESOURCE (copasi);
221-
222- QFile file (" :/preferences.ini" );
223- if (file.open (QIODevice::ReadOnly))
224- {
225- QFile outFile (FROM_UTF8 (preferenceConfigFile));
226- if (outFile.open (QIODevice::WriteOnly))
227- {
228- outFile.write (file.readAll ());
229- outFile.close ();
230- }
231- file.close ();
232- }
233- }
234+ Q_INIT_RESOURCE (copasi);
235+ QSettings settings (" :/preferences.ini" , QSettings::IniFormat, this );
234236
235- QSettings settings (preferenceConfigFile.c_str (), QSettings::IniFormat, this );
236237 initTabsFromSettings (settings);
237238}
238239
0 commit comments