From e2ff93e5e70bb2f3367ec7858a3945969a5b0c14 Mon Sep 17 00:00:00 2001 From: garak Date: Mon, 6 Feb 2023 23:48:37 -0500 Subject: [PATCH] add areaList model and filtering, scrolling for all trees --- include/mainwindow.h | 11 +- include/ui/maplistmodels.h | 39 ++- resources/icons/application_form_edit.ico | Bin 1150 -> 1150 bytes resources/icons/connections.ico | Bin 0 -> 1150 bytes resources/images.qrc | 2 + src/mainwindow.cpp | 117 ++++++--- src/ui/maplistmodels.cpp | 280 +++++++++------------- 7 files changed, 241 insertions(+), 208 deletions(-) create mode 100644 resources/icons/connections.ico diff --git a/include/mainwindow.h b/include/mainwindow.h index d4390bbb..7bc47ff2 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -266,6 +266,8 @@ private slots: void on_actionTileset_Editor_triggered(); void on_lineEdit_filterBox_textChanged(const QString &arg1); + void on_lineEdit_filterBox_Areas_textChanged(const QString &arg1); + void on_lineEdit_filterBox_Layouts_textChanged(const QString &arg1); void moveEvent(QMoveEvent *event); void closeEvent(QCloseEvent *); @@ -318,6 +320,9 @@ private: FilterChildrenProxyModel *groupListProxyModel; MapGroupModel *mapGroupModel; + FilterChildrenProxyModel *areaListProxyModel; + MapAreaModel *mapAreaModel; + FilterChildrenProxyModel *layoutListProxyModel; LayoutTreeModel *layoutTreeModel; @@ -348,13 +353,13 @@ private: bool newMapDefaultsSet = false; MapSortOrder mapSortOrder; - enum MapListTab { Groups, Areas, Layouts }; + enum MapListTab { Groups = 0, Areas, Layouts }; bool tilesetNeedsRedraw = false; bool setLayout(QString layoutId); - bool setMap(QString, bool scrollTreeView = false); + bool setMap(QString, bool scroll = false); void unsetMap(); void redrawMapScene(); void refreshMapScene(); @@ -363,11 +368,11 @@ private: bool populateMapList(); void sortMapList(); void openSubWindow(QWidget * window); + void scrollTreeView(QString itemName); QString getExistingDirectory(QString); bool openProject(QString dir); QString getDefaultMap(); void setRecentMap(QString map_name); - QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum); void updateMapList(); diff --git a/include/ui/maplistmodels.h b/include/ui/maplistmodels.h index 166fe79d..d730c05e 100644 --- a/include/ui/maplistmodels.h +++ b/include/ui/maplistmodels.h @@ -15,7 +15,8 @@ enum MapListRoles { TypeRole2, // Used for various extra data needed. }; -// or QStandardItemModel?? + + class MapGroupModel : public QStandardItemModel { Q_OBJECT @@ -52,6 +53,42 @@ signals: +class MapAreaModel : public QStandardItemModel { + Q_OBJECT + +public: + MapAreaModel(Project *project, QObject *parent = nullptr); + ~MapAreaModel() {} + + QVariant data(const QModelIndex &index, int role) const override; + +public: + void setMap(QString mapName) { this->openMap = mapName; } + + QStandardItem *createAreaItem(QString areaName, int areaIndex); + QStandardItem *createMapItem(QString mapName, int areaIndex, int mapIndex); + + QStandardItem *getItem(const QModelIndex &index) const; + QModelIndex indexOfMap(QString mapName); + + void initialize(); + +private: + Project *project; + QStandardItem *root = nullptr; + + QMap areaItems; + QMap mapItems; + // TODO: if reordering, will the item be the same? + + QString openMap; + +signals: + void edited(); +}; + + + class LayoutTreeModel : public QStandardItemModel { Q_OBJECT diff --git a/resources/icons/application_form_edit.ico b/resources/icons/application_form_edit.ico index 7bb403eab9c641b0f756a6de02c6cb30a22a8b65..5d9cc7dafdf245cfecb63a9002530a2ae3990568 100644 GIT binary patch literal 1150 zcmb7@T}YEr7{`wgNTZKMr4+3!B%A3~(ir&J26 zGsN{xLZk^Hju4ch%u1fZ|CW0pUH%;;wYc!ecuUBt%+ceu@eWZXje>3d) zsc_{9oPHI@<7q%U2<)r`PTZRoPP@(vjEBp z;NTTn3>9bL7V_^Eyk_>#%!FYw8c}63;q#|3JRNPaj;q7!H#pY?WV`@0FF)X3t{QG# zD%wl7CHvepj5m$rU3nLp@(1K|WB<_LAj(Qh@zh{|cW4mq4p+jKj2=%rydy(s z)q2sYABW{(P~Ly`_xAK+ps$bUm!o8^LA7K?Rkb9;ZO-+P<{OP@(+D{A3i5Bk!Y?{^ zK6{2b7l_60#E;du+Fqc@{fl$~tOW`Tw; literal 1150 zcmb7D%W7gl5beNxKvuJ!MHbo52h8ux!bl*#B0eIh5JAmO5rZ*7#O-L7MqLRa5>XHz zQ4&K8_*l5nsPRmn9wo3DBxv|2*Wqx8ZJeE*38T>{j*pLVbaaI4>uWHM%jFWZZToUB<$(5G`2BvQQYkz< zJiuf!sTeyx2juH?x&rM6gW)ga^LY#g1GHK#WHK3?o}NPb!(y?(Y&L^DyWK9xrM$hp zDa_|{%w{tMx7&?MrGmS=JKWyhs`$!TE{s7w^R8Aaj7B4c@pz2kaEQrdqFg;55AN^p zRg82x4ZU8k^sHl>|MK#JXf%q;%S*hzz9N^)DL*df=jW(atH@@vs*aPB6WDAvIGxT- z{>R5hJUu<3-|s72U0op_kK^X%2FYX+KA#VrP6uAESH-bft*WP5{q1&J+1YOm^rxQR zy)`x$rBEnS#e$j&(0piVlf4+AGA?8cdh^L@9&%WYxiKW zSYWwag757;?d$a#@{V%`>i%@Q-AxYW(Q>hdZD{q-pZUq>y)2bVC>D#K2K~un{W8Wc f?s=a+3;L7C|7YbCV)aA*S$iKqsy6bGUFv=V+U%?a diff --git a/resources/icons/connections.ico b/resources/icons/connections.ico new file mode 100644 index 0000000000000000000000000000000000000000..effb20c982f6c95a93a7a32e20bac1c026a291bf GIT binary patch literal 1150 zcmbVLO-~b16n!NA09LL|+$iw_LZZQ#km?U`p>F&G5OyZe$^s~`(}in|E`)}tIPFYl zh7Lu64Z#>dT zU|KT+7qOD;l-d?8-Iq79@VHk|`%RI1`CxTuf9MUQzq!dlgcDtY4mi;>SQzWY-gn^Z zw*v)pa@0b-<}~FP@G4Szodg%*j>e-vVptseM2C9aQ(inRKNu l*?5}?hT7$h+NIBJ%2BKBx#s;jU`)K>Z*VYcahOhy-d`6swTA!z literal 0 HcmV?d00001 diff --git a/resources/images.qrc b/resources/images.qrc index e90d5849..676853bb 100644 --- a/resources/images.qrc +++ b/resources/images.qrc @@ -34,6 +34,8 @@ icons/sort_number.ico icons/tall_grass.ico icons/viewsprites.ico + icons/application_form_edit.ico + icons/connections.ico icons/ui/dark_checkbox_checked_disabled.png icons/ui/dark_checkbox_checked_disabled@2x.png icons/ui/dark_checkbox_checked.png diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3904ca0c..06387fa1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -205,8 +205,11 @@ void MainWindow::initCustomUI() { ui->mainTabBar->addTab("Map"); ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico"))); ui->mainTabBar->addTab("Events"); + ui->mainTabBar->setTabIcon(1, QIcon(QStringLiteral(":/icons/viewsprites.ico"))); ui->mainTabBar->addTab("Header"); + ui->mainTabBar->setTabIcon(2, QIcon(QStringLiteral(":/icons/application_form_edit.ico"))); ui->mainTabBar->addTab("Connections"); + ui->mainTabBar->setTabIcon(3, QIcon(QStringLiteral(":/icons/connections.ico"))); ui->mainTabBar->addTab("Wild Pokemon"); ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico"))); } @@ -340,6 +343,8 @@ void MainWindow::initMapSortOrder() { // QMenu *mapSortOrderMenu = new QMenu(this); // QActionGroup *mapSortOrderActionGroup = new QActionGroup(ui->toolButton_MapSortOrder); + // porymapConfig.setMapSortOrder(mapSortOrder); + // mapSortOrderMenu->addAction(ui->actionSort_by_Group); // mapSortOrderMenu->addAction(ui->actionSort_by_Area); // mapSortOrderMenu->addAction(ui->actionSort_by_Layout); @@ -410,14 +415,40 @@ void MainWindow::on_lineEdit_filterBox_textChanged(const QString &text) { this->applyMapListFilter(text); } +void MainWindow::on_lineEdit_filterBox_Areas_textChanged(const QString &text) { + this->applyMapListFilter(text); +} + +void MainWindow::on_lineEdit_filterBox_Layouts_textChanged(const QString &text) { + this->applyMapListFilter(text); +} + void MainWindow::applyMapListFilter(QString filterText) { - /// !TODO - groupListProxyModel->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption)); - if (filterText.isEmpty()) { - ui->mapList->collapseAll(); - } else { - ui->mapList->expandToDepth(0); + FilterChildrenProxyModel *proxy; + QTreeView *list; + switch (this->mapSortOrder) { + case MapSortOrder::SortByGroup: + proxy = this->groupListProxyModel; + list = this->ui->mapList; + break; + case MapSortOrder::SortByArea: + proxy = this->areaListProxyModel; + list = this->ui->areaList; + break; + case MapSortOrder::SortByLayout: + proxy = this->layoutListProxyModel; + list = this->ui->layoutList; + break; } + + proxy->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption)); + if (filterText.isEmpty()) { + list->collapseAll(); + } else { + list->expandToDepth(0); + } + + /// !TODO // ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true); // ui->mapList->scrollTo(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), QAbstractItemView::PositionAtCenter); } @@ -432,6 +463,9 @@ void MainWindow::loadUserSettings() { ui->checkBox_ToggleBorder->setChecked(porymapConfig.getShowBorder()); ui->checkBox_ToggleGrid->setChecked(porymapConfig.getShowGrid()); mapSortOrder = porymapConfig.getMapSortOrder(); + this->ui->mapListContainer->blockSignals(true); + this->ui->mapListContainer->setCurrentIndex(static_cast(this->mapSortOrder)); + this->ui->mapListContainer->blockSignals(false); ui->horizontalSlider_CollisionTransparency->blockSignals(true); this->editor->collisionOpacity = static_cast(porymapConfig.getCollisionOpacity()) / 100; ui->horizontalSlider_CollisionTransparency->setValue(porymapConfig.getCollisionOpacity()); @@ -643,7 +677,7 @@ void MainWindow::unsetMap() { this->ui->comboBox_LayoutSelector->setEnabled(false); } -bool MainWindow::setMap(QString map_name, bool scrollTreeView) { +bool MainWindow::setMap(QString map_name, bool scroll) { // if map name is empty, clear & disable map ui if (map_name.isEmpty()) { unsetMap(); @@ -670,12 +704,8 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) { refreshMapScene(); displayMapProperties(); - if (scrollTreeView) { - // Make sure we clear the filter first so we actually have a scroll target - /// !TODO: make this onto a function that scrolls the current view taking a map name or layout name - groupListProxyModel->setFilterRegularExpression(QString()); - ui->mapList->setCurrentIndex(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name))); - ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter); + if (scroll) { + scrollTreeView(map_name); } showWindowTitle(); @@ -1042,13 +1072,7 @@ bool MainWindow::loadProjectCombos() { return true; } -/// !TODO bool MainWindow::populateMapList() { - // bool success = editor->project->readMapGroups(); - // if (success) { - // sortMapList(); - // } - // return success; bool success = editor->project->readMapGroups(); this->mapGroupModel = new MapGroupModel(editor->project); @@ -1056,21 +1080,43 @@ bool MainWindow::populateMapList() { groupListProxyModel->setSourceModel(this->mapGroupModel); ui->mapList->setModel(groupListProxyModel); + this->mapAreaModel = new MapAreaModel(editor->project); + this->areaListProxyModel = new FilterChildrenProxyModel(); + areaListProxyModel->setSourceModel(this->mapAreaModel); + ui->areaList->setModel(areaListProxyModel); + this->layoutTreeModel = new LayoutTreeModel(editor->project); this->layoutListProxyModel = new FilterChildrenProxyModel(); this->layoutListProxyModel->setSourceModel(this->layoutTreeModel); ui->layoutList->setModel(layoutListProxyModel); - //connect(this->ui->layoutList, &QTreeView::doubleClicked, this, &MainWindow::on_layoutList_activated); - + /// !TODO // ui->mapList->setSelectionMode(QAbstractItemView::ExtendedSelection); // ui->mapList->setDragEnabled(true); // ui->mapList->setAcceptDrops(true); // ui->mapList->setDropIndicatorShown(true); return success; +} - //MapGroupModel +void MainWindow::scrollTreeView(QString itemName) { + switch (ui->mapListContainer->currentIndex()) { + case MapListTab::Groups: + groupListProxyModel->setFilterRegularExpression(QString()); + ui->mapList->setCurrentIndex(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(itemName))); + ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter); + break; + case MapListTab::Areas: + areaListProxyModel->setFilterRegularExpression(QString()); + ui->areaList->setCurrentIndex(areaListProxyModel->mapFromSource(mapAreaModel->indexOfMap(itemName))); + ui->areaList->scrollTo(ui->areaList->currentIndex(), QAbstractItemView::PositionAtCenter); + break; + case MapListTab::Layouts: + layoutListProxyModel->setFilterRegularExpression(QString()); + ui->layoutList->setCurrentIndex(layoutListProxyModel->mapFromSource(layoutTreeModel->indexOfLayout(itemName))); + ui->layoutList->scrollTo(ui->layoutList->currentIndex(), QAbstractItemView::PositionAtCenter); + break; + } } void MainWindow::sortMapList() { @@ -1181,19 +1227,7 @@ void MainWindow::sortMapList() { // updateMapList(); } -/// !TODO -QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) { - // QStandardItem *map = new QStandardItem; - // map->setText(QString("[%1.%2] ").arg(groupNum).arg(inGroupNum, 2, 10, QLatin1Char('0')) + mapName); - // map->setIcon(*mapIcon); - // map->setEditable(false); - // map->setData(mapName, Qt::UserRole); - // map->setData("map_name", MapListUserRoles::TypeRole); - // return map; -} - -void MainWindow::onOpenMapListContextMenu(const QPoint &point) -{ +void MainWindow::onOpenMapListContextMenu(const QPoint &point) { /// !TODO // QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point)); // if (!index.isValid()) { @@ -1462,14 +1496,19 @@ void MainWindow::on_mapListContainer_currentChanged(int index) { // switch (index) { case MapListTab::Groups: + this->mapSortOrder = MapSortOrder::SortByGroup; + if (this->editor && this->editor->map) scrollTreeView(this->editor->map->name); break; case MapListTab::Areas: + this->mapSortOrder = MapSortOrder::SortByArea; + if (this->editor && this->editor->map) scrollTreeView(this->editor->map->name); break; case MapListTab::Layouts: - //setMap(nullptr); - //setLayout(nullptr); + this->mapSortOrder = MapSortOrder::SortByLayout; + if (this->editor && this->editor->layout) scrollTreeView(this->editor->layout->id); break; } + porymapConfig.setMapSortOrder(this->mapSortOrder); } /// !TODO @@ -1489,7 +1528,7 @@ void MainWindow::on_mapList_activated(const QModelIndex &index) { } void MainWindow::on_areaList_activated(const QModelIndex &index) { - // + on_mapList_activated(index); } void MainWindow::on_layoutList_activated(const QModelIndex &index) { @@ -1520,6 +1559,8 @@ void MainWindow::updateMapList() { if (this->editor->map) { mapGroupModel->setMap(this->editor->map->name); groupListProxyModel->layoutChanged(); + mapAreaModel->setMap(this->editor->map->name); + areaListProxyModel->layoutChanged(); } if (this->editor->layout) { diff --git a/src/ui/maplistmodels.cpp b/src/ui/maplistmodels.cpp index e243541e..b904522c 100644 --- a/src/ui/maplistmodels.cpp +++ b/src/ui/maplistmodels.cpp @@ -4,89 +4,10 @@ -/* - - // QIcon mapFolderIcon; - // mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off); - // mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On); - - // QIcon folderIcon; - // folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off); - // //folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On); - - // ui->mapList->setUpdatesEnabled(false); - // mapListModel->clear(); - // mapGroupItemsList->clear(); - // QStandardItem *root = mapListModel->invisibleRootItem(); - - // switch (mapSortOrder) - // { - // case MapSortOrder::Group: - // for (int i = 0; i < project->groupNames.length(); i++) { - // QString group_name = project->groupNames.value(i); - // QStandardItem *group = new QStandardItem; - // group->setText(group_name); - // group->setIcon(mapFolderIcon); - // group->setEditable(false); - // group->setData(group_name, Qt::UserRole); - // group->setData("map_group", MapListUserRoles::TypeRole); - // group->setData(i, MapListUserRoles::GroupRole); - // root->appendRow(group); - // mapGroupItemsList->append(group); - // QStringList names = project->groupedMapNames.value(i); - // for (int j = 0; j < names.length(); j++) { - // QString map_name = names.value(j); - // QStandardItem *map = createMapItem(map_name, i, j); - // group->appendRow(map); - // mapListIndexes.insert(map_name, map->index()); - // } - // } - // break; - - // mapListModel = new QStandardItemModel; - // mapGroupItemsList = new QList; - // mapListProxyModel = new FilterChildrenProxyModel; - - // mapListProxyModel->setSourceModel(mapListModel); - // ui->mapList->setModel(mapListProxyModel); - - // createMapItem: - // QStandardItem *map = new QStandardItem; - // map->setText(QString("[%1.%2] ").arg(groupNum).arg(inGroupNum, 2, 10, QLatin1Char('0')) + mapName); - // map->setIcon(*mapIcon); - // map->setEditable(false); - // map->setData(mapName, Qt::UserRole); - // map->setData("map_name", MapListUserRoles::TypeRole); - // return map; - - // scrolling: - if (scrollTreeView) { - // Make sure we clear the filter first so we actually have a scroll target - /// !TODO - // mapListProxyModel->setFilterRegularExpression(QString()); - // ui->mapList->setCurrentIndex(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name))); - // ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter); - } - - // ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name)), true); - -*/ MapGroupModel::MapGroupModel(Project *project, QObject *parent) : QStandardItemModel(parent) { - // - this->project = project; this->root = this->invisibleRootItem(); - // mapIcon = new QIcon(QStringLiteral(":/icons/map.ico")); - // mapEditedIcon = new QIcon(QStringLiteral(":/icons/map_edited.ico")); - // mapOpenedIcon = new QIcon(QStringLiteral(":/icons/map_opened.ico")); - - // mapFolderIcon = new QIcon(QStringLiteral(":/icons/folder_closed_map.ico")); - - //mapFolderIcon = new QIcon; - //mapFolderIcon->addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off); - //mapFolderIcon->addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On); - initialize(); } @@ -118,9 +39,6 @@ void MapGroupModel::initialize() { QString group_name = this->project->groupNames.value(i); QStandardItem *group = createGroupItem(group_name, i); root->appendRow(group); - QList groupItems; - QMap inGroupItems; - //mapGroupItemsList->append(group); QStringList names = this->project->groupedMapNames.value(i); for (int j = 0; j < names.length(); j++) { QString map_name = names.value(j); @@ -146,35 +64,6 @@ QModelIndex MapGroupModel::indexOfMap(QString mapName) { return QModelIndex(); } - // projectHasUnsavedChanges = false; - // QList list; - // list.append(QModelIndex()); - // while (list.length()) { - // QModelIndex parent = list.takeFirst(); - // for (int i = 0; i < model->rowCount(parent); i++) { - // QModelIndex index = model->index(i, 0, parent); - // if (model->hasChildren(index)) { - // list.append(index); - // } - // QVariant data = index.data(Qt::UserRole); - // if (!data.isNull()) { - // QString map_name = data.toString(); - // if (editor->project && editor->project->mapCache.contains(map_name)) { - // QStandardItem *map = mapListModel->itemFromIndex(mapListIndexes.value(map_name)); - // map->setIcon(*mapIcon); - // if (editor->project->mapCache.value(map_name)->hasUnsavedChanges()) { - // map->setIcon(*mapEditedIcon); - // projectHasUnsavedChanges = true; - // } - // if (editor->map->name == map_name) { - // map->setIcon(*mapOpenedIcon); - // } - // } - // } - // } - // } - -#include QVariant MapGroupModel::data(const QModelIndex &index, int role) const { int row = index.row(); int col = index.column(); @@ -213,10 +102,6 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const { } return mapGrayIcon; } - - // check if map or group - // if map, check if edited or open - //return QIcon(":/icons/porymap-icon-2.ico"); } return QStandardItemModel::data(index, role); @@ -224,52 +109,124 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const { +MapAreaModel::MapAreaModel(Project *project, QObject *parent) : QStandardItemModel(parent) { + this->project = project; + this->root = this->invisibleRootItem(); + + initialize(); +} + +QStandardItem *MapAreaModel::createAreaItem(QString mapsecName, int areaIndex) { + QStandardItem *area = new QStandardItem; + area->setText(mapsecName); + area->setEditable(false); + area->setData(mapsecName, Qt::UserRole); + area->setData("map_section", MapListRoles::TypeRole); + area->setData(areaIndex, MapListRoles::GroupRole); + // group->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); + this->areaItems.insert(mapsecName, area); + return area; +} + +QStandardItem *MapAreaModel::createMapItem(QString mapName, int groupIndex, int mapIndex) { + QStandardItem *map = new QStandardItem; + map->setText(QString("[%1.%2] ").arg(groupIndex).arg(mapIndex, 2, 10, QLatin1Char('0')) + mapName); + map->setEditable(false); + map->setData(mapName, Qt::UserRole); + map->setData("map_name", MapListRoles::TypeRole); + // map->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); + this->mapItems.insert(mapName, map); + return map; +} + +void MapAreaModel::initialize() { + for (int i = 0; i < this->project->mapSectionNameToValue.size(); i++) { + QString mapsecName = project->mapSectionValueToName.value(i); + QStandardItem *areaItem = createAreaItem(mapsecName, i); + this->root->appendRow(areaItem); + } + + for (int i = 0; i < this->project->groupNames.length(); i++) { + QStringList names = this->project->groupedMapNames.value(i); + for (int j = 0; j < names.length(); j++) { + QString mapName = names.value(j); + QStandardItem *map = createMapItem(mapName, i, j); + QString mapsecName = this->project->readMapLocation(mapName); + if (this->areaItems.contains(mapsecName)) { + this->areaItems[mapsecName]->appendRow(map); + } + } + } +} + +QStandardItem *MapAreaModel::getItem(const QModelIndex &index) const { + if (index.isValid()) { + QStandardItem *item = static_cast(index.internalPointer()); + if (item) + return item; + } + return this->root; +} + +QModelIndex MapAreaModel::indexOfMap(QString mapName) { + if (this->mapItems.contains(mapName)) { + return this->mapItems[mapName]->index(); + } + return QModelIndex(); +} + +QVariant MapAreaModel::data(const QModelIndex &index, int role) const { + int row = index.row(); + int col = index.column(); + + if (role == Qt::DecorationRole) { + static QIcon mapGrayIcon = QIcon(QStringLiteral(":/icons/map_grayed.ico")); + static QIcon mapIcon = QIcon(QStringLiteral(":/icons/map.ico")); + static QIcon mapEditedIcon = QIcon(QStringLiteral(":/icons/map_edited.ico")); + static QIcon mapOpenedIcon = QIcon(QStringLiteral(":/icons/map_opened.ico")); + + static QIcon mapFolderIcon; + static QIcon folderIcon; + static bool loaded = false; + if (!loaded) { + mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off); + mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On); + folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off); + folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On); + loaded = true; + } + + QStandardItem *item = this->getItem(index)->child(row, col); + QString type = item->data(MapListRoles::TypeRole).toString(); + + if (type == "map_section") { + if (item->hasChildren()) { + return mapFolderIcon; + } + return folderIcon; + } else if (type == "map_name") { + QString mapName = item->data(Qt::UserRole).toString(); + if (mapName == this->openMap) { + return mapOpenedIcon; + } + else if (this->project->mapCache.contains(mapName)) { + if (this->project->mapCache.value(mapName)->hasUnsavedChanges()) { + return mapEditedIcon; + } + else { + return mapIcon; + } + } + return mapGrayIcon; + } + } + + return QStandardItemModel::data(index, role); +} - - - - - - - - - // case MapSortOrder::Layout: - // { - // QMap layoutIndices; - // for (int i = 0; i < project->mapLayoutsTable.length(); i++) { - // QString layoutId = project->mapLayoutsTable.value(i); - // MapLayout *layout = project->mapLayouts.value(layoutId); - // QStandardItem *layoutItem = new QStandardItem; - // layoutItem->setText(layout->name); - // layoutItem->setIcon(folderIcon); - // layoutItem->setEditable(false); - // layoutItem->setData(layout->name, Qt::UserRole); - // layoutItem->setData("map_layout", MapListUserRoles::TypeRole); - // layoutItem->setData(layout->id, MapListUserRoles::TypeRole2); - // layoutItem->setData(i, MapListUserRoles::GroupRole); - // root->appendRow(layoutItem); - // mapGroupItemsList->append(layoutItem); - // layoutIndices[layoutId] = i; - // } - // for (int i = 0; i < project->groupNames.length(); i++) { - // QStringList names = project->groupedMapNames.value(i); - // for (int j = 0; j < names.length(); j++) { - // QString map_name = names.value(j); - // QStandardItem *map = createMapItem(map_name, i, j); - // QString layoutId = project->readMapLayoutId(map_name); - // QStandardItem *layoutItem = mapGroupItemsList->at(layoutIndices.value(layoutId)); - // layoutItem->setIcon(mapFolderIcon); - // layoutItem->appendRow(map); - // mapListIndexes.insert(map_name, map->index()); - // } - // } - // break; - // } LayoutTreeModel::LayoutTreeModel(Project *project, QObject *parent) : QStandardItemModel(parent) { - // - this->project = project; this->root = this->invisibleRootItem(); @@ -279,7 +236,6 @@ LayoutTreeModel::LayoutTreeModel(Project *project, QObject *parent) : QStandardI QStandardItem *LayoutTreeModel::createLayoutItem(QString layoutId) { QStandardItem *layout = new QStandardItem; layout->setText(this->project->layoutIdsToNames[layoutId]); - //layout->setText(layoutId); layout->setEditable(false); layout->setData(layoutId, Qt::UserRole); layout->setData("map_layout", MapListRoles::TypeRole); @@ -301,7 +257,6 @@ QStandardItem *LayoutTreeModel::createMapItem(QString mapName) { void LayoutTreeModel::initialize() { for (int i = 0; i < this->project->mapLayoutsTable.length(); i++) { - // QString layoutId = project->mapLayoutsTable.value(i); QStandardItem *layoutItem = createLayoutItem(layoutId); this->root->appendRow(layoutItem); @@ -315,8 +270,6 @@ void LayoutTreeModel::initialize() { this->layoutItems[layoutId]->appendRow(map); } } - - // // project->readMapLayoutName } QStandardItem *LayoutTreeModel::getItem(const QModelIndex &index) const { @@ -364,12 +317,7 @@ QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const { } return QVariant(); - - // check if map or group - // if map, check if edited or open - //return QIcon(":/icons/porymap-icon-2.ico"); } return QStandardItemModel::data(index, role); } -