From b71aa162c00ff180cc946b8fd6c9c670d04ec262 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 22 Dec 2023 13:28:54 +0100 Subject: QSidebar: Use pmf-style connects Port all string-based signal/slots connections to pmf-style connects. Pick-to: 6.7 Change-Id: I4ebabf1b117f86f39d3875965efa8ee5042bce84 Reviewed-by: Axel Spoerl --- src/widgets/dialogs/qsidebar.cpp | 46 ++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src/widgets/dialogs/qsidebar.cpp') diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 75e43a2bed..9f6b329a6f 100644 --- a/src/widgets/dialogs/qsidebar.cpp +++ b/src/widgets/dialogs/qsidebar.cpp @@ -43,6 +43,12 @@ QUrlModel::QUrlModel(QObject *parent) : QStandardItemModel(parent), showFullPath { } +QUrlModel::~QUrlModel() +{ + for (const auto &conn : std::as_const(modelConnections)) + disconnect(conn); +} + /*! \reimp */ @@ -266,21 +272,19 @@ void QUrlModel::setFileSystemModel(QFileSystemModel *model) if (model == fileSystemModel) return; if (fileSystemModel != nullptr) { - disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(dataChanged(QModelIndex,QModelIndex))); - disconnect(model, SIGNAL(layoutChanged()), - this, SLOT(layoutChanged())); - disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(layoutChanged())); + for (const auto &conn : std::as_const(modelConnections)) + disconnect(conn); } fileSystemModel = model; if (fileSystemModel != nullptr) { - connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(dataChanged(QModelIndex,QModelIndex))); - connect(model, SIGNAL(layoutChanged()), - this, SLOT(layoutChanged())); - connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)), - this, SLOT(layoutChanged())); + modelConnections = { + connect(model, &QFileSystemModel::dataChanged, + this, &QUrlModel::dataChanged), + connect(model, &QFileSystemModel::layoutChanged, + this, &QUrlModel::layoutChanged), + connect(model, &QFileSystemModel::rowsRemoved, + this, &QUrlModel::layoutChanged), + }; } clear(); insertColumns(0, 1); @@ -352,14 +356,14 @@ void QSidebar::setModelAndUrls(QFileSystemModel *model, const QList &newUr setModel(urlModel); setItemDelegate(new QSideBarDelegate(this)); - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(clicked(QModelIndex))); + connect(selectionModel(), &QItemSelectionModel::currentChanged, + this, &QSidebar::clicked); #if QT_CONFIG(draganddrop) setDragDropMode(QAbstractItemView::DragDrop); #endif setContextMenuPolicy(Qt::CustomContextMenu); - connect(this, SIGNAL(customContextMenuRequested(QPoint)), - this, SLOT(showContextMenu(QPoint))); + connect(this, &QSidebar::customContextMenuRequested, + this, &QSidebar::showContextMenu); urlModel->setUrls(newUrls); setCurrentIndex(this->model()->index(0,0)); } @@ -385,8 +389,8 @@ QSize QSidebar::sizeHint() const void QSidebar::selectUrl(const QUrl &url) { - disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(clicked(QModelIndex))); + disconnect(selectionModel(), &QItemSelectionModel::currentChanged, + this, &QSidebar::clicked); selectionModel()->clear(); for (int i = 0; i < model()->rowCount(); ++i) { @@ -396,8 +400,8 @@ void QSidebar::selectUrl(const QUrl &url) } } - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(clicked(QModelIndex))); + connect(selectionModel(), &QItemSelectionModel::currentChanged, + this, &QSidebar::clicked); } #if QT_CONFIG(menu) @@ -413,7 +417,7 @@ void QSidebar::showContextMenu(const QPoint &position) QAction *action = new QAction(QFileDialog::tr("Remove"), this); if (indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty()) action->setEnabled(false); - connect(action, SIGNAL(triggered()), this, SLOT(removeEntry())); + connect(action, &QAction::triggered, this, &QSidebar::removeEntry); actions.append(action); } if (actions.size() > 0) -- cgit v1.2.3