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>bb10
parent
4fdcb1212d
commit
b71aa162c0
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue