Skip to content

Commit

Permalink
add areaList model and filtering, scrolling for all trees
Browse files Browse the repository at this point in the history
  • Loading branch information
garakmon committed Feb 7, 2023
1 parent 6ccb3bd commit 33c7293
Show file tree
Hide file tree
Showing 7 changed files with 231 additions and 198 deletions.
11 changes: 8 additions & 3 deletions include/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,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 *);
Expand Down Expand Up @@ -315,6 +317,9 @@ private slots:
FilterChildrenProxyModel *groupListProxyModel;
MapGroupModel *mapGroupModel;

FilterChildrenProxyModel *areaListProxyModel;
MapAreaModel *mapAreaModel;

FilterChildrenProxyModel *layoutListProxyModel;
LayoutTreeModel *layoutTreeModel;

Expand Down Expand Up @@ -345,25 +350,25 @@ private slots:
bool newMapDefaultsSet = false;

MapSortOrder mapSortOrder;
enum MapListTab { Groups, Areas, Layouts };
enum MapListTab { Groups = 0, Areas, Layouts };

bool needsFullRedraw = false;

bool setLayout(QString layoutId);

bool setMap(QString, bool scrollTreeView = false);
bool setMap(QString, bool scroll = false);
void unsetMap();
void redrawMapScene();
void refreshMapScene();
bool loadDataStructures();
bool loadProjectCombos();
bool populateMapList();
void sortMapList();
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();

Expand Down
39 changes: 38 additions & 1 deletion include/ui/maplistmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ enum MapListRoles {
TypeRole2, // Used for various extra data needed.
};

// or QStandardItemModel??


class MapGroupModel : public QStandardItemModel {
Q_OBJECT

Expand Down Expand Up @@ -52,6 +53,42 @@ class MapGroupModel : public QStandardItemModel {



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

Expand Down
Binary file modified resources/icons/application_form_edit.ico
Binary file not shown.
Binary file added resources/icons/connections.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions resources/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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>
Expand Down
113 changes: 77 additions & 36 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,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")));
}
Expand Down Expand Up @@ -339,6 +342,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);
Expand Down Expand Up @@ -411,14 +416,40 @@ void MainWindow::on_lineEdit_filterBox_textChanged(const QString &text) {
this->applyMapListFilter(text);
}

void MainWindow::on_lineEdit_filterBox_Areas_textChanged(const QString &text) {
this->applyMapListFilter(text);
}

void MainWindow::on_lineEdit_filterBox_Layouts_textChanged(const QString &text) {
this->applyMapListFilter(text);
}

void MainWindow::applyMapListFilter(QString filterText) {
/// !TODO
groupListProxyModel->setFilterRegularExpression(QRegularExpression(filterText, QRegularExpression::CaseInsensitiveOption));
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()) {
ui->mapList->collapseAll();
list->collapseAll();
} else {
ui->mapList->expandToDepth(0);
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);
}
Expand All @@ -433,6 +464,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());
Expand Down Expand Up @@ -624,7 +658,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();
Expand All @@ -651,12 +685,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();
Expand Down Expand Up @@ -1023,35 +1053,51 @@ 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);
this->groupListProxyModel = new FilterChildrenProxyModel();
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() {
Expand Down Expand Up @@ -1162,19 +1208,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()) {
Expand Down Expand Up @@ -1446,14 +1480,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
Expand All @@ -1473,7 +1512,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) {
Expand Down Expand Up @@ -1504,6 +1543,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) {
Expand Down
Loading

0 comments on commit 33c7293

Please sign in to comment.