From: Amol Godbole Date: Thu, 9 Nov 2023 17:17:33 +0000 (-0600) Subject: DolphinView: Use SingleShot and Queued Connections X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/5a8bd47296e204a68014a60757758c50fa623526 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. --- diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 5f4f0bb9a..939f66157 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -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; } diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 6b77a46ea..ae0aa903c 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -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; - - m_view->editRole(index, "text"); + connect( + m_view, + &KItemListView::scrollingStopped, + this, + [this, index]() { + 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 {