Browse Source

Avoid allocating a new menu/action manually

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
412e326cf2
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 5
      src/gui/addnewtorrentdialog.cpp
  2. 20
      src/gui/mainwindow.cpp
  3. 6
      src/gui/properties/propertieswidget.cpp
  4. 4
      src/gui/search/searchjobwidget.cpp

5
src/gui/addnewtorrentdialog.cpp

@ -478,8 +478,7 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
menu->addSeparator(); menu->addSeparator();
} }
QMenu *subMenu = new QMenu(menu); QMenu *subMenu = menu->addMenu(tr("Priority"));
subMenu->setTitle(tr("Priority"));
connect(m_ui->actionNotDownloaded, &QAction::triggered, subMenu, [applyPriorities]() connect(m_ui->actionNotDownloaded, &QAction::triggered, subMenu, [applyPriorities]()
{ {
@ -505,8 +504,6 @@ void AddNewTorrentDialog::displayContentTreeMenu(const QPoint &)
}); });
subMenu->addAction(m_ui->actionMaximum); subMenu->addAction(m_ui->actionMaximum);
menu->addMenu(subMenu);
menu->popup(QCursor::pos()); menu->popup(QCursor::pos());
} }

20
src/gui/mainwindow.cpp

@ -528,21 +528,17 @@ void MainWindow::addToolbarContextMenu()
m_ui->toolBar->setContextMenuPolicy(Qt::CustomContextMenu); m_ui->toolBar->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->toolBar, &QWidget::customContextMenuRequested, this, &MainWindow::toolbarMenuRequested); connect(m_ui->toolBar, &QWidget::customContextMenuRequested, this, &MainWindow::toolbarMenuRequested);
QAction *iconsOnly = new QAction(tr("Icons Only"), m_toolbarMenu); QAction *iconsOnly = m_toolbarMenu->addAction(tr("Icons Only"));
connect(iconsOnly, &QAction::triggered, this, &MainWindow::toolbarIconsOnly); connect(iconsOnly, &QAction::triggered, this, &MainWindow::toolbarIconsOnly);
QAction *textOnly = new QAction(tr("Text Only"), m_toolbarMenu); QAction *textOnly = m_toolbarMenu->addAction(tr("Text Only"));
connect(textOnly, &QAction::triggered, this, &MainWindow::toolbarTextOnly); connect(textOnly, &QAction::triggered, this, &MainWindow::toolbarTextOnly);
QAction *textBesideIcons = new QAction(tr("Text Alongside Icons"), m_toolbarMenu); QAction *textBesideIcons = m_toolbarMenu->addAction(tr("Text Alongside Icons"));
connect(textBesideIcons, &QAction::triggered, this, &MainWindow::toolbarTextBeside); connect(textBesideIcons, &QAction::triggered, this, &MainWindow::toolbarTextBeside);
QAction *textUnderIcons = new QAction(tr("Text Under Icons"), m_toolbarMenu); QAction *textUnderIcons = m_toolbarMenu->addAction(tr("Text Under Icons"));
connect(textUnderIcons, &QAction::triggered, this, &MainWindow::toolbarTextUnder); connect(textUnderIcons, &QAction::triggered, this, &MainWindow::toolbarTextUnder);
QAction *followSystemStyle = new QAction(tr("Follow System Style"), m_toolbarMenu); QAction *followSystemStyle = m_toolbarMenu->addAction(tr("Follow System Style"));
connect(followSystemStyle, &QAction::triggered, this, &MainWindow::toolbarFollowSystem); connect(followSystemStyle, &QAction::triggered, this, &MainWindow::toolbarFollowSystem);
m_toolbarMenu->addAction(iconsOnly);
m_toolbarMenu->addAction(textOnly);
m_toolbarMenu->addAction(textBesideIcons);
m_toolbarMenu->addAction(textUnderIcons);
m_toolbarMenu->addAction(followSystemStyle);
auto *textPositionGroup = new QActionGroup(m_toolbarMenu); auto *textPositionGroup = new QActionGroup(m_toolbarMenu);
textPositionGroup->addAction(iconsOnly); textPositionGroup->addAction(iconsOnly);
iconsOnly->setCheckable(true); iconsOnly->setCheckable(true);
@ -693,11 +689,9 @@ void MainWindow::showFilterContextMenu(const QPoint &)
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addSeparator(); menu->addSeparator();
QAction *useRegexAct = new QAction(tr("Use regular expressions"), menu); QAction *useRegexAct = menu->addAction(tr("Use regular expressions"));
useRegexAct->setCheckable(true); useRegexAct->setCheckable(true);
useRegexAct->setChecked(pref->getRegexAsFilteringPatternForTransferList()); useRegexAct->setChecked(pref->getRegexAsFilteringPatternForTransferList());
menu->addAction(useRegexAct);
connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForTransferList); connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForTransferList);
connect(useRegexAct, &QAction::toggled, this, [this]() { m_transferListWidget->applyNameFilter(m_searchFilter->text()); }); connect(useRegexAct, &QAction::toggled, this, [this]() { m_transferListWidget->applyNameFilter(m_searchFilter->text()); });

6
src/gui/properties/propertieswidget.cpp

@ -600,10 +600,8 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
menu->addSeparator(); menu->addSeparator();
} }
QMenu *subMenu = new QMenu(menu);
if (!m_torrent->isSeed()) { if (!m_torrent->isSeed()) {
subMenu->setTitle(tr("Priority")); QMenu *subMenu = menu->addMenu(tr("Priority"));
const auto applyPriorities = [this, selectedRows](const BitTorrent::DownloadPriority prio) const auto applyPriorities = [this, selectedRows](const BitTorrent::DownloadPriority prio)
{ {
@ -639,8 +637,6 @@ void PropertiesWidget::displayFilesListMenu(const QPoint &)
applyPriorities(BitTorrent::DownloadPriority::Maximum); applyPriorities(BitTorrent::DownloadPriority::Maximum);
}); });
subMenu->addAction(m_ui->actionMaximum); subMenu->addAction(m_ui->actionMaximum);
menu->addMenu(subMenu);
} }
// The selected torrent might have disappeared during exec() // The selected torrent might have disappeared during exec()

4
src/gui/search/searchjobwidget.cpp

@ -361,11 +361,9 @@ void SearchJobWidget::showFilterContextMenu(const QPoint &)
menu->setAttribute(Qt::WA_DeleteOnClose); menu->setAttribute(Qt::WA_DeleteOnClose);
menu->addSeparator(); menu->addSeparator();
QAction *useRegexAct = new QAction(tr("Use regular expressions"), menu); QAction *useRegexAct = menu->addAction(tr("Use regular expressions"));
useRegexAct->setCheckable(true); useRegexAct->setCheckable(true);
useRegexAct->setChecked(pref->getRegexAsFilteringPatternForSearchJob()); useRegexAct->setChecked(pref->getRegexAsFilteringPatternForSearchJob());
menu->addAction(useRegexAct);
connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForSearchJob); connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForSearchJob);
connect(useRegexAct, &QAction::toggled, this, [this]() { filterSearchResults(m_lineEditSearchResultsFilter->text()); }); connect(useRegexAct, &QAction::toggled, this, [this]() { filterSearchResults(m_lineEditSearchResultsFilter->text()); });

Loading…
Cancel
Save