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

Method add

MiniZincIDE/project.cpp:253–331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

251}
252
253void Project::add(const QString& fileName)
254{
255 auto abs = QFileInfo(fileName).absoluteFilePath();
256 auto path = relativeToProject(fileName);
257 if (contains(abs)) {
258 return;
259 }
260
261#if QT_VERSION >= 0x060000
262 auto parts = path.split("/", Qt::SkipEmptyParts); // Qt always uses / as the path separator
263#else
264 auto parts = path.split("/", QString::SkipEmptyParts); // Qt always uses / as the path separator
265#endif
266 auto file = parts.takeLast();
267
268 QStandardItem* node = otherItem;
269 QString icon;
270 NodeType type = NodeType::Other;
271 if (file.endsWith(".mzc.mzn") || file.endsWith(".mzc")) {
272 node = checkersItem;
273 icon = ":/images/mznicon.png";
274 type = NodeType::Checker;
275 } else if (file.endsWith(".mzn")) {
276 node = modelsItem;
277 icon = ":/images/mznicon.png";
278 type = NodeType::Model;
279 } else if (file.endsWith(".dzn") || file.endsWith(".json")) {
280 node = dataItem;
281 icon = ":/images/mznicon.png";
282 type = NodeType::Data;
283 } else if (file.endsWith(".mpc")) {
284 node = configsItem;
285 icon = ":/images/mznicon.png";
286 type = NodeType::SolverConfig;
287 } else if (file == "_mooc" || file == "_coursera") {
288 if (mooc) {
289 delete mooc;
290 }
291 mooc = new MOOCAssignment(fileName);
292 emit moocChanged(mooc);
293 }
294
295 node->setFlags(Qt::ItemIsEnabled);
296
297 // Traverse existing path items
298 int i = 0;
299 while (!parts.empty() && i < node->rowCount()) {
300 if (getType(node->child(i)->index()) == NodeType::Dir &&
301 node->child(i)->text() == parts.first()) {
302 parts.pop_front();
303 node = node->child(i);
304 i = 0;
305 } else {
306 i++;
307 }
308 }
309 // Create new path items
310 for (auto& part : parts) {

Callers 5

setupContextMenuMethod · 0.80
createEditorMethod · 0.80
openFileMethod · 0.80
saveFileMethod · 0.80
onFunction · 0.80

Calls 1

firstMethod · 0.80

Tested by

no test coverage detected