|
@@ -289,11 +289,12 @@ void MainWindow::populateMapList() {
|
289
|
289
|
QIcon folderIcon;
|
290
|
290
|
folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
291
|
291
|
|
292
|
|
- QIcon mapIcon;
|
293
|
|
- mapIcon.addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
294
|
|
- mapIcon.addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
|
|
292
|
+ mapIcon = new QIcon;
|
|
293
|
+ mapIcon->addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
|
294
|
+ mapIcon->addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
|
295
|
295
|
|
296
|
296
|
mapListModel = new QStandardItemModel;
|
|
297
|
+ mapGroupsModel = new QList<QStandardItem*>;
|
297
|
298
|
|
298
|
299
|
QStandardItem *entry = new QStandardItem;
|
299
|
300
|
entry->setText(project->getProjectTitle());
|
|
@@ -316,16 +317,13 @@ void MainWindow::populateMapList() {
|
316
|
317
|
group->setEditable(false);
|
317
|
318
|
group->setData(group_name, Qt::UserRole);
|
318
|
319
|
group->setData("map_group", MapListUserRoles::TypeRole);
|
|
320
|
+ group->setData(i, MapListUserRoles::GroupRole);
|
319
|
321
|
maps->appendRow(group);
|
|
322
|
+ mapGroupsModel->append(group);
|
320
|
323
|
QStringList *names = project->groupedMapNames->value(i);
|
321
|
324
|
for (int j = 0; j < names->length(); j++) {
|
322
|
325
|
QString map_name = names->value(j);
|
323
|
|
- QStandardItem *map = new QStandardItem;
|
324
|
|
- map->setText(QString("[%1.%2] ").arg(i).arg(j, 2, 10, QLatin1Char('0')) + map_name);
|
325
|
|
- map->setIcon(mapIcon);
|
326
|
|
- map->setEditable(false);
|
327
|
|
- map->setData(map_name, Qt::UserRole);
|
328
|
|
- map->setData("map_name", MapListUserRoles::TypeRole);
|
|
326
|
+ QStandardItem *map = createMapItem(map_name, i, j);
|
329
|
327
|
group->appendRow(map);
|
330
|
328
|
}
|
331
|
329
|
}
|
|
@@ -341,6 +339,16 @@ void MainWindow::populateMapList() {
|
341
|
339
|
ui->mapList->repaint();
|
342
|
340
|
}
|
343
|
341
|
|
|
342
|
+QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) {
|
|
343
|
+ QStandardItem *map = new QStandardItem;
|
|
344
|
+ map->setText(QString("[%1.%2] ").arg(groupNum).arg(inGroupNum, 2, 10, QLatin1Char('0')) + mapName);
|
|
345
|
+ map->setIcon(*mapIcon);
|
|
346
|
+ map->setEditable(false);
|
|
347
|
+ map->setData(mapName, Qt::UserRole);
|
|
348
|
+ map->setData("map_name", MapListUserRoles::TypeRole);
|
|
349
|
+ return map;
|
|
350
|
+}
|
|
351
|
+
|
344
|
352
|
void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
345
|
353
|
{
|
346
|
354
|
QModelIndex index = ui->mapList->indexAt(point);
|
|
@@ -357,18 +365,26 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
357
|
365
|
// Build custom context menu depending on which type of item was selected (map group, map name, etc.)
|
358
|
366
|
if (itemType == "map_group") {
|
359
|
367
|
QString groupName = selectedItem->data(Qt::UserRole).toString();
|
|
368
|
+ int groupNum = selectedItem->data(MapListUserRoles::GroupRole).toInt();
|
360
|
369
|
QMenu* menu = new QMenu();
|
361
|
370
|
QActionGroup* actions = new QActionGroup(menu);
|
362
|
|
- actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupName);
|
363
|
|
- connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(addNewMapToGroup(QAction*)));
|
|
371
|
+ actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupNum);
|
|
372
|
+ connect(actions, SIGNAL(triggered(QAction*)), this, SLOT(onAddNewMapToGroupClick(QAction*)));
|
364
|
373
|
menu->exec(QCursor::pos());
|
365
|
374
|
}
|
366
|
375
|
}
|
367
|
376
|
|
368
|
|
-void MainWindow::addNewMapToGroup(QAction* triggeredAction)
|
|
377
|
+void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
|
369
|
378
|
{
|
370
|
|
- QString groupName = triggeredAction->data().toString();
|
371
|
|
- qDebug() << "Adding new map " << groupName;
|
|
379
|
+ int groupNum = triggeredAction->data().toInt();
|
|
380
|
+ QStandardItem* groupItem = mapGroupsModel->at(groupNum);
|
|
381
|
+
|
|
382
|
+ QString newMapName = editor->project->getNewMapName();
|
|
383
|
+ editor->project->addNewMapToGroup(newMapName, groupNum);
|
|
384
|
+
|
|
385
|
+ int numMapsInGroup = groupItem->rowCount();
|
|
386
|
+ QStandardItem *newMapItem = createMapItem(newMapName, groupNum, numMapsInGroup);
|
|
387
|
+ groupItem->appendRow(newMapItem);
|
372
|
388
|
}
|
373
|
389
|
|
374
|
390
|
void MainWindow::on_mapList_activated(const QModelIndex &index)
|