add toggleable button to hide empty map folders

This commit is contained in:
garak 2024-01-09 21:50:22 -05:00
parent c0f32c6a17
commit cd5b1f98d2
8 changed files with 113 additions and 1 deletions

View file

@ -79,6 +79,31 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_HideShow_Groups">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Toggle hide all empty 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/folder_eye_closed.ico</normaloff>
<normalon>:/icons/folder_eye_open.ico</normalon>
</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Groups">
<property name="toolTip">
@ -214,6 +239,31 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_HideShow_Areas">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Toggle hide all empty mapsection 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/folder_eye_closed.ico</normaloff>
<normalon>:/icons/folder_eye_open.ico</normalon>
</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Areas">
<property name="toolTip">
@ -349,6 +399,31 @@
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QToolButton" name="toolButton_HideShow_Layouts">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Toggle hide all unused layouts&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/folder_eye_closed.ico</normaloff>
<normalon>:/icons/folder_eye_open.ico</normalon>
</iconset>
</property>
<property name="popupMode">
<enum>QToolButton::InstantPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_ExpandAll_Layouts">
<property name="toolTip">

View file

@ -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();

View file

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -12,6 +12,8 @@
<file>icons/fill_color.ico</file>
<file>icons/folder_closed_map.ico</file>
<file>icons/folder_closed.ico</file>
<file>icons/folder_eye_closed.ico</file>
<file>icons/folder_eye_open.ico</file>
<file>icons/folder_map_edited.ico</file>
<file>icons/folder_map_opened.ico</file>
<file>icons/folder_map.ico</file>

View file

@ -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);

View file

@ -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)
{