X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/cd2e64154fd5446a7e19aff4cb147efe2f2ba31e..bcccdc60df12b565f3dd142e4471dbe4329cafde:/src/kitemviews/kfileitemmodel.cpp diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 28e0876b9..4463b37ae 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -25,7 +26,6 @@ #include #include #include -#include #include Q_GLOBAL_STATIC(QRecursiveMutex, s_collatorMutex) @@ -99,7 +99,7 @@ KFileItemModel::KFileItemModel(QObject *parent) // for a lot of items within a quite small timeslot. To prevent expensive resortings the // resorting is postponed until the timer has been exceeded. m_resortAllItemsTimer = new QTimer(this); - m_resortAllItemsTimer->setInterval(500); + m_resortAllItemsTimer->setInterval(50); m_resortAllItemsTimer->setSingleShot(true); connect(m_resortAllItemsTimer, &QTimer::timeout, this, &KFileItemModel::resortAllItems); @@ -260,6 +260,13 @@ void KFileItemModel::setShowTrashMime(bool show) } } +void KFileItemModel::scheduleResortAllItems() +{ + if (!m_resortAllItemsTimer->isActive()) { + m_resortAllItemsTimer->start(); + } +} + void KFileItemModel::setShowHiddenFiles(bool show) { m_dirLister->setShowHiddenFiles(show); @@ -981,7 +988,7 @@ void KFileItemModel::resortAllItems() // been moved because of the resorting. QList oldUrls; oldUrls.reserve(itemCount); - for (const ItemData *itemData : qAsConst(m_itemData)) { + for (const ItemData *itemData : std::as_const(m_itemData)) { oldUrls.append(itemData->item.url()); } @@ -1196,7 +1203,12 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items) for (const KFileItem &item : items) { if (item.url() == currentDir) { - Q_EMIT currentDirectoryRemoved(); + // #473377: Delay emitting currentDirectoryRemoved() to avoid modifying KCoreDirLister + // before KCoreDirListerCache::deleteDir() returns. + QTimer::singleShot(0, this, [this] { + Q_EMIT currentDirectoryRemoved(); + }); + return; } @@ -1226,7 +1238,7 @@ void KFileItemModel::slotItemsDeleted(const KFileItemList &items) indexesToRemoveWithChildren.reserve(m_itemData.count()); const int itemCount = m_itemData.count(); - for (int index : qAsConst(indexesToRemove)) { + for (int index : std::as_const(indexesToRemove)) { indexesToRemoveWithChildren.append(index); const int parentLevel = expandedParentsCount(index); @@ -1644,7 +1656,7 @@ void KFileItemModel::prepareItemsForSorting(QList &itemDataList) case DeletionTimeRole: // These roles can be determined with retrieveData, and they have to be stored // in the QHash "values" for the sorting. - for (ItemData *itemData : qAsConst(itemDataList)) { + for (ItemData *itemData : std::as_const(itemDataList)) { if (itemData->values.isEmpty()) { itemData->values = retrieveData(itemData->item, itemData->parent); } @@ -1653,7 +1665,7 @@ void KFileItemModel::prepareItemsForSorting(QList &itemDataList) case TypeRole: // At least store the data including the file type for items with known MIME type. - for (ItemData *itemData : qAsConst(itemDataList)) { + for (ItemData *itemData : std::as_const(itemDataList)) { if (itemData->values.isEmpty()) { const KFileItem item = itemData->item; if (item.isDir() || item.isMimeTypeKnown()) { @@ -2850,3 +2862,5 @@ void KFileItemModel::slotListerError(KIO::Job *job) Q_EMIT errorMessage(!errorString.isEmpty() ? errorString : i18nc("@info:status", "Unknown error.")); } } + +#include "moc_kfileitemmodel.cpp"