From cd5b1f98d2531b008ca58fa89b205a826dda220d Mon Sep 17 00:00:00 2001 From: garak Date: Tue, 9 Jan 2024 21:50:22 -0500 Subject: [PATCH] add toggleable button to hide empty map folders --- forms/mainwindow.ui | 75 ++++++++++++++++++++++++++ include/mainwindow.h | 3 ++ include/ui/filterchildrenproxymodel.h | 4 +- resources/icons/folder_eye_closed.ico | Bin 0 -> 4286 bytes resources/icons/folder_eye_open.ico | Bin 0 -> 4286 bytes resources/images.qrc | 2 + src/mainwindow.cpp | 21 ++++++++ src/ui/filterchildrenproxymodel.cpp | 9 ++++ 8 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 resources/icons/folder_eye_closed.ico create mode 100644 resources/icons/folder_eye_open.ico diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui index 7d14043a..244f1b29 100644 --- a/forms/mainwindow.ui +++ b/forms/mainwindow.ui @@ -79,6 +79,31 @@ 3 + + + + <html><head/><body><p>Toggle hide all empty map folders</p></body></html> + + + + + + + :/icons/folder_eye_closed.ico + :/icons/folder_eye_open.ico + + + + QToolButton::InstantPopup + + + true + + + true + + + @@ -214,6 +239,31 @@ 3 + + + + <html><head/><body><p>Toggle hide all empty mapsection folders</p></body></html> + + + + + + + :/icons/folder_eye_closed.ico + :/icons/folder_eye_open.ico + + + + QToolButton::InstantPopup + + + true + + + true + + + @@ -349,6 +399,31 @@ 3 + + + + <html><head/><body><p>Toggle hide all unused layouts</p></body></html> + + + + + + + :/icons/folder_eye_closed.ico + :/icons/folder_eye_open.ico + + + + QToolButton::InstantPopup + + + true + + + true + + + diff --git a/include/mainwindow.h b/include/mainwindow.h index 1e496139..4a5d5777 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -279,10 +279,13 @@ private slots: void on_horizontalSlider_CollisionTransparency_valueChanged(int value); + void on_toolButton_HideShow_Groups_clicked(); void on_toolButton_ExpandAll_Groups_clicked(); void on_toolButton_CollapseAll_Groups_clicked(); + void on_toolButton_HideShow_Areas_clicked(); void on_toolButton_ExpandAll_Areas_clicked(); void on_toolButton_CollapseAll_Areas_clicked(); + void on_toolButton_HideShow_Layouts_clicked(); void on_toolButton_ExpandAll_Layouts_clicked(); void on_toolButton_CollapseAll_Layouts_clicked(); diff --git a/include/ui/filterchildrenproxymodel.h b/include/ui/filterchildrenproxymodel.h index b73cbd62..5853d625 100644 --- a/include/ui/filterchildrenproxymodel.h +++ b/include/ui/filterchildrenproxymodel.h @@ -9,9 +9,11 @@ class FilterChildrenProxyModel : public QSortFilterProxyModel public: explicit FilterChildrenProxyModel(QObject *parent = nullptr); + void toggleHideEmpty() { this->hideEmpty = !this->hideEmpty; } protected: bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const; - +private: + bool hideEmpty = false; }; #endif // FILTERCHILDRENPROXYMODEL_H diff --git a/resources/icons/folder_eye_closed.ico b/resources/icons/folder_eye_closed.ico new file mode 100644 index 0000000000000000000000000000000000000000..354abadb4e6511d9f13ef4a089aa3e29e2380084 GIT binary patch literal 4286 zcmeI0drXs87{=>Vm`3B`B3@^VOEz7Mn`o3xK|nS)H8XBAG0RkxiKr+S5fJNTP9+Kq z5m4i0>gEug%z<}6Wr|!BC>Ki+s8mp#=w#rHwv=bj`J`AXNO4QtA0F~+doJI3-tRrn zIbVxR)`5S62Fb*$EcOkV%tj`Y4IyljITF#{S^*$?#mmbbrY87w_Cg`j@_Qs2T@+L7aLR-Y>OeVYl6FUyE zm-k(hTpl`0St>J?Cu=rTAcz0BnTz_(%m} z^}vn?K=ggf*r>UK$%oV!zP$+jHYqS5Bo}W9LQPrFRN&pnLQIJ($IuN)r>XyT zV+=MEw&h{w(K4(psKt(IU{e(kVga*GRKR}!b&T9q(k8Y$OE97lm)LSl*_U_LsP7b= z3purCCur~s^*2-+5PY+3x~)jUz>o}lo=}BJM{eQMxJpbse6vMFpBN*?ifg(CoxW?- z7wf+DZUY>*<{{>9AiS~x-&Yv0t_=dO+(&2s6X?7C0$l&7!QAr?F#B9BW}U5h%DEc2 zrqses^l?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@X-^O z!iSiBv=*a6%kW7Dqe4m{_$<5>3+dI9T-S2OtDo7ZG1S$bhf+)C{84U?Un4MiM;>-p zx8cCecDR=-u&zP@FCDyDe^oqr&)!>VY`fBg&)xS2Q~!OjcovQRZ}i>wH-P!atKf0* z4pQ&7!|9p=&csE_bp>3B2l0GG+}S^%Mv3G*Dp-eP-lncGF?gb%j}!L+pIS8>F5kth zgXPHJIrIl(aZD3Wtu)dPEkLKJ}cEzSDto^R853L$z8HquH@Cl*@tA$3TgmTxGxO zD!`Iw9<}>v_0Kc^gxB1O$4l@m=e%TU%sVE7MQ}DIynyk+IT#+qb@)Hc-WU!=YhJ>ptMPw9d1vnS(Yf8{>xGh2GZj@R~8v|YzXb*U1WjJYMxc%h|H?E0b6 z&!_&X;x>A?jehRR8rB_n&AzA`M0*dcWPe-wv!o50xKq}stF)%3(J$un$F7h%yvLE_ zJw<4;J&t)(&UKV?tXJVW{aK~%;y2wX7>W3oaoi>OaxBYl!*U&#vYyIk!Z^OeeHkKr zl>bUR@msFeZ@T*Z#Ptg1gqXuMuJJk8F0M}wdzv%4WBil4p>=rfX)y;8hwj$)EN600 zQAp&>zgGBS^5*y7|2qb>fVR|_(^&74zC^sAi8Hb@x^2ANZ4vi~ah}naK_icons/fill_color.ico icons/folder_closed_map.ico icons/folder_closed.ico + icons/folder_eye_closed.ico + icons/folder_eye_open.ico icons/folder_map_edited.ico icons/folder_map_opened.ico icons/folder_map.ico diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 08b18d43..d9e23785 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2821,6 +2821,13 @@ void MainWindow::initTilesetEditor() { connect(this->tilesetEditor, &TilesetEditor::tilesetsSaved, this, &MainWindow::onTilesetsSaved); } +void MainWindow::on_toolButton_HideShow_Groups_clicked() { + if (ui->mapList) { + this->groupListProxyModel->toggleHideEmpty(); + this->groupListProxyModel->setFilterRegularExpression(this->ui->lineEdit_filterBox->text()); + } +} + void MainWindow::on_toolButton_ExpandAll_Groups_clicked() { if (ui->mapList) { ui->mapList->expandToDepth(0); @@ -2833,6 +2840,13 @@ void MainWindow::on_toolButton_CollapseAll_Groups_clicked() { } } +void MainWindow::on_toolButton_HideShow_Areas_clicked() { + if (ui->areaList) { + this->areaListProxyModel->toggleHideEmpty(); + this->areaListProxyModel->setFilterRegularExpression(this->ui->lineEdit_filterBox->text()); + } +} + void MainWindow::on_toolButton_ExpandAll_Areas_clicked() { if (ui->areaList) { ui->areaList->expandToDepth(0); @@ -2845,6 +2859,13 @@ void MainWindow::on_toolButton_CollapseAll_Areas_clicked() { } } +void MainWindow::on_toolButton_HideShow_Layouts_clicked() { + if (ui->layoutList) { + this->layoutListProxyModel->toggleHideEmpty(); + this->layoutListProxyModel->setFilterRegularExpression(this->ui->lineEdit_filterBox->text()); + } +} + void MainWindow::on_toolButton_ExpandAll_Layouts_clicked() { if (ui->layoutList) { ui->layoutList->expandToDepth(0); diff --git a/src/ui/filterchildrenproxymodel.cpp b/src/ui/filterchildrenproxymodel.cpp index a08c150c..99464ae6 100644 --- a/src/ui/filterchildrenproxymodel.cpp +++ b/src/ui/filterchildrenproxymodel.cpp @@ -8,6 +8,15 @@ FilterChildrenProxyModel::FilterChildrenProxyModel(QObject *parent) : bool FilterChildrenProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const { + if (this->hideEmpty && source_parent.row() < 0) // want to hide children + { + QModelIndex source_index = sourceModel()->index(source_row, this->filterKeyColumn(), source_parent) ; + if(source_index.isValid()) + { + if (!sourceModel()->hasChildren(source_index)) + return false; + } + } // custom behaviour : if(filterRegularExpression().pattern().isEmpty() == false) {