add different tabs for map list views

This commit is contained in:
garak 2023-01-30 18:47:37 -05:00
parent 61256d39ca
commit 917e61b98a
6 changed files with 1008 additions and 455 deletions

View file

@ -32,7 +32,7 @@
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="mapListContainer" native="true">
<widget class="QTabWidget" name="mapListContainer">
<property name="enabled">
<bool>true</bool>
</property>
@ -42,168 +42,414 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_MapSortOrder">
<property name="enabled">
<bool>true</bool>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Sort map list&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/sort_alphabet.ico</normaloff>:/icons/sort_alphabet.ico</iconset>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="toolButtonStyle">
<enum>Qt::ToolButtonIconOnly</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="arrowType">
<enum>Qt::NoArrow</enum>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expand all map folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/expand_all.ico</normaloff>:/icons/expand_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_CollapseAll">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Collapse all map list folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/collapse_all.ico</normaloff>:/icons/collapse_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_filterBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter maps...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="mapList">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="mapListContainerPage1">
<attribute name="title">
<string>Groups</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Groups">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expand all map folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/expand_all.ico</normaloff>:/icons/expand_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_CollapseAll_Groups">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Collapse all map list folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/collapse_all.ico</normaloff>:/icons/collapse_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_filterBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="mapList">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mapListContainerPage2" native="true">
<attribute name="title">
<string>Areas</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_Areas">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1111">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Areas">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expand all map folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/expand_all.ico</normaloff>:/icons/expand_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_CollapseAll_Areas">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Collapse all map list folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/collapse_all.ico</normaloff>:/icons/collapse_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_filterBox_Areas">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="areaList">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="mapListContainerPage3">
<attribute name="title">
<string>Layouts</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_Layouts">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_111">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Layouts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Expand all layout folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/expand_all.ico</normaloff>:/icons/expand_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_CollapseAll_Layouts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Collapse all layout folders&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../resources/images.qrc">
<normaloff>:/icons/collapse_all.ico</normaloff>:/icons/collapse_all.ico</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>12</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_filterBox_Layouts">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string/>
</property>
<property name="placeholderText">
<string>Filter...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTreeView" name="layoutList">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectItems</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QFrame" name="frame_Main">
<property name="sizePolicy">
@ -260,7 +506,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<property name="movable" stdset="0">
<bool>false</bool>
@ -813,7 +1059,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<width>256</width>
<height>74</height>
</rect>
</property>
@ -1001,10 +1247,10 @@
</property>
<property name="geometry">
<rect>
<x>8</x>
<x>0</x>
<y>0</y>
<width>411</width>
<height>413</height>
<width>91</width>
<height>74</height>
</rect>
</property>
<property name="sizePolicy">
@ -1154,8 +1400,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>428</width>
<height>696</height>
<width>92</width>
<height>550</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -1314,8 +1560,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>398</width>
<height>631</height>
<width>91</width>
<height>460</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
@ -1615,8 +1861,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1709,8 +1955,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1803,8 +2049,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1903,8 +2149,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -1997,8 +2243,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>581</height>
<width>100</width>
<height>16</height>
</rect>
</property>
<property name="sizePolicy">
@ -2051,8 +2297,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>625</height>
<width>100</width>
<height>30</height>
</rect>
</property>
<property name="sizePolicy">

View file

@ -21,6 +21,7 @@
#include "regionmapeditor.h"
#include "mapimageexporter.h"
#include "filterchildrenproxymodel.h"
#include "maplistmodels.h"
#include "newmappopup.h"
#include "newtilesetdialog.h"
#include "shortcutseditor.h"
@ -257,8 +258,6 @@ private slots:
void on_actionTileset_Editor_triggered();
void mapSortOrder_changed(QAction *action);
void on_lineEdit_filterBox_textChanged(const QString &arg1);
void moveEvent(QMoveEvent *event);
@ -267,8 +266,14 @@ private slots:
void eventTabChanged(int index);
void on_horizontalSlider_CollisionTransparency_valueChanged(int value);
void on_toolButton_ExpandAll_clicked();
void on_toolButton_CollapseAll_clicked();
void on_toolButton_ExpandAll_Groups_clicked();
void on_toolButton_CollapseAll_Groups_clicked();
void on_toolButton_ExpandAll_Areas_clicked();
void on_toolButton_CollapseAll_Areas_clicked();
void on_toolButton_ExpandAll_Layouts_clicked();
void on_toolButton_CollapseAll_Layouts_clicked();
void on_actionAbout_Porymap_triggered();
void on_actionOpen_Log_File_triggered();
void on_actionOpen_Config_Folder_triggered();
@ -302,13 +307,15 @@ private:
QPointer<PreferenceEditor> preferenceEditor = nullptr;
QPointer<ProjectSettingsEditor> projectSettingsEditor = nullptr;
QPointer<CustomScriptsEditor> customScriptsEditor = nullptr;
FilterChildrenProxyModel *mapListProxyModel;
QStandardItemModel *mapListModel;
QList<QStandardItem*> *mapGroupItemsList;
QMap<QString, QModelIndex> mapListIndexes;
QIcon* mapIcon;
QIcon* mapEditedIcon;
QIcon* mapOpenedIcon;
FilterChildrenProxyModel *groupListProxyModel;
MapGroupModel *mapGroupModel;
// QStandardItemModel *mapListModel;
// QList<QStandardItem*> *mapGroupItemsList;
// QMap<QString, QModelIndex> mapListIndexes;
// QIcon* mapIcon;
// QIcon* mapEditedIcon;
// QIcon* mapOpenedIcon;
QAction *undoAction = nullptr;
QAction *redoAction = nullptr;
@ -397,10 +404,4 @@ private:
int insertTilesetLabel(QStringList * list, QString label);
};
enum MapListUserRoles {
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
TypeRole, // Used to differentiate between the different layers of the map list tree view.
TypeRole2, // Used for various extra data needed.
};
#endif // MAINWINDOW_H

View file

@ -0,0 +1,58 @@
#pragma once
#ifndef MAPLISTMODELS_H
#define MAPLISTMODELS_H
#include <QStandardItemModel>
#include <QMap>
class Project;
enum MapListRoles {
GroupRole = Qt::UserRole + 1, // Used to hold the map group number.
TypeRole, // Used to differentiate between the different layers of the map list tree view.
TypeRole2, // Used for various extra data needed.
};
// or QStandardItemModel??
class MapGroupModel : public QStandardItemModel {
Q_OBJECT
public:
MapGroupModel(Project *project, QObject *parent = nullptr);
~MapGroupModel() {}
QVariant data(const QModelIndex &index, int role) const override;
public:
void setMap(QString mapName) { this->openMap = mapName; }
QStandardItem *createGroupItem(QString groupName, int groupIndex);
QStandardItem *createMapItem(QString mapName, int groupIndex, int mapIndex);
QStandardItem *getItem(const QModelIndex &index) const;
QModelIndex indexOfMap(QString mapName);
void initialize();
private:
Project *project;
QStandardItem *root = nullptr;
QMap<QString, QStandardItem *> groupItems;
QMap<QString, QStandardItem *> mapItems;
// TODO: if reordering, will the item be the same?
QString openMap;
// QIcon *mapIcon = nullptr;
// QIcon *mapEditedIcon = nullptr;
// QIcon *mapOpenedIcon = nullptr;
// QIcon *mapFolderIcon = nullptr;
signals:
void edited();
};
#endif // MAPLISTMODELS_H

View file

@ -58,6 +58,7 @@ SOURCES += src/core/block.cpp \
src/ui/customattributestable.cpp \
src/ui/eventframes.cpp \
src/ui/filterchildrenproxymodel.cpp \
src/ui/maplistmodels.cpp \
src/ui/graphicsview.cpp \
src/ui/imageproviders.cpp \
src/ui/mappixmapitem.cpp \
@ -147,6 +148,7 @@ HEADERS += include/core/block.h \
include/ui/customattributestable.h \
include/ui/eventframes.h \
include/ui/filterchildrenproxymodel.h \
include/ui/maplistmodels.h \
include/ui/graphicsview.h \
include/ui/imageproviders.h \
include/ui/mappixmapitem.h \

View file

@ -19,6 +19,7 @@
#include "prefab.h"
#include "montabwidget.h"
#include "imageexport.h"
#include "maplistmodels.h"
#include <QFileDialog>
#include <QClipboard>
@ -151,13 +152,14 @@ void MainWindow::initExtraShortcuts() {
shortcutToggle_Smart_Paths->setObjectName("shortcutToggle_Smart_Paths");
shortcutToggle_Smart_Paths->setWhatsThis("Toggle Smart Paths");
auto *shortcutExpand_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_ExpandAll_clicked()));
shortcutExpand_All->setObjectName("shortcutExpand_All");
shortcutExpand_All->setWhatsThis("Map List: Expand all folders");
/// !TODO
// auto *shortcutExpand_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_ExpandAll_clicked()));
// shortcutExpand_All->setObjectName("shortcutExpand_All");
// shortcutExpand_All->setWhatsThis("Map List: Expand all folders");
auto *shortcutCollapse_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_CollapseAll_clicked()));
shortcutCollapse_All->setObjectName("shortcutCollapse_All");
shortcutCollapse_All->setWhatsThis("Map List: Collapse all folders");
// auto *shortcutCollapse_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_CollapseAll_clicked()));
// shortcutCollapse_All->setObjectName("shortcutCollapse_All");
// shortcutCollapse_All->setWhatsThis("Map List: Collapse all folders");
auto *shortcut_Open_Scripts = new Shortcut(QKeySequence(), ui->toolButton_Open_Scripts, SLOT(click()));
shortcut_Open_Scripts->setObjectName("shortcut_Open_Scripts");
@ -210,6 +212,7 @@ void MainWindow::initCustomUI() {
}
void MainWindow::initExtraSignals() {
/// !TODO
// Right-clicking on items in the map list tree view brings up a context menu.
ui->mapList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->mapList, &QTreeView::customContextMenuRequested,
@ -311,16 +314,17 @@ void MainWindow::initEditor() {
}
void MainWindow::initMiscHeapObjects() {
mapIcon = new QIcon(QStringLiteral(":/icons/map.ico"));
mapEditedIcon = new QIcon(QStringLiteral(":/icons/map_edited.ico"));
mapOpenedIcon = new QIcon(QStringLiteral(":/icons/map_opened.ico"));
// mapIcon = new QIcon(QStringLiteral(":/icons/map.ico"));
// mapEditedIcon = new QIcon(QStringLiteral(":/icons/map_edited.ico"));
// mapOpenedIcon = new QIcon(QStringLiteral(":/icons/map_opened.ico"));
mapListModel = new QStandardItemModel;
mapGroupItemsList = new QList<QStandardItem*>;
mapListProxyModel = new FilterChildrenProxyModel;
/// !TODO
// mapListModel = new QStandardItemModel;
// mapGroupItemsList = new QList<QStandardItem*>;
// mapListProxyModel = new FilterChildrenProxyModel;
mapListProxyModel->setSourceModel(mapListModel);
ui->mapList->setModel(mapListProxyModel);
// mapListProxyModel->setSourceModel(mapListModel);
// ui->mapList->setModel(mapListProxyModel);
eventTabObjectWidget = ui->tab_Objects;
eventTabWarpWidget = ui->tab_Warps;
@ -332,23 +336,23 @@ void MainWindow::initMiscHeapObjects() {
}
void MainWindow::initMapSortOrder() {
QMenu *mapSortOrderMenu = new QMenu(this);
QActionGroup *mapSortOrderActionGroup = new QActionGroup(ui->toolButton_MapSortOrder);
// QMenu *mapSortOrderMenu = new QMenu(this);
// QActionGroup *mapSortOrderActionGroup = new QActionGroup(ui->toolButton_MapSortOrder);
mapSortOrderMenu->addAction(ui->actionSort_by_Group);
mapSortOrderMenu->addAction(ui->actionSort_by_Area);
mapSortOrderMenu->addAction(ui->actionSort_by_Layout);
ui->toolButton_MapSortOrder->setMenu(mapSortOrderMenu);
// mapSortOrderMenu->addAction(ui->actionSort_by_Group);
// mapSortOrderMenu->addAction(ui->actionSort_by_Area);
// mapSortOrderMenu->addAction(ui->actionSort_by_Layout);
// ui->toolButton_MapSortOrder->setMenu(mapSortOrderMenu);
mapSortOrderActionGroup->addAction(ui->actionSort_by_Group);
mapSortOrderActionGroup->addAction(ui->actionSort_by_Area);
mapSortOrderActionGroup->addAction(ui->actionSort_by_Layout);
// mapSortOrderActionGroup->addAction(ui->actionSort_by_Group);
// mapSortOrderActionGroup->addAction(ui->actionSort_by_Area);
// mapSortOrderActionGroup->addAction(ui->actionSort_by_Layout);
connect(mapSortOrderActionGroup, &QActionGroup::triggered, this, &MainWindow::mapSortOrder_changed);
// connect(mapSortOrderActionGroup, &QActionGroup::triggered, this, &MainWindow::mapSortOrder_changed);
QAction* sortOrder = ui->toolButton_MapSortOrder->menu()->actions()[mapSortOrder];
ui->toolButton_MapSortOrder->setIcon(sortOrder->icon());
sortOrder->setChecked(true);
// QAction* sortOrder = ui->toolButton_MapSortOrder->menu()->actions()[mapSortOrder];
// ui->toolButton_MapSortOrder->setIcon(sortOrder->icon());
// sortOrder->setChecked(true);
}
void MainWindow::showWindowTitle() {
@ -393,46 +397,20 @@ void MainWindow::setProjectSpecificUIVisibility()
ui->label_FloorNumber->setVisible(floorNumEnabled);
}
void MainWindow::mapSortOrder_changed(QAction *action)
{
QList<QAction*> items = ui->toolButton_MapSortOrder->menu()->actions();
int i = 0;
for (; i < items.count(); i++)
{
if (items[i] == action)
{
break;
}
}
if (i != mapSortOrder)
{
ui->toolButton_MapSortOrder->setIcon(action->icon());
mapSortOrder = static_cast<MapSortOrder>(i);
porymapConfig.setMapSortOrder(mapSortOrder);
if (isProjectOpen())
{
sortMapList();
applyMapListFilter(ui->lineEdit_filterBox->text());
}
}
void MainWindow::on_lineEdit_filterBox_textChanged(const QString &text) {
this->applyMapListFilter(text);
}
void MainWindow::on_lineEdit_filterBox_textChanged(const QString &arg1)
{
this->applyMapListFilter(arg1);
}
void MainWindow::applyMapListFilter(QString filterText)
{
mapListProxyModel->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption));
void MainWindow::applyMapListFilter(QString filterText) {
/// !TODO
groupListProxyModel->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption));
if (filterText.isEmpty()) {
ui->mapList->collapseAll();
} else {
ui->mapList->expandToDepth(0);
}
ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true);
ui->mapList->scrollTo(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), QAbstractItemView::PositionAtCenter);
// ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true);
// ui->mapList->scrollTo(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), QAbstractItemView::PositionAtCenter);
}
void MainWindow::loadUserSettings() {
@ -650,8 +628,9 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
return false;
}
if (editor->map != nullptr && !editor->map->name.isNull()) {
ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), false);
if (editor->map && !editor->map->name.isNull()) {
// !TODO: function to act on current view? or that does all the views
ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false);
}
refreshMapScene();
@ -659,13 +638,12 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
if (scrollTreeView) {
// Make sure we clear the filter first so we actually have a scroll target
mapListProxyModel->setFilterRegularExpression(QString());
ui->mapList->setCurrentIndex(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name)));
/// !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);
}
ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(map_name)), true);
showWindowTitle();
connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged);
@ -973,169 +951,187 @@ bool MainWindow::loadProjectCombos() {
return true;
}
/// !TODO
bool MainWindow::populateMapList() {
// bool success = editor->project->readMapGroups();
// if (success) {
// sortMapList();
// }
// return success;
bool success = editor->project->readMapGroups();
if (success) {
sortMapList();
}
this->mapGroupModel = new MapGroupModel(editor->project);
this->groupListProxyModel = new FilterChildrenProxyModel();
groupListProxyModel->setSourceModel(this->mapGroupModel);
ui->mapList->setModel(groupListProxyModel);
// ui->mapList->setSelectionMode(QAbstractItemView::ExtendedSelection);
// ui->mapList->setDragEnabled(true);
// ui->mapList->setAcceptDrops(true);
// ui->mapList->setDropIndicatorShown(true);
return success;
//MapGroupModel
}
void MainWindow::sortMapList() {
Project *project = editor->project;
// Project *project = editor->project;
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 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);
// 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();
// 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;
case MapSortOrder::Area:
{
QMap<QString, int> mapsecToGroupNum;
for (int i = 0; i < project->mapSectionNameToValue.size(); i++) {
QString mapsec_name = project->mapSectionValueToName.value(i);
QStandardItem *mapsec = new QStandardItem;
mapsec->setText(mapsec_name);
mapsec->setIcon(folderIcon);
mapsec->setEditable(false);
mapsec->setData(mapsec_name, Qt::UserRole);
mapsec->setData("map_sec", MapListUserRoles::TypeRole);
mapsec->setData(i, MapListUserRoles::GroupRole);
root->appendRow(mapsec);
mapGroupItemsList->append(mapsec);
mapsecToGroupNum.insert(mapsec_name, 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 location = project->readMapLocation(map_name);
QStandardItem *mapsecItem = mapGroupItemsList->at(mapsecToGroupNum[location]);
mapsecItem->setIcon(mapFolderIcon);
mapsecItem->appendRow(map);
mapListIndexes.insert(map_name, map->index());
}
}
break;
}
case MapSortOrder::Layout:
{
QMap<QString, int> 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;
}
}
// 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;
// case MapSortOrder::Area:
// {
// QMap<QString, int> mapsecToGroupNum;
// for (int i = 0; i < project->mapSectionNameToValue.size(); i++) {
// QString mapsec_name = project->mapSectionValueToName.value(i);
// QStandardItem *mapsec = new QStandardItem;
// mapsec->setText(mapsec_name);
// mapsec->setIcon(folderIcon);
// mapsec->setEditable(false);
// mapsec->setData(mapsec_name, Qt::UserRole);
// mapsec->setData("map_sec", MapListUserRoles::TypeRole);
// mapsec->setData(i, MapListUserRoles::GroupRole);
// root->appendRow(mapsec);
// mapGroupItemsList->append(mapsec);
// mapsecToGroupNum.insert(mapsec_name, 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 location = project->readMapLocation(map_name);
// QStandardItem *mapsecItem = mapGroupItemsList->at(mapsecToGroupNum[location]);
// mapsecItem->setIcon(mapFolderIcon);
// mapsecItem->appendRow(map);
// mapListIndexes.insert(map_name, map->index());
// }
// }
// break;
// }
// case MapSortOrder::Layout:
// {
// QMap<QString, int> 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;
// }
// }
ui->mapList->setUpdatesEnabled(true);
ui->mapList->repaint();
updateMapList();
// ui->mapList->setUpdatesEnabled(true);
// ui->mapList->repaint();
// 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;
// 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)
{
QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point));
if (!index.isValid()) {
return;
}
/// !TODO
// QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point));
// if (!index.isValid()) {
// return;
// }
QStandardItem *selectedItem = mapListModel->itemFromIndex(index);
QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole);
if (!itemType.isValid()) {
return;
}
// QStandardItem *selectedItem = mapListModel->itemFromIndex(index);
// QVariant itemType = selectedItem->data(MapListUserRoles::TypeRole);
// if (!itemType.isValid()) {
// return;
// }
// Build custom context menu depending on which type of item was selected (map group, map name, etc.)
if (itemType == "map_group") {
QString groupName = selectedItem->data(Qt::UserRole).toString();
int groupNum = selectedItem->data(MapListUserRoles::GroupRole).toInt();
QMenu* menu = new QMenu(this);
QActionGroup* actions = new QActionGroup(menu);
actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupNum);
connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToGroupClick);
menu->exec(QCursor::pos());
} else if (itemType == "map_sec") {
QString secName = selectedItem->data(Qt::UserRole).toString();
QMenu* menu = new QMenu(this);
QActionGroup* actions = new QActionGroup(menu);
actions->addAction(menu->addAction("Add New Map to Area"))->setData(secName);
connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToAreaClick);
menu->exec(QCursor::pos());
} else if (itemType == "map_layout") {
QString layoutId = selectedItem->data(MapListUserRoles::TypeRole2).toString();
QMenu* menu = new QMenu(this);
QActionGroup* actions = new QActionGroup(menu);
actions->addAction(menu->addAction("Add New Map with Layout"))->setData(layoutId);
connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToLayoutClick);
menu->exec(QCursor::pos());
}
// // Build custom context menu depending on which type of item was selected (map group, map name, etc.)
// if (itemType == "map_group") {
// QString groupName = selectedItem->data(Qt::UserRole).toString();
// int groupNum = selectedItem->data(MapListUserRoles::GroupRole).toInt();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map to Group"))->setData(groupNum);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToGroupClick);
// menu->exec(QCursor::pos());
// } else if (itemType == "map_sec") {
// QString secName = selectedItem->data(Qt::UserRole).toString();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map to Area"))->setData(secName);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToAreaClick);
// menu->exec(QCursor::pos());
// } else if (itemType == "map_layout") {
// QString layoutId = selectedItem->data(MapListUserRoles::TypeRole2).toString();
// QMenu* menu = new QMenu(this);
// QActionGroup* actions = new QActionGroup(menu);
// actions->addAction(menu->addAction("Add New Map with Layout"))->setData(layoutId);
// connect(actions, &QActionGroup::triggered, this, &MainWindow::onAddNewMapToLayoutClick);
// menu->exec(QCursor::pos());
// }
}
void MainWindow::onAddNewMapToGroupClick(QAction* triggeredAction)
@ -1170,14 +1166,15 @@ void MainWindow::onNewMapCreated() {
editor->project->saveMap(newMap);
editor->project->saveAllDataStructures();
QStandardItem* groupItem = mapGroupItemsList->at(newMapGroup);
int numMapsInGroup = groupItem->rowCount();
// !TODO
// QStandardItem* groupItem = mapGroupItemsList->at(newMapGroup);
// int numMapsInGroup = groupItem->rowCount();
QStandardItem *newMapItem = createMapItem(newMapName, newMapGroup, numMapsInGroup);
groupItem->appendRow(newMapItem);
mapListIndexes.insert(newMapName, newMapItem->index());
// QStandardItem *newMapItem = createMapItem(newMapName, newMapGroup, numMapsInGroup);
// groupItem->appendRow(newMapItem);
// mapListIndexes.insert(newMapName, newMapItem->index());
sortMapList();
// sortMapList();
setMap(newMapName, true);
if (newMap->needsHealLocation) {
@ -1362,10 +1359,11 @@ void MainWindow::currentMetatilesSelectionChanged()
}
}
/// !TODO
void MainWindow::on_mapList_activated(const QModelIndex &index)
{
QVariant data = index.data(Qt::UserRole);
if (index.data(MapListUserRoles::TypeRole) == "map_name" && !data.isNull()) {
if (index.data(MapListRoles::TypeRole) == "map_name" && !data.isNull()) {
QString mapName = data.toString();
if (!setMap(mapName)) {
QMessageBox msgBox(this);
@ -1378,38 +1376,43 @@ void MainWindow::on_mapList_activated(const QModelIndex &index)
}
}
/// !TODO something with the projectHasUnsavedChanges var
void MainWindow::drawMapListIcons(QAbstractItemModel *model) {
projectHasUnsavedChanges = false;
QList<QModelIndex> 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);
}
}
}
}
}
// projectHasUnsavedChanges = false;
// QList<QModelIndex> 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);
// }
// }
// }
// }
// }
}
void MainWindow::updateMapList() {
drawMapListIcons(mapListModel);
//MapGroupModel *model = static_cast<MapGroupModel *>(this->ui->mapList->model());
mapGroupModel->setMap(this->editor->map->name);
groupListProxyModel->layoutChanged();
//mapGroupModel->layoutChanged();
// drawMapListIcons(mapListModel);
}
void MainWindow::on_action_Save_Project_triggered() {
@ -2667,18 +2670,42 @@ void MainWindow::initTilesetEditor() {
connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved);
}
void MainWindow::on_toolButton_ExpandAll_clicked()
{
if (ui->mapList) {
ui->mapList->expandToDepth(0);
}
// void MainWindow::on_toolButton_ExpandAll_clicked()
// {
// if (ui->mapList) {
// ui->mapList->expandToDepth(0);
// }
// }
// void MainWindow::on_toolButton_CollapseAll_clicked()
// {
// if (ui->mapList) {
// ui->mapList->collapseAll();
// }
// }
void MainWindow::on_toolButton_ExpandAll_Groups_clicked() {
//
}
void MainWindow::on_toolButton_CollapseAll_clicked()
{
if (ui->mapList) {
ui->mapList->collapseAll();
}
void MainWindow::on_toolButton_CollapseAll_Groups_clicked() {
//
}
void MainWindow::on_toolButton_ExpandAll_Areas_clicked() {
//
}
void MainWindow::on_toolButton_CollapseAll_Areas_clicked() {
//
}
void MainWindow::on_toolButton_ExpandAll_Layouts_clicked() {
//
}
void MainWindow::on_toolButton_CollapseAll_Layouts_clicked() {
//
}
void MainWindow::on_actionAbout_Porymap_triggered()

219
src/ui/maplistmodels.cpp Normal file
View file

@ -0,0 +1,219 @@
#include "maplistmodels.h"
#include "project.h"
/*
// 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<QStandardItem*>;
// 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();
}
QStandardItem *MapGroupModel::createGroupItem(QString groupName, int groupIndex) {
QStandardItem *group = new QStandardItem;
group->setText(groupName);
group->setEditable(true);
group->setData(groupName, Qt::UserRole);
group->setData("map_group", MapListRoles::TypeRole);
group->setData(groupIndex, MapListRoles::GroupRole);
// group->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
this->groupItems.insert(groupName, group);
return group;
}
QStandardItem *MapGroupModel::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 MapGroupModel::initialize() {
for (int i = 0; i < this->project->groupNames.length(); i++) {
QString group_name = this->project->groupNames.value(i);
QStandardItem *group = createGroupItem(group_name, i);
root->appendRow(group);
QList<QStandardItem *> groupItems;
QMap<QString, QStandardItem *> 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);
QStandardItem *map = createMapItem(map_name, i, j);
group->appendRow(map);
}
}
}
QStandardItem *MapGroupModel::getItem(const QModelIndex &index) const {
if (index.isValid()) {
QStandardItem *item = static_cast<QStandardItem*>(index.internalPointer());
if (item)
return item;
}
return this->root;
}
QModelIndex MapGroupModel::indexOfMap(QString mapName) {
if (this->mapItems.contains(mapName)) {
return this->mapItems[mapName]->index();
}
return QModelIndex();
}
// projectHasUnsavedChanges = false;
// QList<QModelIndex> 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 <QDebug>
QVariant MapGroupModel::data(const QModelIndex &index, int role) const {
int row = index.row();
int col = index.column();
if (role == Qt::DecorationRole) {
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 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);
loaded = true;
}
QStandardItem *item = this->getItem(index)->child(row, col);
QString type = item->data(MapListRoles::TypeRole).toString();
if (type == "map_group") {
return mapFolderIcon;
} 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;
}
}
return mapIcon;
}
// check if map or group
// if map, check if edited or open
//return QIcon(":/icons/porymap-icon-2.ico");
}
return QStandardItemModel::data(index, role);
}