add areaList model and filtering, scrolling for all trees
This commit is contained in:
parent
9918159caa
commit
e2ff93e5e7
7 changed files with 241 additions and 208 deletions
|
@ -266,6 +266,8 @@ private slots:
|
|||
void on_actionTileset_Editor_triggered();
|
||||
|
||||
void on_lineEdit_filterBox_textChanged(const QString &arg1);
|
||||
void on_lineEdit_filterBox_Areas_textChanged(const QString &arg1);
|
||||
void on_lineEdit_filterBox_Layouts_textChanged(const QString &arg1);
|
||||
|
||||
void moveEvent(QMoveEvent *event);
|
||||
void closeEvent(QCloseEvent *);
|
||||
|
@ -318,6 +320,9 @@ private:
|
|||
FilterChildrenProxyModel *groupListProxyModel;
|
||||
MapGroupModel *mapGroupModel;
|
||||
|
||||
FilterChildrenProxyModel *areaListProxyModel;
|
||||
MapAreaModel *mapAreaModel;
|
||||
|
||||
FilterChildrenProxyModel *layoutListProxyModel;
|
||||
LayoutTreeModel *layoutTreeModel;
|
||||
|
||||
|
@ -348,13 +353,13 @@ private:
|
|||
bool newMapDefaultsSet = false;
|
||||
|
||||
MapSortOrder mapSortOrder;
|
||||
enum MapListTab { Groups, Areas, Layouts };
|
||||
enum MapListTab { Groups = 0, Areas, Layouts };
|
||||
|
||||
bool tilesetNeedsRedraw = false;
|
||||
|
||||
bool setLayout(QString layoutId);
|
||||
|
||||
bool setMap(QString, bool scrollTreeView = false);
|
||||
bool setMap(QString, bool scroll = false);
|
||||
void unsetMap();
|
||||
void redrawMapScene();
|
||||
void refreshMapScene();
|
||||
|
@ -363,11 +368,11 @@ private:
|
|||
bool populateMapList();
|
||||
void sortMapList();
|
||||
void openSubWindow(QWidget * window);
|
||||
void scrollTreeView(QString itemName);
|
||||
QString getExistingDirectory(QString);
|
||||
bool openProject(QString dir);
|
||||
QString getDefaultMap();
|
||||
void setRecentMap(QString map_name);
|
||||
QStandardItem* createMapItem(QString mapName, int groupNum, int inGroupNum);
|
||||
|
||||
void updateMapList();
|
||||
|
||||
|
|
|
@ -15,7 +15,8 @@ enum MapListRoles {
|
|||
TypeRole2, // Used for various extra data needed.
|
||||
};
|
||||
|
||||
// or QStandardItemModel??
|
||||
|
||||
|
||||
class MapGroupModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -52,6 +53,42 @@ signals:
|
|||
|
||||
|
||||
|
||||
class MapAreaModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MapAreaModel(Project *project, QObject *parent = nullptr);
|
||||
~MapAreaModel() {}
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
public:
|
||||
void setMap(QString mapName) { this->openMap = mapName; }
|
||||
|
||||
QStandardItem *createAreaItem(QString areaName, int areaIndex);
|
||||
QStandardItem *createMapItem(QString mapName, int areaIndex, int mapIndex);
|
||||
|
||||
QStandardItem *getItem(const QModelIndex &index) const;
|
||||
QModelIndex indexOfMap(QString mapName);
|
||||
|
||||
void initialize();
|
||||
|
||||
private:
|
||||
Project *project;
|
||||
QStandardItem *root = nullptr;
|
||||
|
||||
QMap<QString, QStandardItem *> areaItems;
|
||||
QMap<QString, QStandardItem *> mapItems;
|
||||
// TODO: if reordering, will the item be the same?
|
||||
|
||||
QString openMap;
|
||||
|
||||
signals:
|
||||
void edited();
|
||||
};
|
||||
|
||||
|
||||
|
||||
class LayoutTreeModel : public QStandardItemModel {
|
||||
Q_OBJECT
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
BIN
resources/icons/connections.ico
Normal file
BIN
resources/icons/connections.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -34,6 +34,8 @@
|
|||
<file>icons/sort_number.ico</file>
|
||||
<file>icons/tall_grass.ico</file>
|
||||
<file>icons/viewsprites.ico</file>
|
||||
<file>icons/application_form_edit.ico</file>
|
||||
<file>icons/connections.ico</file>
|
||||
<file>icons/ui/dark_checkbox_checked_disabled.png</file>
|
||||
<file>icons/ui/dark_checkbox_checked_disabled@2x.png</file>
|
||||
<file>icons/ui/dark_checkbox_checked.png</file>
|
||||
|
|
|
@ -205,8 +205,11 @@ void MainWindow::initCustomUI() {
|
|||
ui->mainTabBar->addTab("Map");
|
||||
ui->mainTabBar->setTabIcon(0, QIcon(QStringLiteral(":/icons/map.ico")));
|
||||
ui->mainTabBar->addTab("Events");
|
||||
ui->mainTabBar->setTabIcon(1, QIcon(QStringLiteral(":/icons/viewsprites.ico")));
|
||||
ui->mainTabBar->addTab("Header");
|
||||
ui->mainTabBar->setTabIcon(2, QIcon(QStringLiteral(":/icons/application_form_edit.ico")));
|
||||
ui->mainTabBar->addTab("Connections");
|
||||
ui->mainTabBar->setTabIcon(3, QIcon(QStringLiteral(":/icons/connections.ico")));
|
||||
ui->mainTabBar->addTab("Wild Pokemon");
|
||||
ui->mainTabBar->setTabIcon(4, QIcon(QStringLiteral(":/icons/tall_grass.ico")));
|
||||
}
|
||||
|
@ -340,6 +343,8 @@ void MainWindow::initMapSortOrder() {
|
|||
// QMenu *mapSortOrderMenu = new QMenu(this);
|
||||
// QActionGroup *mapSortOrderActionGroup = new QActionGroup(ui->toolButton_MapSortOrder);
|
||||
|
||||
// porymapConfig.setMapSortOrder(mapSortOrder);
|
||||
|
||||
// mapSortOrderMenu->addAction(ui->actionSort_by_Group);
|
||||
// mapSortOrderMenu->addAction(ui->actionSort_by_Area);
|
||||
// mapSortOrderMenu->addAction(ui->actionSort_by_Layout);
|
||||
|
@ -410,14 +415,40 @@ void MainWindow::on_lineEdit_filterBox_textChanged(const QString &text) {
|
|||
this->applyMapListFilter(text);
|
||||
}
|
||||
|
||||
void MainWindow::applyMapListFilter(QString filterText) {
|
||||
/// !TODO
|
||||
groupListProxyModel->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption));
|
||||
if (filterText.isEmpty()) {
|
||||
ui->mapList->collapseAll();
|
||||
} else {
|
||||
ui->mapList->expandToDepth(0);
|
||||
void MainWindow::on_lineEdit_filterBox_Areas_textChanged(const QString &text) {
|
||||
this->applyMapListFilter(text);
|
||||
}
|
||||
|
||||
void MainWindow::on_lineEdit_filterBox_Layouts_textChanged(const QString &text) {
|
||||
this->applyMapListFilter(text);
|
||||
}
|
||||
|
||||
void MainWindow::applyMapListFilter(QString filterText) {
|
||||
FilterChildrenProxyModel *proxy;
|
||||
QTreeView *list;
|
||||
switch (this->mapSortOrder) {
|
||||
case MapSortOrder::SortByGroup:
|
||||
proxy = this->groupListProxyModel;
|
||||
list = this->ui->mapList;
|
||||
break;
|
||||
case MapSortOrder::SortByArea:
|
||||
proxy = this->areaListProxyModel;
|
||||
list = this->ui->areaList;
|
||||
break;
|
||||
case MapSortOrder::SortByLayout:
|
||||
proxy = this->layoutListProxyModel;
|
||||
list = this->ui->layoutList;
|
||||
break;
|
||||
}
|
||||
|
||||
proxy->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption));
|
||||
if (filterText.isEmpty()) {
|
||||
list->collapseAll();
|
||||
} else {
|
||||
list->expandToDepth(0);
|
||||
}
|
||||
|
||||
/// !TODO
|
||||
// ui->mapList->setExpanded(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), true);
|
||||
// ui->mapList->scrollTo(mapListProxyModel->mapFromSource(mapListIndexes.value(editor->map->name)), QAbstractItemView::PositionAtCenter);
|
||||
}
|
||||
|
@ -432,6 +463,9 @@ void MainWindow::loadUserSettings() {
|
|||
ui->checkBox_ToggleBorder->setChecked(porymapConfig.getShowBorder());
|
||||
ui->checkBox_ToggleGrid->setChecked(porymapConfig.getShowGrid());
|
||||
mapSortOrder = porymapConfig.getMapSortOrder();
|
||||
this->ui->mapListContainer->blockSignals(true);
|
||||
this->ui->mapListContainer->setCurrentIndex(static_cast<int>(this->mapSortOrder));
|
||||
this->ui->mapListContainer->blockSignals(false);
|
||||
ui->horizontalSlider_CollisionTransparency->blockSignals(true);
|
||||
this->editor->collisionOpacity = static_cast<qreal>(porymapConfig.getCollisionOpacity()) / 100;
|
||||
ui->horizontalSlider_CollisionTransparency->setValue(porymapConfig.getCollisionOpacity());
|
||||
|
@ -643,7 +677,7 @@ void MainWindow::unsetMap() {
|
|||
this->ui->comboBox_LayoutSelector->setEnabled(false);
|
||||
}
|
||||
|
||||
bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
||||
bool MainWindow::setMap(QString map_name, bool scroll) {
|
||||
// if map name is empty, clear & disable map ui
|
||||
if (map_name.isEmpty()) {
|
||||
unsetMap();
|
||||
|
@ -670,12 +704,8 @@ bool MainWindow::setMap(QString map_name, bool scrollTreeView) {
|
|||
refreshMapScene();
|
||||
displayMapProperties();
|
||||
|
||||
if (scrollTreeView) {
|
||||
// Make sure we clear the filter first so we actually have a scroll target
|
||||
/// !TODO: make this onto a function that scrolls the current view taking a map name or layout name
|
||||
groupListProxyModel->setFilterRegularExpression(QString());
|
||||
ui->mapList->setCurrentIndex(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)));
|
||||
ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||
if (scroll) {
|
||||
scrollTreeView(map_name);
|
||||
}
|
||||
|
||||
showWindowTitle();
|
||||
|
@ -1042,13 +1072,7 @@ bool MainWindow::loadProjectCombos() {
|
|||
return true;
|
||||
}
|
||||
|
||||
/// !TODO
|
||||
bool MainWindow::populateMapList() {
|
||||
// bool success = editor->project->readMapGroups();
|
||||
// if (success) {
|
||||
// sortMapList();
|
||||
// }
|
||||
// return success;
|
||||
bool success = editor->project->readMapGroups();
|
||||
|
||||
this->mapGroupModel = new MapGroupModel(editor->project);
|
||||
|
@ -1056,21 +1080,43 @@ bool MainWindow::populateMapList() {
|
|||
groupListProxyModel->setSourceModel(this->mapGroupModel);
|
||||
ui->mapList->setModel(groupListProxyModel);
|
||||
|
||||
this->mapAreaModel = new MapAreaModel(editor->project);
|
||||
this->areaListProxyModel = new FilterChildrenProxyModel();
|
||||
areaListProxyModel->setSourceModel(this->mapAreaModel);
|
||||
ui->areaList->setModel(areaListProxyModel);
|
||||
|
||||
this->layoutTreeModel = new LayoutTreeModel(editor->project);
|
||||
this->layoutListProxyModel = new FilterChildrenProxyModel();
|
||||
this->layoutListProxyModel->setSourceModel(this->layoutTreeModel);
|
||||
ui->layoutList->setModel(layoutListProxyModel);
|
||||
|
||||
//connect(this->ui->layoutList, &QTreeView::doubleClicked, this, &MainWindow::on_layoutList_activated);
|
||||
|
||||
/// !TODO
|
||||
// ui->mapList->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
// ui->mapList->setDragEnabled(true);
|
||||
// ui->mapList->setAcceptDrops(true);
|
||||
// ui->mapList->setDropIndicatorShown(true);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
//MapGroupModel
|
||||
void MainWindow::scrollTreeView(QString itemName) {
|
||||
switch (ui->mapListContainer->currentIndex()) {
|
||||
case MapListTab::Groups:
|
||||
groupListProxyModel->setFilterRegularExpression(QString());
|
||||
ui->mapList->setCurrentIndex(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(itemName)));
|
||||
ui->mapList->scrollTo(ui->mapList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||
break;
|
||||
case MapListTab::Areas:
|
||||
areaListProxyModel->setFilterRegularExpression(QString());
|
||||
ui->areaList->setCurrentIndex(areaListProxyModel->mapFromSource(mapAreaModel->indexOfMap(itemName)));
|
||||
ui->areaList->scrollTo(ui->areaList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||
break;
|
||||
case MapListTab::Layouts:
|
||||
layoutListProxyModel->setFilterRegularExpression(QString());
|
||||
ui->layoutList->setCurrentIndex(layoutListProxyModel->mapFromSource(layoutTreeModel->indexOfLayout(itemName)));
|
||||
ui->layoutList->scrollTo(ui->layoutList->currentIndex(), QAbstractItemView::PositionAtCenter);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::sortMapList() {
|
||||
|
@ -1181,19 +1227,7 @@ void MainWindow::sortMapList() {
|
|||
// updateMapList();
|
||||
}
|
||||
|
||||
/// !TODO
|
||||
QStandardItem* MainWindow::createMapItem(QString mapName, int groupNum, int inGroupNum) {
|
||||
// QStandardItem *map = new QStandardItem;
|
||||
// map->setText(QString("[%1.%2] ").arg(groupNum).arg(inGroupNum, 2, 10, QLatin1Char('0')) + mapName);
|
||||
// map->setIcon(*mapIcon);
|
||||
// map->setEditable(false);
|
||||
// map->setData(mapName, Qt::UserRole);
|
||||
// map->setData("map_name", MapListUserRoles::TypeRole);
|
||||
// return map;
|
||||
}
|
||||
|
||||
void MainWindow::onOpenMapListContextMenu(const QPoint &point)
|
||||
{
|
||||
void MainWindow::onOpenMapListContextMenu(const QPoint &point) {
|
||||
/// !TODO
|
||||
// QModelIndex index = mapListProxyModel->mapToSource(ui->mapList->indexAt(point));
|
||||
// if (!index.isValid()) {
|
||||
|
@ -1462,14 +1496,19 @@ void MainWindow::on_mapListContainer_currentChanged(int index) {
|
|||
//
|
||||
switch (index) {
|
||||
case MapListTab::Groups:
|
||||
this->mapSortOrder = MapSortOrder::SortByGroup;
|
||||
if (this->editor && this->editor->map) scrollTreeView(this->editor->map->name);
|
||||
break;
|
||||
case MapListTab::Areas:
|
||||
this->mapSortOrder = MapSortOrder::SortByArea;
|
||||
if (this->editor && this->editor->map) scrollTreeView(this->editor->map->name);
|
||||
break;
|
||||
case MapListTab::Layouts:
|
||||
//setMap(nullptr);
|
||||
//setLayout(nullptr);
|
||||
this->mapSortOrder = MapSortOrder::SortByLayout;
|
||||
if (this->editor && this->editor->layout) scrollTreeView(this->editor->layout->id);
|
||||
break;
|
||||
}
|
||||
porymapConfig.setMapSortOrder(this->mapSortOrder);
|
||||
}
|
||||
|
||||
/// !TODO
|
||||
|
@ -1489,7 +1528,7 @@ void MainWindow::on_mapList_activated(const QModelIndex &index) {
|
|||
}
|
||||
|
||||
void MainWindow::on_areaList_activated(const QModelIndex &index) {
|
||||
//
|
||||
on_mapList_activated(index);
|
||||
}
|
||||
|
||||
void MainWindow::on_layoutList_activated(const QModelIndex &index) {
|
||||
|
@ -1520,6 +1559,8 @@ void MainWindow::updateMapList() {
|
|||
if (this->editor->map) {
|
||||
mapGroupModel->setMap(this->editor->map->name);
|
||||
groupListProxyModel->layoutChanged();
|
||||
mapAreaModel->setMap(this->editor->map->name);
|
||||
areaListProxyModel->layoutChanged();
|
||||
}
|
||||
|
||||
if (this->editor->layout) {
|
||||
|
|
|
@ -4,89 +4,10 @@
|
|||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
// QIcon mapFolderIcon;
|
||||
// mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
// mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On);
|
||||
|
||||
// QIcon folderIcon;
|
||||
// folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
// //folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On);
|
||||
|
||||
// ui->mapList->setUpdatesEnabled(false);
|
||||
// mapListModel->clear();
|
||||
// mapGroupItemsList->clear();
|
||||
// QStandardItem *root = mapListModel->invisibleRootItem();
|
||||
|
||||
// switch (mapSortOrder)
|
||||
// {
|
||||
// case MapSortOrder::Group:
|
||||
// for (int i = 0; i < project->groupNames.length(); i++) {
|
||||
// QString group_name = project->groupNames.value(i);
|
||||
// QStandardItem *group = new QStandardItem;
|
||||
// group->setText(group_name);
|
||||
// group->setIcon(mapFolderIcon);
|
||||
// group->setEditable(false);
|
||||
// group->setData(group_name, Qt::UserRole);
|
||||
// group->setData("map_group", MapListUserRoles::TypeRole);
|
||||
// group->setData(i, MapListUserRoles::GroupRole);
|
||||
// root->appendRow(group);
|
||||
// mapGroupItemsList->append(group);
|
||||
// QStringList names = project->groupedMapNames.value(i);
|
||||
// for (int j = 0; j < names.length(); j++) {
|
||||
// QString map_name = names.value(j);
|
||||
// QStandardItem *map = createMapItem(map_name, i, j);
|
||||
// group->appendRow(map);
|
||||
// mapListIndexes.insert(map_name, map->index());
|
||||
// }
|
||||
// }
|
||||
// break;
|
||||
|
||||
// mapListModel = new QStandardItemModel;
|
||||
// mapGroupItemsList = new QList<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();
|
||||
}
|
||||
|
||||
|
@ -118,9 +39,6 @@ void MapGroupModel::initialize() {
|
|||
QString group_name = this->project->groupNames.value(i);
|
||||
QStandardItem *group = createGroupItem(group_name, i);
|
||||
root->appendRow(group);
|
||||
QList<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);
|
||||
|
@ -146,35 +64,6 @@ QModelIndex MapGroupModel::indexOfMap(QString mapName) {
|
|||
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();
|
||||
|
@ -213,10 +102,6 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const {
|
|||
}
|
||||
return mapGrayIcon;
|
||||
}
|
||||
|
||||
// check if map or group
|
||||
// if map, check if edited or open
|
||||
//return QIcon(":/icons/porymap-icon-2.ico");
|
||||
}
|
||||
|
||||
return QStandardItemModel::data(index, role);
|
||||
|
@ -224,52 +109,124 @@ QVariant MapGroupModel::data(const QModelIndex &index, int role) const {
|
|||
|
||||
|
||||
|
||||
MapAreaModel::MapAreaModel(Project *project, QObject *parent) : QStandardItemModel(parent) {
|
||||
this->project = project;
|
||||
this->root = this->invisibleRootItem();
|
||||
|
||||
initialize();
|
||||
}
|
||||
|
||||
QStandardItem *MapAreaModel::createAreaItem(QString mapsecName, int areaIndex) {
|
||||
QStandardItem *area = new QStandardItem;
|
||||
area->setText(mapsecName);
|
||||
area->setEditable(false);
|
||||
area->setData(mapsecName, Qt::UserRole);
|
||||
area->setData("map_section", MapListRoles::TypeRole);
|
||||
area->setData(areaIndex, MapListRoles::GroupRole);
|
||||
// group->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||
this->areaItems.insert(mapsecName, area);
|
||||
return area;
|
||||
}
|
||||
|
||||
QStandardItem *MapAreaModel::createMapItem(QString mapName, int groupIndex, int mapIndex) {
|
||||
QStandardItem *map = new QStandardItem;
|
||||
map->setText(QString("[%1.%2] ").arg(groupIndex).arg(mapIndex, 2, 10, QLatin1Char('0')) + mapName);
|
||||
map->setEditable(false);
|
||||
map->setData(mapName, Qt::UserRole);
|
||||
map->setData("map_name", MapListRoles::TypeRole);
|
||||
// map->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled);
|
||||
this->mapItems.insert(mapName, map);
|
||||
return map;
|
||||
}
|
||||
|
||||
void MapAreaModel::initialize() {
|
||||
for (int i = 0; i < this->project->mapSectionNameToValue.size(); i++) {
|
||||
QString mapsecName = project->mapSectionValueToName.value(i);
|
||||
QStandardItem *areaItem = createAreaItem(mapsecName, i);
|
||||
this->root->appendRow(areaItem);
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->project->groupNames.length(); i++) {
|
||||
QStringList names = this->project->groupedMapNames.value(i);
|
||||
for (int j = 0; j < names.length(); j++) {
|
||||
QString mapName = names.value(j);
|
||||
QStandardItem *map = createMapItem(mapName, i, j);
|
||||
QString mapsecName = this->project->readMapLocation(mapName);
|
||||
if (this->areaItems.contains(mapsecName)) {
|
||||
this->areaItems[mapsecName]->appendRow(map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStandardItem *MapAreaModel::getItem(const QModelIndex &index) const {
|
||||
if (index.isValid()) {
|
||||
QStandardItem *item = static_cast<QStandardItem*>(index.internalPointer());
|
||||
if (item)
|
||||
return item;
|
||||
}
|
||||
return this->root;
|
||||
}
|
||||
|
||||
QModelIndex MapAreaModel::indexOfMap(QString mapName) {
|
||||
if (this->mapItems.contains(mapName)) {
|
||||
return this->mapItems[mapName]->index();
|
||||
}
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
QVariant MapAreaModel::data(const QModelIndex &index, int role) const {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
|
||||
if (role == Qt::DecorationRole) {
|
||||
static QIcon mapGrayIcon = QIcon(QStringLiteral(":/icons/map_grayed.ico"));
|
||||
static QIcon mapIcon = QIcon(QStringLiteral(":/icons/map.ico"));
|
||||
static QIcon mapEditedIcon = QIcon(QStringLiteral(":/icons/map_edited.ico"));
|
||||
static QIcon mapOpenedIcon = QIcon(QStringLiteral(":/icons/map_opened.ico"));
|
||||
|
||||
static QIcon mapFolderIcon;
|
||||
static QIcon folderIcon;
|
||||
static bool loaded = false;
|
||||
if (!loaded) {
|
||||
mapFolderIcon.addFile(QStringLiteral(":/icons/folder_closed_map.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
mapFolderIcon.addFile(QStringLiteral(":/icons/folder_map.ico"), QSize(), QIcon::Normal, QIcon::On);
|
||||
folderIcon.addFile(QStringLiteral(":/icons/folder_closed.ico"), QSize(), QIcon::Normal, QIcon::Off);
|
||||
folderIcon.addFile(QStringLiteral(":/icons/folder.ico"), QSize(), QIcon::Normal, QIcon::On);
|
||||
loaded = true;
|
||||
}
|
||||
|
||||
QStandardItem *item = this->getItem(index)->child(row, col);
|
||||
QString type = item->data(MapListRoles::TypeRole).toString();
|
||||
|
||||
if (type == "map_section") {
|
||||
if (item->hasChildren()) {
|
||||
return mapFolderIcon;
|
||||
}
|
||||
return folderIcon;
|
||||
} else if (type == "map_name") {
|
||||
QString mapName = item->data(Qt::UserRole).toString();
|
||||
if (mapName == this->openMap) {
|
||||
return mapOpenedIcon;
|
||||
}
|
||||
else if (this->project->mapCache.contains(mapName)) {
|
||||
if (this->project->mapCache.value(mapName)->hasUnsavedChanges()) {
|
||||
return mapEditedIcon;
|
||||
}
|
||||
else {
|
||||
return mapIcon;
|
||||
}
|
||||
}
|
||||
return mapGrayIcon;
|
||||
}
|
||||
}
|
||||
|
||||
return QStandardItemModel::data(index, role);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// case MapSortOrder::Layout:
|
||||
// {
|
||||
// QMap<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;
|
||||
// }
|
||||
LayoutTreeModel::LayoutTreeModel(Project *project, QObject *parent) : QStandardItemModel(parent) {
|
||||
//
|
||||
|
||||
this->project = project;
|
||||
this->root = this->invisibleRootItem();
|
||||
|
||||
|
@ -279,7 +236,6 @@ LayoutTreeModel::LayoutTreeModel(Project *project, QObject *parent) : QStandardI
|
|||
QStandardItem *LayoutTreeModel::createLayoutItem(QString layoutId) {
|
||||
QStandardItem *layout = new QStandardItem;
|
||||
layout->setText(this->project->layoutIdsToNames[layoutId]);
|
||||
//layout->setText(layoutId);
|
||||
layout->setEditable(false);
|
||||
layout->setData(layoutId, Qt::UserRole);
|
||||
layout->setData("map_layout", MapListRoles::TypeRole);
|
||||
|
@ -301,7 +257,6 @@ QStandardItem *LayoutTreeModel::createMapItem(QString mapName) {
|
|||
|
||||
void LayoutTreeModel::initialize() {
|
||||
for (int i = 0; i < this->project->mapLayoutsTable.length(); i++) {
|
||||
//
|
||||
QString layoutId = project->mapLayoutsTable.value(i);
|
||||
QStandardItem *layoutItem = createLayoutItem(layoutId);
|
||||
this->root->appendRow(layoutItem);
|
||||
|
@ -315,8 +270,6 @@ void LayoutTreeModel::initialize() {
|
|||
this->layoutItems[layoutId]->appendRow(map);
|
||||
}
|
||||
}
|
||||
|
||||
// // project->readMapLayoutName
|
||||
}
|
||||
|
||||
QStandardItem *LayoutTreeModel::getItem(const QModelIndex &index) const {
|
||||
|
@ -364,12 +317,7 @@ QVariant LayoutTreeModel::data(const QModelIndex &index, int role) const {
|
|||
}
|
||||
|
||||
return QVariant();
|
||||
|
||||
// check if map or group
|
||||
// if map, check if edited or open
|
||||
//return QIcon(":/icons/porymap-icon-2.ico");
|
||||
}
|
||||
|
||||
return QStandardItemModel::data(index, role);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue