| 72 | } |
| 73 | |
| 74 | QStringList Project::loadProject(const QString& file, ConfigWindow* configWindow) |
| 75 | { |
| 76 | clear(); |
| 77 | |
| 78 | projectFile(file); |
| 79 | |
| 80 | QStringList warnings; |
| 81 | |
| 82 | QFile f(file); |
| 83 | QFileInfo fi(f); |
| 84 | if (!f.open(QFile::ReadOnly)) { |
| 85 | throw FileError("Failed to open project file"); |
| 86 | } |
| 87 | |
| 88 | auto doc = QJsonDocument::fromJson(f.readAll()); |
| 89 | |
| 90 | if (doc.isObject()) { |
| 91 | loadJSON(doc.object(), fi, configWindow, warnings); |
| 92 | } else { |
| 93 | f.reset(); |
| 94 | QDataStream in(&f); |
| 95 | loadLegacy(in, fi, configWindow, warnings); |
| 96 | } |
| 97 | |
| 98 | f.close(); |
| 99 | |
| 100 | // Save these because adding the configs can change them |
| 101 | auto projectBuiltinConfigId = selectedBuiltinConfigId; |
| 102 | auto projectBuiltinConfigVersion = selectedBuiltinConfigVersion; |
| 103 | auto projectselectedSolverConfigFile = selectedSolverConfigFile; |
| 104 | |
| 105 | for (auto& sc : solverConfigurationFiles()) { |
| 106 | configWindow->addConfig(sc); |
| 107 | } |
| 108 | |
| 109 | if (!projectBuiltinConfigId.isEmpty()) { |
| 110 | int index = configWindow->findBuiltinConfig(projectBuiltinConfigId, projectBuiltinConfigVersion); |
| 111 | if (index == -1) { |
| 112 | warnings << "Could not find solver " + projectBuiltinConfigId + "@" + projectBuiltinConfigVersion; |
| 113 | } else { |
| 114 | configWindow->setCurrentIndex(index); |
| 115 | } |
| 116 | } else if (!projectselectedSolverConfigFile.isEmpty()) { |
| 117 | int index = configWindow->findConfigFile(rootDir().absolutePath() + "/" + projectselectedSolverConfigFile); |
| 118 | configWindow->setCurrentIndex(index); |
| 119 | } |
| 120 | |
| 121 | setModified(false); |
| 122 | |
| 123 | return warnings; |
| 124 | } |
| 125 | |
| 126 | void Project::loadJSON(const QJsonObject& obj, const QFileInfo& fi, ConfigWindow* configWindow, QStringList& warnings) |
| 127 | { |
nothing calls this directly
no test coverage detected