diff --git a/include/ui/maplistmodels.h b/include/ui/maplistmodels.h index 1962ad40..920bf9ba 100644 --- a/include/ui/maplistmodels.h +++ b/include/ui/maplistmodels.h @@ -148,6 +148,7 @@ public: ~LayoutTreeModel() {} QVariant data(const QModelIndex &index, int role) const override; + QStandardItem *createMapFolderItem(const QString &folderName, QStandardItem *folder) override; protected: void removeItem(QStandardItem *item) override; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3c16b0f4..71484f2f 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1279,13 +1279,13 @@ void MainWindow::onOpenMapListContextMenu(const QPoint &point) { }); } if (copyDisplayNameAction) { - connect(copyDisplayNameAction, &QAction::triggered, [this, sourceModel, index] { - setClipboardData(sourceModel->data(index, Qt::DisplayRole).toString()); + connect(copyDisplayNameAction, &QAction::triggered, [this, selectedItem] { + setClipboardData(selectedItem->text()); }); } if (copyToolTipAction) { - connect(copyToolTipAction, &QAction::triggered, [this, sourceModel, index] { - setClipboardData(sourceModel->data(index, Qt::ToolTipRole).toString()); + connect(copyToolTipAction, &QAction::triggered, [this, selectedItem] { + setClipboardData(selectedItem->toolTip()); }); } diff --git a/src/ui/maplistmodels.cpp b/src/ui/maplistmodels.cpp index 1890684b..d6b20af9 100644 --- a/src/ui/maplistmodels.cpp +++ b/src/ui/maplistmodels.cpp @@ -98,6 +98,7 @@ QStandardItem *MapListModel::createMapItem(const QString &mapName, QStandardItem map->setData("map_name", MapListUserRoles::TypeRole); map->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemNeverHasChildren); map->setEditable(this->editable); // Will override flags if necessary + map->setToolTip(this->project->mapNamesToMapConstants.value(mapName)); this->mapItems.insert(mapName, map); return map; } @@ -147,9 +148,9 @@ QVariant MapListModel::data(const QModelIndex &index, int role) const { const QString type = item->data(MapListUserRoles::TypeRole).toString(); const QString name = item->data(MapListUserRoles::NameRole).toString(); - if (type == "map_name") { - // Data for maps in the map list - if (role == Qt::DecorationRole) { + if (role == Qt::DecorationRole) { + if (type == "map_name") { + // Decorating map in the map list if (name == this->activeItemName) return this->mapOpenedIcon; @@ -157,12 +158,8 @@ QVariant MapListModel::data(const QModelIndex &index, int role) const { if (!map) return this->mapGrayIcon; return map->hasUnsavedChanges() ? this->mapEditedIcon : this->mapIcon; - } else if (role == Qt::ToolTipRole) { - return this->project->mapNamesToMapConstants.value(name); - } - } else if (type == this->folderTypeName) { - // Data for map folders in the map list - if (role == Qt::DecorationRole) { + } else if (type == this->folderTypeName) { + // Decorating map folder in the map list return item->hasChildren() ? this->mapFolderIcon : this->emptyMapFolderIcon; } } @@ -451,6 +448,19 @@ void LayoutTreeModel::removeItem(QStandardItem *) { // TODO: Deleting layouts not supported } +QStandardItem *LayoutTreeModel::createMapFolderItem(const QString &folderName, QStandardItem *folder) { + folder = MapListModel::createMapFolderItem(folderName, folder); + + // Despite using layout IDs internally, the Layouts map list shows layouts using their file path name. + // We could handle this with Qt::DisplayRole in LayoutTreeModel::data, but then it would be sorted using the ID instead of the name. + const Layout* layout = this->project->mapLayouts.value(folderName); + if (layout) { + folder->setText(layout->name); + folder->setToolTip(layout->id); + } + return folder; +} + QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) return QVariant(); @@ -463,23 +473,16 @@ QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const { const QString name = item->data(MapListUserRoles::NameRole).toString(); if (type == this->folderTypeName) { - const Layout* layout = this->project->mapLayouts.value(name); - if (role == Qt::DecorationRole) { // Map layouts are used as folders, but we display them with the same icons as maps. if (name == this->activeItemName) return this->mapOpenedIcon; + const Layout* layout = this->project->mapLayouts.value(name); if (!layout || !layout->loaded) return this->mapGrayIcon; return layout->hasUnsavedChanges() ? this->mapEditedIcon : this->mapIcon; } - else if (role == Qt::DisplayRole) { - // Despite using layout IDs internally, the Layouts map list shows layouts using their file path name. - if (layout) return layout->name; - } else if (role == Qt::ToolTipRole) { - if (layout) return layout->id; - } } return MapListModel::data(index, role); }