@@ -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
8793QString 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+
175203void CategoryFilterWidget::addCategory ()
176204{
177205 TorrentCategoryDialog::createCategory (this );
0 commit comments