mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-22 08:27:24 -06:00
committed by
GitHub
parent
b5d16dfeee
commit
25224f6050
@@ -81,7 +81,18 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent)
|
||||
connect(this, &QWidget::customContextMenuRequested, this, &CategoryFilterWidget::showMenu);
|
||||
connect(selectionModel(), &QItemSelectionModel::currentRowChanged
|
||||
, this, &CategoryFilterWidget::onCurrentRowChanged);
|
||||
connect(model(), &QAbstractItemModel::modelReset, this, &CategoryFilterWidget::callUpdateGeometry);
|
||||
connect(model(), &QAbstractItemModel::rowsRemoved, this, [this]
|
||||
{
|
||||
adjustIndentation();
|
||||
updateGeometry();
|
||||
});
|
||||
connect(model(), &QAbstractItemModel::modelReset, this, [this]
|
||||
{
|
||||
adjustIndentation();
|
||||
updateGeometry();
|
||||
});
|
||||
|
||||
adjustIndentation();
|
||||
}
|
||||
|
||||
QString CategoryFilterWidget::currentCategory() const
|
||||
@@ -156,10 +167,13 @@ QSize CategoryFilterWidget::minimumSizeHint() const
|
||||
return size;
|
||||
}
|
||||
|
||||
void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, int start, int end)
|
||||
void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, const int start, const int end)
|
||||
{
|
||||
QTreeView::rowsInserted(parent, start, end);
|
||||
|
||||
if (parent.isValid())
|
||||
adjustIndentation();
|
||||
|
||||
// Expand all parents if the parent(s) of the node are not expanded.
|
||||
QModelIndex p = parent;
|
||||
while (p.isValid())
|
||||
@@ -172,6 +186,26 @@ void CategoryFilterWidget::rowsInserted(const QModelIndex &parent, int start, in
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
bool CategoryFilterWidget::hasAnySubcategory() const
|
||||
{
|
||||
const int rowCount = model()->rowCount();
|
||||
for (int row = 0; row < rowCount; ++row)
|
||||
{
|
||||
if (model()->hasChildren(model()->index(row, 0)))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CategoryFilterWidget::adjustIndentation()
|
||||
{
|
||||
if (hasAnySubcategory())
|
||||
resetIndentation();
|
||||
else
|
||||
setIndentation(0);
|
||||
}
|
||||
|
||||
void CategoryFilterWidget::addCategory()
|
||||
{
|
||||
TorrentCategoryDialog::createCategory(this);
|
||||
|
||||
@@ -60,4 +60,6 @@ private:
|
||||
QSize sizeHint() const override;
|
||||
QSize minimumSizeHint() const override;
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
||||
bool hasAnySubcategory() const;
|
||||
void adjustIndentation();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user