mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 07:27:22 -06:00
Avoid creating unnecessary event loops
This is part 2.
This commit is contained in:
@@ -405,39 +405,44 @@ void SearchJobWidget::saveSettings() const
|
||||
Preferences::instance()->setSearchTabHeaderState(header()->saveState());
|
||||
}
|
||||
|
||||
void SearchJobWidget::displayToggleColumnsMenu(const QPoint&)
|
||||
void SearchJobWidget::displayToggleColumnsMenu(const QPoint &)
|
||||
{
|
||||
QMenu hideshowColumn(this);
|
||||
hideshowColumn.setTitle(tr("Column visibility"));
|
||||
QList<QAction*> actions;
|
||||
auto menu = new QMenu(this);
|
||||
menu->setAttribute(Qt::WA_DeleteOnClose);
|
||||
menu->setTitle(tr("Column visibility"));
|
||||
|
||||
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) {
|
||||
QAction *myAct = hideshowColumn.addAction(m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
QAction *myAct = menu->addAction(m_searchListModel->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString());
|
||||
myAct->setCheckable(true);
|
||||
myAct->setChecked(!m_ui->resultsBrowser->isColumnHidden(i));
|
||||
actions.append(myAct);
|
||||
}
|
||||
int visibleCols = 0;
|
||||
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) {
|
||||
if (!m_ui->resultsBrowser->isColumnHidden(i))
|
||||
++visibleCols;
|
||||
|
||||
if (visibleCols > 1)
|
||||
break;
|
||||
myAct->setData(i);
|
||||
}
|
||||
|
||||
// Call menu
|
||||
QAction *act = hideshowColumn.exec(QCursor::pos());
|
||||
if (act) {
|
||||
int col = actions.indexOf(act);
|
||||
Q_ASSERT(col >= 0);
|
||||
Q_ASSERT(visibleCols > 0);
|
||||
connect(menu, &QMenu::triggered, this, [this](const QAction *action)
|
||||
{
|
||||
int visibleCols = 0;
|
||||
for (int i = 0; i < SearchSortModel::DL_LINK; ++i) {
|
||||
if (!m_ui->resultsBrowser->isColumnHidden(i))
|
||||
++visibleCols;
|
||||
|
||||
if (visibleCols > 1)
|
||||
break;
|
||||
}
|
||||
|
||||
const int col = action->data().toInt();
|
||||
|
||||
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (visibleCols == 1))
|
||||
return;
|
||||
|
||||
m_ui->resultsBrowser->setColumnHidden(col, !m_ui->resultsBrowser->isColumnHidden(col));
|
||||
|
||||
if ((!m_ui->resultsBrowser->isColumnHidden(col)) && (m_ui->resultsBrowser->columnWidth(col) <= 5))
|
||||
m_ui->resultsBrowser->resizeColumnToContents(col);
|
||||
|
||||
saveSettings();
|
||||
}
|
||||
});
|
||||
|
||||
menu->popup(QCursor::pos());
|
||||
}
|
||||
|
||||
void SearchJobWidget::searchFinished(bool cancelled)
|
||||
|
||||
@@ -99,7 +99,7 @@ private:
|
||||
void updateFilter();
|
||||
void filterSearchResults(const QString &name);
|
||||
void showFilterContextMenu(const QPoint &);
|
||||
void displayToggleColumnsMenu(const QPoint&);
|
||||
void displayToggleColumnsMenu(const QPoint &);
|
||||
void onItemDoubleClicked(const QModelIndex &index);
|
||||
void searchFinished(bool cancelled);
|
||||
void searchFailed();
|
||||
|
||||
Reference in New Issue
Block a user