QSidebar: Use pmf-style connects
Port all string-based signal/slots connections to pmf-style connects. Change-Id: I4ebabf1b117f86f39d3875965efa8ee5042bce84 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit b71aa162c00ff180cc946b8fd6c9c670d04ec262) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
144fcb8e79
commit
a91c2b8c71
@ -43,6 +43,12 @@ QUrlModel::QUrlModel(QObject *parent) : QStandardItemModel(parent), showFullPath
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QUrlModel::~QUrlModel()
|
||||||
|
{
|
||||||
|
for (const auto &conn : std::as_const(modelConnections))
|
||||||
|
disconnect(conn);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@ -266,21 +272,19 @@ void QUrlModel::setFileSystemModel(QFileSystemModel *model)
|
|||||||
if (model == fileSystemModel)
|
if (model == fileSystemModel)
|
||||||
return;
|
return;
|
||||||
if (fileSystemModel != nullptr) {
|
if (fileSystemModel != nullptr) {
|
||||||
disconnect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
for (const auto &conn : std::as_const(modelConnections))
|
||||||
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
disconnect(conn);
|
||||||
disconnect(model, SIGNAL(layoutChanged()),
|
|
||||||
this, SLOT(layoutChanged()));
|
|
||||||
disconnect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
|
||||||
this, SLOT(layoutChanged()));
|
|
||||||
}
|
}
|
||||||
fileSystemModel = model;
|
fileSystemModel = model;
|
||||||
if (fileSystemModel != nullptr) {
|
if (fileSystemModel != nullptr) {
|
||||||
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
|
modelConnections = {
|
||||||
this, SLOT(dataChanged(QModelIndex,QModelIndex)));
|
connect(model, &QFileSystemModel::dataChanged,
|
||||||
connect(model, SIGNAL(layoutChanged()),
|
this, &QUrlModel::dataChanged),
|
||||||
this, SLOT(layoutChanged()));
|
connect(model, &QFileSystemModel::layoutChanged,
|
||||||
connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
|
this, &QUrlModel::layoutChanged),
|
||||||
this, SLOT(layoutChanged()));
|
connect(model, &QFileSystemModel::rowsRemoved,
|
||||||
|
this, &QUrlModel::layoutChanged),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
clear();
|
clear();
|
||||||
insertColumns(0, 1);
|
insertColumns(0, 1);
|
||||||
@ -352,14 +356,14 @@ void QSidebar::setModelAndUrls(QFileSystemModel *model, const QList<QUrl> &newUr
|
|||||||
setModel(urlModel);
|
setModel(urlModel);
|
||||||
setItemDelegate(new QSideBarDelegate(this));
|
setItemDelegate(new QSideBarDelegate(this));
|
||||||
|
|
||||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
connect(selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
this, SLOT(clicked(QModelIndex)));
|
this, &QSidebar::clicked);
|
||||||
#if QT_CONFIG(draganddrop)
|
#if QT_CONFIG(draganddrop)
|
||||||
setDragDropMode(QAbstractItemView::DragDrop);
|
setDragDropMode(QAbstractItemView::DragDrop);
|
||||||
#endif
|
#endif
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)),
|
connect(this, &QSidebar::customContextMenuRequested,
|
||||||
this, SLOT(showContextMenu(QPoint)));
|
this, &QSidebar::showContextMenu);
|
||||||
urlModel->setUrls(newUrls);
|
urlModel->setUrls(newUrls);
|
||||||
setCurrentIndex(this->model()->index(0,0));
|
setCurrentIndex(this->model()->index(0,0));
|
||||||
}
|
}
|
||||||
@ -385,8 +389,8 @@ QSize QSidebar::sizeHint() const
|
|||||||
|
|
||||||
void QSidebar::selectUrl(const QUrl &url)
|
void QSidebar::selectUrl(const QUrl &url)
|
||||||
{
|
{
|
||||||
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
disconnect(selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
this, SLOT(clicked(QModelIndex)));
|
this, &QSidebar::clicked);
|
||||||
|
|
||||||
selectionModel()->clear();
|
selectionModel()->clear();
|
||||||
for (int i = 0; i < model()->rowCount(); ++i) {
|
for (int i = 0; i < model()->rowCount(); ++i) {
|
||||||
@ -396,8 +400,8 @@ void QSidebar::selectUrl(const QUrl &url)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
connect(selectionModel(), &QItemSelectionModel::currentChanged,
|
||||||
this, SLOT(clicked(QModelIndex)));
|
this, &QSidebar::clicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if QT_CONFIG(menu)
|
#if QT_CONFIG(menu)
|
||||||
@ -413,7 +417,7 @@ void QSidebar::showContextMenu(const QPoint &position)
|
|||||||
QAction *action = new QAction(QFileDialog::tr("Remove"), this);
|
QAction *action = new QAction(QFileDialog::tr("Remove"), this);
|
||||||
if (indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty())
|
if (indexAt(position).data(QUrlModel::UrlRole).toUrl().path().isEmpty())
|
||||||
action->setEnabled(false);
|
action->setEnabled(false);
|
||||||
connect(action, SIGNAL(triggered()), this, SLOT(removeEntry()));
|
connect(action, &QAction::triggered, this, &QSidebar::removeEntry);
|
||||||
actions.append(action);
|
actions.append(action);
|
||||||
}
|
}
|
||||||
if (actions.size() > 0)
|
if (actions.size() > 0)
|
||||||
|
@ -47,6 +47,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
QUrlModel(QObject *parent = nullptr);
|
QUrlModel(QObject *parent = nullptr);
|
||||||
|
~QUrlModel();
|
||||||
|
|
||||||
QStringList mimeTypes() const override;
|
QStringList mimeTypes() const override;
|
||||||
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||||
@ -80,6 +81,7 @@ private:
|
|||||||
|
|
||||||
QList<WatchItem> watching;
|
QList<WatchItem> watching;
|
||||||
QList<QUrl> invalidUrls;
|
QList<QUrl> invalidUrls;
|
||||||
|
std::array<QMetaObject::Connection, 3> modelConnections;
|
||||||
};
|
};
|
||||||
Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE);
|
Q_DECLARE_TYPEINFO(QUrlModel::WatchItem, Q_RELOCATABLE_TYPE);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user