|
@@ -293,13 +293,13 @@ void MainWindow::populateMapList() {
|
293
|
293
|
mapIcon.addFile(QStringLiteral(":/icons/map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
294
|
294
|
mapIcon.addFile(QStringLiteral(":/icons/image.ico"), QSize(), QIcon::Normal, QIcon::On);
|
295
|
295
|
|
296
|
|
- QStandardItemModel *model = new QStandardItemModel;
|
|
296
|
+ mapListModel = new QStandardItemModel;
|
297
|
297
|
|
298
|
298
|
QStandardItem *entry = new QStandardItem;
|
299
|
299
|
entry->setText(project->getProjectTitle());
|
300
|
300
|
entry->setIcon(folderIcon);
|
301
|
301
|
entry->setEditable(false);
|
302
|
|
- model->appendRow(entry);
|
|
302
|
+ mapListModel->appendRow(entry);
|
303
|
303
|
|
304
|
304
|
QStandardItem *maps = new QStandardItem;
|
305
|
305
|
maps->setText("maps");
|
|
@@ -314,6 +314,8 @@ void MainWindow::populateMapList() {
|
314
|
314
|
group->setText(group_name);
|
315
|
315
|
group->setIcon(mapFolderIcon);
|
316
|
316
|
group->setEditable(false);
|
|
317
|
+ group->setData(group_name, Qt::UserRole);
|
|
318
|
+ group->setData("map_group", MapListUserRoles::TypeRole);
|
317
|
319
|
maps->appendRow(group);
|
318
|
320
|
QStringList *names = project->groupedMapNames->value(i);
|
319
|
321
|
for (int j = 0; j < names->length(); j++) {
|
|
@@ -323,17 +325,52 @@ void MainWindow::populateMapList() {
|
323
|
325
|
map->setIcon(mapIcon);
|
324
|
326
|
map->setEditable(false);
|
325
|
327
|
map->setData(map_name, Qt::UserRole);
|
|
328
|
+ map->setData("map_name", MapListUserRoles::TypeRole);
|
326
|
329
|
group->appendRow(map);
|
327
|
|
- //ui->mapList->setExpanded(model->indexFromItem(map), false); // redundant
|
328
|
330
|
}
|
329
|
331
|
}
|
330
|
332
|
|
331
|
|
- ui->mapList->setModel(model);
|
|
333
|
+ // Right-clicking on items in the map list tree view brings up a context menu.
|
|
334
|
+ ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
335
|
+ connect(ui->mapList, SIGNAL(customContextMenuRequested(const QPoint &)),
|
|
336
|
+ this, SLOT(onOpenMapListContextMenu(const QPoint &)));
|
|
337
|
+
|
|
338
|
+ ui->mapList->setModel(mapListModel);
|
332
|
339
|
ui->mapList->setUpdatesEnabled(true);
|
333
|
340
|
ui->mapList->expandToDepth(2);
|
334
|
341
|
ui->mapList->repaint();
|
335
|
342
|
}
|
336
|
343
|
|
|
344
|
+void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
|
345
|
+{
|
|
346
|
+ QModelIndex index = ui->mapList->indexAt(point);
|
|
347
|
+ if (!index.isValid()) {
|
|
348
|
+ return;
|
|
349
|
+ }
|
|
350
|
+
|
|
351
|
+ QStandardItem *selectedItem = mapListModel->itemFromIndex(index);
|
|
352
|
+ QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole);
|
|
353
|
+ if (!itemType.isValid()) {
|
|
354
|
+ return;
|
|
355
|
+ }
|
|
356
|
+
|
|
357
|
+ // Build custom context menu depending on which type of item was selected (map group, map name, etc.)
|
|
358
|
+ if (itemType == "map_group") {
|
|
359
|
+ QString groupName = selectedItem->data(Qt::UserRole).toString();
|
|
360
|
+ QMenu* menu = new QMenu();
|
|
361
|
+ 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*)));
|
|
364
|
+ menu->exec(QCursor::pos());
|
|
365
|
+ }
|
|
366
|
+}
|
|
367
|
+
|
|
368
|
+void MainWindow::addNewMapToGroup(QAction* triggeredAction)
|
|
369
|
+{
|
|
370
|
+ QString groupName = triggeredAction->data().toString();
|
|
371
|
+ qDebug() << "Adding new map " << groupName;
|
|
372
|
+}
|
|
373
|
+
|
337
|
374
|
void MainWindow::on_mapList_activated(const QModelIndex &index)
|
338
|
375
|
{
|
339
|
376
|
QVariant data = index.data(Qt::UserRole);
|