From f46ac36a94d7bee7aefdabbfad5929295ce4be50 Mon Sep 17 00:00:00 2001 From: garak Date: Thu, 18 Apr 2024 14:38:15 -0400 Subject: [PATCH] cleanup: shortcuts, setLayout --- include/mainwindow.h | 7 ++++--- src/core/maplayout.cpp | 43 ------------------------------------------ src/mainwindow.cpp | 34 +++++++++++++++------------------ 3 files changed, 19 insertions(+), 65 deletions(-) diff --git a/include/mainwindow.h b/include/mainwindow.h index d2350d72..7ee2786c 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -185,6 +185,7 @@ private slots: void onLoadMapRequested(QString, QString); void onMapChanged(Map *map); + void onLayoutChanged(Layout *layout); void onMapNeedsRedrawing(); void onLayoutNeedsRedrawing(); void onTilesetsSaved(QString, QString); @@ -280,9 +281,9 @@ private slots: void on_horizontalSlider_CollisionTransparency_valueChanged(int value); - void on_toolButton_HideShow_clicked(); - void on_toolButton_ExpandAll_clicked(); - void on_toolButton_CollapseAll_clicked(); + void do_HideShow(); + void do_ExpandAll(); + void do_CollapseAll(); void on_toolButton_HideShow_Groups_clicked(); void on_toolButton_ExpandAll_Groups_clicked(); void on_toolButton_CollapseAll_Groups_clicked(); diff --git a/src/core/maplayout.cpp b/src/core/maplayout.cpp index 4f639373..9e283e26 100644 --- a/src/core/maplayout.cpp +++ b/src/core/maplayout.cpp @@ -5,51 +5,8 @@ #include "scripting.h" #include "imageproviders.h" - // QString id; - // QString name; - // int width; - // int height; - // int border_width; - // int border_height; - // QString border_path; - // QString blockdata_path; - - // QString tileset_primary_label; - // QString tileset_secondary_label; - - // Tileset *tileset_primary = nullptr; - // Tileset *tileset_secondary = nullptr; - - // Blockdata blockdata; - - // QImage image; - // QPixmap pixmap; - // QImage border_image; - // QPixmap border_pixmap; - // QImage collision_image; - // QPixmap collision_pixmap; - - // Blockdata border; - // Blockdata cached_blockdata; - // Blockdata cached_collision; - // Blockdata cached_border; - // struct { - // Blockdata blocks; - // QSize mapDimensions; - // Blockdata border; - // QSize borderDimensions; - // } lastCommitBlocks; // to track map changes - - // QList metatileLayerOrder; - // QList metatileLayerOpacity; - - // LayoutPixmapItem *layoutItem = nullptr; - // CollisionPixmapItem *collisionItem = nullptr; - // BorderMetatilesPixmapItem *borderItem = nullptr; - - // QUndoStack editHistory; Layout *Layout::copy() { Layout *layout = new Layout; layout->copyFrom(this); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6afeca14..f7884ad6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -162,15 +162,15 @@ void MainWindow::initExtraShortcuts() { shortcutToggle_Smart_Paths->setObjectName("shortcutToggle_Smart_Paths"); shortcutToggle_Smart_Paths->setWhatsThis("Toggle Smart Paths"); - auto *shortcutHide_Show = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_HideShow_clicked())); + auto *shortcutHide_Show = new Shortcut(QKeySequence(), this, SLOT(do_HideShow())); shortcutHide_Show->setObjectName("shortcutHide_Show"); shortcutHide_Show->setWhatsThis("Map List: Hide/Show Empty Folders"); - auto *shortcutExpand_All = new Shortcut(QKeySequence(), this, SLOT(on_toolButton_ExpandAll_clicked())); + auto *shortcutExpand_All = new Shortcut(QKeySequence(), this, SLOT(do_ExpandAll())); 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(do_CollapseAll())); shortcutCollapse_All->setObjectName("shortcutCollapse_All"); shortcutCollapse_All->setWhatsThis("Map List: Collapse all folders"); @@ -847,7 +847,6 @@ bool MainWindow::setMap(QString map_name, bool scroll) { } if (editor->map && !editor->map->name.isNull()) { - // !TODO: function to act on current view? or that does all the views ui->mapList->setExpanded(groupListProxyModel->mapFromSource(mapGroupModel->indexOfMap(map_name)), false); } @@ -869,12 +868,12 @@ bool MainWindow::setMap(QString map_name, bool scroll) { showWindowTitle(); - connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged); - connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing); - connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); }); + connect(editor->map, &Map::mapChanged, this, &MainWindow::onMapChanged, Qt::UniqueConnection); + connect(editor->map, &Map::mapNeedsRedrawing, this, &MainWindow::onMapNeedsRedrawing, Qt::UniqueConnection); + connect(editor->map, &Map::modified, this, &MainWindow::markMapEdited, Qt::UniqueConnection); - connect(editor->layout, &Layout::layoutChanged, [this]() { onMapChanged(nullptr); }); - connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing); + connect(editor->layout, &Layout::layoutChanged, this, &MainWindow::onLayoutChanged, Qt::UniqueConnection); + connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing, Qt::UniqueConnection); setRecentMapConfig(map_name); updateMapList(); @@ -903,9 +902,7 @@ bool MainWindow::setLayout(QString layoutId) { showWindowTitle(); updateMapList(); - // !TODO: make sure these connections are not duplicated / cleared later connect(editor->layout, &Layout::needsRedrawing, this, &MainWindow::onLayoutNeedsRedrawing, Qt::UniqueConnection); - // connect(editor->map, &Map::modified, [this](){ this->markMapEdited(); }); updateTilesetEditor(); @@ -1064,12 +1061,9 @@ void MainWindow::displayMapProperties() { } void MainWindow::on_comboBox_LayoutSelector_currentTextChanged(const QString &text) { - // if (editor && editor->project && editor->map) { if (editor->project->mapLayouts.contains(text)) { editor->map->setLayout(editor->project->loadLayout(text)); - // !TODO: method to setMapLayout instead of having to do whole setMap thing, - // also edit history and bug fixes setMap(editor->map->name); markMapEdited(); } @@ -1834,7 +1828,6 @@ void MainWindow::currentMetatilesSelectionChanged() { scrollMetatileSelectorToSelection(); } -// !TODO void MainWindow::on_mapListContainer_currentChanged(int index) { switch (index) { case MapListTab::Groups: @@ -1853,7 +1846,6 @@ void MainWindow::on_mapListContainer_currentChanged(int index) { porymapConfig.setMapSortOrder(this->mapSortOrder); } -/// !TODO void MainWindow::on_mapList_activated(const QModelIndex &index) { QVariant data = index.data(Qt::UserRole); if (index.data(MapListRoles::TypeRole) == "map_name" && !data.isNull()) { @@ -2844,6 +2836,10 @@ void MainWindow::onMapChanged(Map *) { updateMapList(); } +void MainWindow::onLayoutChanged(Layout *) { + updateMapList(); +} + void MainWindow::onMapNeedsRedrawing() { redrawMapScene(); } @@ -3172,7 +3168,7 @@ void MainWindow::initTilesetEditor() { connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved); } -void MainWindow::on_toolButton_ExpandAll_clicked() { +void MainWindow::do_ExpandAll() { switch (ui->mapListContainer->currentIndex()) { case MapListTab::Groups: this->on_toolButton_ExpandAll_Groups_clicked(); @@ -3186,7 +3182,7 @@ void MainWindow::on_toolButton_ExpandAll_clicked() { } } -void MainWindow::on_toolButton_CollapseAll_clicked() { +void MainWindow::do_CollapseAll() { switch (ui->mapListContainer->currentIndex()) { case MapListTab::Groups: this->on_toolButton_CollapseAll_Groups_clicked(); @@ -3200,7 +3196,7 @@ void MainWindow::on_toolButton_CollapseAll_clicked() { } } -void MainWindow::on_toolButton_HideShow_clicked() { +void MainWindow::do_HideShow() { switch (ui->mapListContainer->currentIndex()) { case MapListTab::Groups: this->on_toolButton_HideShow_Groups_clicked();