diff --git a/src/widgets/dialogs/qsidebar.cpp b/src/widgets/dialogs/qsidebar.cpp index 75e43a2bed2..9f6b329a6f6 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) diff --git a/src/widgets/dialogs/qsidebar_p.h b/src/widgets/dialogs/qsidebar_p.h index 74805e4f2d0..ed17a2ff311 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 watching; QList invalidUrls; + std::array modelConnections; }; Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE);