Skip to content

Commit bda726c

Browse files
committed
Remove indentation if no subcategory exists
1 parent 93470f2 commit bda726c

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/gui/transferlistfilters/categoryfilterwidget.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,13 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent)
8181
connect(this, &QWidget::customContextMenuRequested, this, &CategoryFilterWidget::showMenu);
8282
connect(selectionModel(), &QItemSelectionModel::currentRowChanged
8383
, this, &CategoryFilterWidget::onCurrentRowChanged);
84-
connect(model(), &QAbstractItemModel::modelReset, this, &CategoryFilterWidget::callUpdateGeometry);
84+
connect(model(), &QAbstractItemModel::rowsInserted, this, [this](const QModelIndex &parent)
85+
{
86+
if (parent.isValid())
87+
adjustIndentation();
88+
});
89+
connect(model(), &QAbstractItemModel::rowsRemoved, this, &CategoryFilterWidget::adjustIndentation);
90+
connect(model(), &QAbstractItemModel::modelReset, this, &CategoryFilterWidget::adjustIndentation);
8591
}
8692

8793
QString CategoryFilterWidget::currentCategory() const
@@ -156,7 +162,7 @@ QSize CategoryFilterWidget::minimumSizeHint() const
156162
return size;
157163
}
158164

159-
void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, int start, int end)
165+
void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, const int start, const int end)
160166
{
161167
QTreeView::rowsInserted(parent, start, end);
162168

@@ -172,6 +178,28 @@ void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, int start, in
172178
updateGeometry();
173179
}
174180

181+
bool CategoryFilterWidget::hasAnySubcategory() const
182+
{
183+
const int rowCount = model()->rowCount();
184+
for (int row = 0; row < rowCount; ++row)
185+
{
186+
if (model()->hasChildren(model()->index(row, 0)))
187+
return true;
188+
}
189+
190+
return false;
191+
}
192+
193+
void CategoryFilterWidget::adjustIndentation()
194+
{
195+
if (hasAnySubcategory())
196+
resetIndentation();
197+
else
198+
setIndentation(0);
199+
200+
updateGeometry();
201+
}
202+
175203
void CategoryFilterWidget::addCategory()
176204
{
177205
TorrentCategoryDialog::createCategory(this);

src/gui/transferlistfilters/categoryfilterwidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,6 @@ private slots:
6060
QSize sizeHint() const override;
6161
QSize minimumSizeHint() const override;
6262
void rowsInserted(const QModelIndex &parent, int start, int end) override;
63+
bool hasAnySubcategory() const;
64+
void adjustIndentation();
6365
};

0 commit comments

Comments
 (0)