Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add buttons to select/check files based on filter #20698

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/gui/properties/propertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,17 @@ PropertiesWidget::PropertiesWidget(QWidget *parent)
m_contentFilterLine->setPlaceholderText(tr("Filter files..."));
m_contentFilterLine->setFixedWidth(300);
connect(m_contentFilterLine, &LineEdit::textChanged, m_ui->filesList, &TorrentContentWidget::setFilterPattern);
m_ui->contentFilterLayout->insertWidget(3, m_contentFilterLine);
m_ui->contentFilterLayout->insertWidget(6, m_contentFilterLine);

m_ui->filesList->setDoubleClickAction(TorrentContentWidget::DoubleClickAction::Open);
m_ui->filesList->setOpenByEnterKey(true);

// SIGNAL/SLOTS
connect(m_ui->selectAllButton, &QPushButton::clicked, m_ui->filesList, &TorrentContentWidget::checkAll);
connect(m_ui->selectNoneButton, &QPushButton::clicked, m_ui->filesList, &TorrentContentWidget::checkNone);
connect(m_ui->selectMatchButton, &QPushButton::clicked, m_ui->filesList, &TorrentContentWidget::selectMatches);
connect(m_ui->checkSelectionButton, &QPushButton::clicked, m_ui->filesList, &TorrentContentWidget::checkSelection);
connect(m_ui->uncheckSelectionButton, &QPushButton::clicked, m_ui->filesList, &TorrentContentWidget::uncheckSelection);
connect(m_ui->listWebSeeds, &QWidget::customContextMenuRequested, this, &PropertiesWidget::displayWebSeedListMenu);
connect(m_ui->stackedProperties, &QStackedWidget::currentChanged, this, &PropertiesWidget::loadDynamicData);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::torrentSavePathChanged, this, &PropertiesWidget::updateSavePath);
Expand Down
21 changes: 21 additions & 0 deletions src/gui/properties/propertieswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,27 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="checkSelectionButton">
<property name="text">
<string>Select Selected</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="uncheckSelectionButton">
<property name="text">
<string>Deselect Selected</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="selectMatchButton">
<property name="text">
<string>Select Matches</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
36 changes: 36 additions & 0 deletions src/gui/torrentcontentwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,42 @@ void TorrentContentWidget::checkNone()
model()->setData(model()->index(i, TorrentContentModelItem::COL_NAME), Qt::Unchecked, Qt::CheckStateRole);
}

void TorrentContentWidget::checkSelection()
{
const QModelIndexList selection = selectionModel()->selectedIndexes();

for (const QModelIndex &index : selection)
model()->setData(index, Qt::Checked, Qt::CheckStateRole);
}

void TorrentContentWidget::uncheckSelection()
{
const QModelIndexList selection = selectionModel()->selectedIndexes();

for (const QModelIndex &index : selection)
model()->setData(index, Qt::Unchecked, Qt::CheckStateRole);
}

void TorrentContentWidget::selectMatches()
{
std::function<void(const QModelIndex &index, const QSortFilterProxyModel *model)> iterModel;
iterModel = [this, &iterModel](const QModelIndex &index, const QSortFilterProxyModel *model)
{
// Select current item if it matches the filter pattern
if (model->data(index).toString().contains(model->filterRegularExpression()))
selectionModel()->select(index, QItemSelectionModel::Select);

// Check current items children
if (!model->hasChildren(index))
return;
for (int i = 0; i < model->rowCount(index); ++i)
iterModel(model->index(i, 0, index), model);
};

// Select all matching items for root item
iterModel(m_filterModel->index(0, 0), m_filterModel);
}

void TorrentContentWidget::keyPressEvent(QKeyEvent *event)
{
if ((event->key() != Qt::Key_Space) && (event->key() != Qt::Key_Select))
Expand Down
3 changes: 3 additions & 0 deletions src/gui/torrentcontentwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ class TorrentContentWidget final : public QTreeView

void checkAll();
void checkNone();
void checkSelection();
void uncheckSelection();
void selectMatches();

signals:
void stateChanged();
Expand Down