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

View file

@ -21,6 +21,7 @@
#include "regionmapeditor.h" #include "regionmapeditor.h"
#include "mapimageexporter.h" #include "mapimageexporter.h"
#include "filterchildrenproxymodel.h" #include "filterchildrenproxymodel.h"
#include "maplistmodels.h"
#include "newmappopup.h" #include "newmappopup.h"
#include "newtilesetdialog.h" #include "newtilesetdialog.h"
#include "shortcutseditor.h" #include "shortcutseditor.h"
@ -257,8 +258,6 @@ private slots:
void on_actionTileset_Editor_triggered(); void on_actionTileset_Editor_triggered();
void mapSortOrder_changed(QAction *action);
void on_lineEdit_filterBox_textChanged(const QString &arg1); void on_lineEdit_filterBox_textChanged(const QString &arg1);
void moveEvent(QMoveEvent *event); void moveEvent(QMoveEvent *event);
@ -267,8 +266,14 @@ private slots:
void eventTabChanged(int index); void eventTabChanged(int index);
void on_horizontalSlider_CollisionTransparency_valueChanged(int value); 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_actionAbout_Porymap_triggered();
void on_actionOpen_Log_File_triggered(); void on_actionOpen_Log_File_triggered();
void on_actionOpen_Config_Folder_triggered(); void on_actionOpen_Config_Folder_triggered();
@ -302,13 +307,15 @@ private:
QPointer<PreferenceEditor> preferenceEditor = nullptr; QPointer<PreferenceEditor> preferenceEditor = nullptr;
QPointer<ProjectSettingsEditor> projectSettingsEditor = nullptr; QPointer<ProjectSettingsEditor> projectSettingsEditor = nullptr;
QPointer<CustomScriptsEditor> customScriptsEditor = nullptr; QPointer<CustomScriptsEditor> customScriptsEditor = nullptr;
FilterChildrenProxyModel *mapListProxyModel;
QStandardItemModel *mapListModel; FilterChildrenProxyModel *groupListProxyModel;
QList<QStandardItem*> *mapGroupItemsList; MapGroupModel *mapGroupModel;
QMap<QString, QModelIndex> mapListIndexes; // QStandardItemModel *mapListModel;
QIcon* mapIcon; // QList<QStandardItem*> *mapGroupItemsList;
QIcon* mapEditedIcon; // QMap<QString, QModelIndex> mapListIndexes;
QIcon* mapOpenedIcon; // QIcon* mapIcon;
// QIcon* mapEditedIcon;
// QIcon* mapOpenedIcon;
QAction *undoAction = nullptr; QAction *undoAction = nullptr;
QAction *redoAction = nullptr; QAction *redoAction = nullptr;
@ -397,10 +404,4 @@ private:
int insertTilesetLabel(QStringList * list, QString label); 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 #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/customattributestable.cpp \
src/ui/eventframes.cpp \ src/ui/eventframes.cpp \
src/ui/filterchildrenproxymodel.cpp \ src/ui/filterchildrenproxymodel.cpp \
src/ui/maplistmodels.cpp \
src/ui/graphicsview.cpp \ src/ui/graphicsview.cpp \
src/ui/imageproviders.cpp \ src/ui/imageproviders.cpp \
src/ui/mappixmapitem.cpp \ src/ui/mappixmapitem.cpp \
@ -147,6 +148,7 @@ HEADERS += include/core/block.h \
include/ui/customattributestable.h \ include/ui/customattributestable.h \
include/ui/eventframes.h \ include/ui/eventframes.h \
include/ui/filterchildrenproxymodel.h \ include/ui/filterchildrenproxymodel.h \
include/ui/maplistmodels.h \
include/ui/graphicsview.h \ include/ui/graphicsview.h \
include/ui/imageproviders.h \ include/ui/imageproviders.h \
include/ui/mappixmapitem.h \ include/ui/mappixmapitem.h \

View file

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