| 251 | } |
| 252 | |
| 253 | void 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) { |
no test coverage detected