1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00

DolphinView: Use SingleShot and Queued Connections

A minor refactor where Qt::SingleShotConnection has been utilized.
Also, signal delay using QTimer has been replaced with a
Qt::QueuedConnection.
This commit is contained in:
Amol Godbole 2023-11-09 11:17:33 -06:00 committed by Méven Car
parent c035e95e1d
commit 5a8bd47296
2 changed files with 13 additions and 16 deletions

View File

@ -1196,12 +1196,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items)
for (const KFileItem &item : items) {
if (item.url() == currentDir) {
// #473377: Delay emitting currentDirectoryRemoved() to avoid modifying KCoreDirLister
// before KCoreDirListerCache::deleteDir() returns.
QTimer::singleShot(0, this, [this] {
Q_EMIT currentDirectoryRemoved();
});
Q_EMIT currentDirectoryRemoved();
return;
}

View File

@ -200,7 +200,8 @@ DolphinView::DolphinView(const QUrl &url, QWidget *parent)
connect(m_model, &KFileItemModel::directoryRedirection, this, &DolphinView::slotDirectoryRedirection);
connect(m_model, &KFileItemModel::urlIsFileError, this, &DolphinView::urlIsFileError);
connect(m_model, &KFileItemModel::fileItemsChanged, this, &DolphinView::fileItemsChanged);
connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved);
// #473377: Use a QueuedConnection to avoid modifying KCoreDirLister before KCoreDirListerCache::deleteDir() returns.
connect(m_model, &KFileItemModel::currentDirectoryRemoved, this, &DolphinView::currentDirectoryRemoved, Qt::QueuedConnection);
connect(this, &DolphinView::itemCountChanged, this, &DolphinView::updatePlaceholderLabel);
@ -740,17 +741,18 @@ void DolphinView::renameSelectedItems()
if (items.count() == 1 && GeneralSettings::renameInline()) {
const int index = m_model->index(items.first());
QMetaObject::Connection *const connection = new QMetaObject::Connection;
*connection = connect(m_view, &KItemListView::scrollingStopped, this, [=]() {
QObject::disconnect(*connection);
delete connection;
connect(
m_view,
&KItemListView::scrollingStopped,
this,
[this, index]() {
m_view->editRole(index, "text");
m_view->editRole(index, "text");
hideToolTip();
hideToolTip();
connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished);
});
connect(m_view, &DolphinItemListView::roleEditingFinished, this, &DolphinView::slotRoleEditingFinished);
},
Qt::SingleShotConnection);
m_view->scrollToItem(index);
} else {