diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2023-12-22 13:28:54 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2024-01-10 03:11:52 +0000 |
commit | b71aa162c00ff180cc946b8fd6c9c670d04ec262 (patch) | |
tree | f051dc8900f48badec040df9bad5fae3c2f47c6b | |
parent | 4fdcb1212d1a67d2e4b5aed28095e22e609d530a (diff) |
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 <axel.spoerl@qt.io>
-rw-r--r-- | src/widgets/dialogs/qsidebar.cpp | 46 | ||||
-rw-r--r-- | src/widgets/dialogs/qsidebar_p.h | 2 |
2 files changed, 27 insertions, 21 deletions
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<QUrl> &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) diff --git a/src/widgets/dialogs/qsidebar_p.h b/src/widgets/dialogs/qsidebar_p.h index 74805e4f2d..ed17a2ff31 100644 --- a/src/widgets/dialogs/qsidebar_p.h +++ b/src/widgets/dialogs/qsidebar_p.h @@ -47,6 +47,7 @@ public: }; QUrlModel(QObject *parent = nullptr); + ~QUrlModel(); QStringList mimeTypes() const override; QMimeData *mimeData(const QModelIndexList &indexes) const override; @@ -80,6 +81,7 @@ private: QList<WatchItem> watching; QList<QUrl> invalidUrls; + std::array<QMetaObject::Connection, 3> modelConnections; }; Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE); |