MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / loadDriver

Method loadDriver

MiniZincIDE/preferencesdialog.cpp:210–286  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

208}
209
210void PreferencesDialog::loadDriver(bool showError)
211{
212 auto& driver = MznDriver::get();
213 auto& solvers = driver.solvers();
214
215 _solversPopulated = false;
216 auto dest = ui->solvers_combo->currentIndex();
217 bool destExists = dest < solvers.size();
218 bool addNew = dest == ui->solvers_combo->count() - 1;
219 QString matchId;
220 QString matchVersion;
221 if (dest == _editingSolverIndex) {
222 // Was editing, so use widget values
223 matchId = ui->solverId->text();
224 matchVersion = ui->version->text();
225 destExists = true;
226 } else if (destExists) {
227 // Switching to different solver
228 matchId = solvers[dest]->id;
229 matchVersion = solvers[dest]->version;
230 }
231 try {
232 driver.setLocation(ui->mznDistribPath->text());
233 ui->mzn2fzn_version->setText(driver.minizincVersionString());
234 } catch (Exception& e) {
235 if (showError) {
236 showMessageBox(e.message());
237 }
238 ui->mzn2fzn_version->setText(e.message());
239 }
240
241 // Load user solver search paths
242 ui->extraSearchPath_listWidget->clear();
243 ui->configuration_groupBox->setEnabled(driver.isValid());
244 _userDefaultFlags.clear();
245 auto& userConfigFile = driver.userConfigFile();
246 QFile uc(userConfigFile);
247 if (uc.exists() && uc.open(QFile::ReadOnly)) {
248 QJsonDocument doc = QJsonDocument::fromJson(uc.readAll());
249 auto obj = doc.object();
250 if (obj.contains("mzn_solver_path")) {
251 for (auto it : obj["mzn_solver_path"].toArray()) {
252 auto path = it.toString();
253 if (!path.isEmpty()) {
254 ui->extraSearchPath_listWidget->addItem(path);
255 }
256 }
257 }
258 if (obj.contains("solverDefaults")) {
259 for (auto it : obj["solverDefaults"].toArray()) {
260 auto arr = it.toArray();
261 auto solverId = arr[0].toString();
262 auto flag = arr[1].toString();
263 _userDefaultFlags.insert(solverId, flag);
264 }
265 }
266 }
267

Callers

nothing calls this directly

Calls 9

currentIndexMethod · 0.80
countMethod · 0.80
setLocationMethod · 0.80
isValidMethod · 0.80
containsMethod · 0.80
setCurrentIndexMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected