From 8c58a69be67883d1403305912c024bc51df3c9cb Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 1 Sep 2017 19:36:53 +0300 Subject: [PATCH] Use Qt5 connect() style in CategoryFilterWidget --- src/gui/categoryfilterwidget.cpp | 29 ++++++++++++++++------------- src/gui/categoryfilterwidget.h | 1 + 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/gui/categoryfilterwidget.cpp b/src/gui/categoryfilterwidget.cpp index 0bdc5ac67..abec735cc 100644 --- a/src/gui/categoryfilterwidget.cpp +++ b/src/gui/categoryfilterwidget.cpp @@ -81,12 +81,12 @@ CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) sortByColumn(0, Qt::AscendingOrder); setCurrentIndex(model()->index(0, 0)); - connect(this, SIGNAL(collapsed(QModelIndex)), SLOT(callUpdateGeometry())); - connect(this, SIGNAL(expanded(QModelIndex)), SLOT(callUpdateGeometry())); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint))); - connect(selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)) - , SLOT(onCurrentRowChanged(QModelIndex,QModelIndex))); - connect(model(), SIGNAL(modelReset()), SLOT(callUpdateGeometry())); + connect(this, &QTreeView::collapsed, this, &CategoryFilterWidget::callUpdateGeometry); + connect(this, &QTreeView::expanded, this, &CategoryFilterWidget::callUpdateGeometry); + connect(this, &QWidget::customContextMenuRequested, this, &CategoryFilterWidget::showMenu); + connect(selectionModel(), &QItemSelectionModel::currentRowChanged + , this, &CategoryFilterWidget::onCurrentRowChanged); + connect(model(), &QAbstractItemModel::modelReset, this, &CategoryFilterWidget::callUpdateGeometry); } QString CategoryFilterWidget::currentCategory() const @@ -113,7 +113,7 @@ void CategoryFilterWidget::showMenu(QPoint) QAction *addAct = menu.addAction( GuiIconProvider::instance()->getIcon("list-add") , tr("Add category...")); - connect(addAct, SIGNAL(triggered()), SLOT(addCategory())); + connect(addAct, &QAction::triggered, this, &CategoryFilterWidget::addCategory); auto selectedRows = selectionModel()->selectedRows(); if (!selectedRows.empty() && !CategoryFilterModel::isSpecialItem(selectedRows.first())) { @@ -121,36 +121,36 @@ void CategoryFilterWidget::showMenu(QPoint) QAction *addSubAct = menu.addAction( GuiIconProvider::instance()->getIcon("list-add") , tr("Add subcategory...")); - connect(addSubAct, SIGNAL(triggered()), SLOT(addSubcategory())); + connect(addSubAct, &QAction::triggered, this, &CategoryFilterWidget::addSubcategory); } QAction *removeAct = menu.addAction( GuiIconProvider::instance()->getIcon("list-remove") , tr("Remove category")); - connect(removeAct, SIGNAL(triggered()), SLOT(removeCategory())); + connect(removeAct, &QAction::triggered, this, &CategoryFilterWidget::removeCategory); } QAction *removeUnusedAct = menu.addAction( GuiIconProvider::instance()->getIcon("list-remove") , tr("Remove unused categories")); - connect(removeUnusedAct, SIGNAL(triggered()), SLOT(removeUnusedCategories())); + connect(removeUnusedAct, &QAction::triggered, this, &CategoryFilterWidget::removeUnusedCategories); menu.addSeparator(); QAction *startAct = menu.addAction( GuiIconProvider::instance()->getIcon("media-playback-start") , tr("Resume torrents")); - connect(startAct, SIGNAL(triggered()), SIGNAL(actionResumeTorrentsTriggered())); + connect(startAct, &QAction::triggered, this, &CategoryFilterWidget::actionResumeTorrentsTriggered); QAction *pauseAct = menu.addAction( GuiIconProvider::instance()->getIcon("media-playback-pause") , tr("Pause torrents")); - connect(pauseAct, SIGNAL(triggered()), SIGNAL(actionPauseTorrentsTriggered())); + connect(pauseAct, &QAction::triggered, this, &CategoryFilterWidget::actionPauseTorrentsTriggered); QAction *deleteTorrentsAct = menu.addAction( GuiIconProvider::instance()->getIcon("edit-delete") , tr("Delete torrents")); - connect(deleteTorrentsAct, SIGNAL(triggered()), SIGNAL(actionDeleteTorrentsTriggered())); + connect(deleteTorrentsAct, &QAction::triggered, this, &CategoryFilterWidget::actionDeleteTorrentsTriggered); menu.exec(QCursor::pos()); } @@ -167,6 +167,9 @@ void CategoryFilterWidget::callUpdateGeometry() QSize CategoryFilterWidget::sizeHint() const { + // The sizeHint must depend on viewportSizeHint, + // otherwise widget will not correctly adjust the + // size when subcategories are used. const QSize viewportSize {viewportSizeHint()}; return { viewportSize.width(), diff --git a/src/gui/categoryfilterwidget.h b/src/gui/categoryfilterwidget.h index 528a3c827..c03477895 100644 --- a/src/gui/categoryfilterwidget.h +++ b/src/gui/categoryfilterwidget.h @@ -31,6 +31,7 @@ class CategoryFilterWidget: public QTreeView { Q_OBJECT + Q_DISABLE_COPY(CategoryFilterWidget) public: explicit CategoryFilterWidget(QWidget *parent = nullptr);