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

Method setDefaultSolver

MiniZincIDE/process.cpp:236–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236void MznDriver::setDefaultSolver(const Solver& s)
237{
238 for (auto* solver : solvers()) {
239 solver->isDefaultSolver = *solver == s;
240 }
241
242 QFile uc(userConfigFile());
243 QJsonObject jo;
244 if (uc.exists()) {
245 if (uc.open(QFile::ReadOnly)) {
246 QJsonDocument doc = QJsonDocument::fromJson(uc.readAll());
247 if (doc.isNull()) {
248 throw DriverError("Cannot modify user configuration file " + userConfigFile());
249 }
250 jo = doc.object();
251 uc.close();
252 }
253 }
254 QJsonArray tagdefs = jo.contains("tagDefaults") ? jo["tagDefaults"].toArray() : QJsonArray();
255 bool hadDefault = false;
256 for (int i=0; i<tagdefs.size(); i++) {
257 if (tagdefs[i].isArray() && tagdefs[i].toArray()[0].isString() && tagdefs[i].toArray()[0].toString().isEmpty()) {
258 QJsonArray def = tagdefs[i].toArray();
259 def[1] = s.id;
260 tagdefs[i] = def;
261 hadDefault = true;
262 break;
263 }
264 }
265 if (!hadDefault) {
266 QJsonArray def;
267 def.append("");
268 def.append(s.id);
269 tagdefs.append(def);
270 }
271 jo["tagDefaults"] = tagdefs;
272 QJsonDocument doc;
273 doc.setObject(jo);
274 QFileInfo uc_info(userConfigFile());
275 if (!QDir().mkpath(uc_info.absoluteDir().absolutePath())) {
276 throw DriverError("Cannot create user configuration directory " + uc_info.absoluteDir().absolutePath());
277 }
278 if (uc.open(QFile::ReadWrite | QIODevice::Truncate)) {
279 uc.write(doc.toJson());
280 uc.close();
281 } else {
282 throw DriverError("Cannot write user configuration file " + userConfigFile());
283 }
284}
285
286void MznProcess::start(const QStringList& args, const QString& cwd)
287{

Calls 5

DriverErrorClass · 0.85
containsMethod · 0.80
toJsonMethod · 0.80
sizeMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected