]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Consti'fy
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index 56c21f51ca50329eeac5c18166154b0fb3da78b4..61bedfacace298160a07831bdc5d23c0e56c938a 100644 (file)
@@ -304,6 +304,9 @@ QString KFileItemModel::roleDescription(const QByteArray& role) const
         int count = 0;
         const RoleInfoMap* map = rolesInfoMap(count);
         for (int i = 0; i < count; ++i) {
+           if (!map[i].roleTranslation) {
+                   continue;
+           }
             description.insert(map[i].role, i18nc(map[i].roleTranslationContext, map[i].roleTranslation));
         }
     }
@@ -786,7 +789,7 @@ void KFileItemModel::onGroupedSortingChanged(bool current)
     m_groups.clear();
 }
 
-void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous)
+void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArray& previous, bool resortItems)
 {
     Q_UNUSED(previous);
     m_sortRole = typeForRole(current);
@@ -797,7 +800,9 @@ void KFileItemModel::onSortRoleChanged(const QByteArray& current, const QByteArr
         setRoles(newRoles);
     }
 
-    resortAllItems();
+    if (resortItems) {
+        resortAllItems();
+    }
 }
 
 void KFileItemModel::onSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous)
@@ -1550,8 +1555,8 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
         data.insert(sharedValue("isLink"), true);
     }
 
-    if (m_requestRole[IsHiddenRole] && item.isHidden()) {
-        data.insert(sharedValue("isHidden"), true);
+    if (m_requestRole[IsHiddenRole]) {
+        data.insert(sharedValue("isHidden"), item.isHidden());
     }
 
     if (m_requestRole[NameRole]) {
@@ -1563,26 +1568,26 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item,
     }
 
     if (m_requestRole[ModificationTimeRole]) {
-        // Don't use KFileItem::timeString() as this is too expensive when
-        // having several thousands of items. Instead the formatting of the
-        // date-time will be done on-demand by the view when the date will be shown.
-        const QDateTime dateTime = item.time(KFileItem::ModificationTime);
+        // Don't use KFileItem::timeString() or KFileItem::time() as this is too expensive when
+        // having several thousands of items. Instead read the raw number from UDSEntry directly
+        // and the formatting of the date-time will be done on-demand by the view when the date will be shown.
+        const long long dateTime = item.entry().numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, -1);
         data.insert(sharedValue("modificationtime"), dateTime);
     }
 
     if (m_requestRole[CreationTimeRole]) {
-        // Don't use KFileItem::timeString() as this is too expensive when
-        // having several thousands of items. Instead the formatting of the
-        // date-time will be done on-demand by the view when the date will be shown.
-        const QDateTime dateTime = item.time(KFileItem::CreationTime);
+        // Don't use KFileItem::timeString() or KFileItem::time() as this is too expensive when
+        // having several thousands of items. Instead read the raw number from UDSEntry directly
+        // and the formatting of the date-time will be done on-demand by the view when the date will be shown.
+        const long long dateTime = item.entry().numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
         data.insert(sharedValue("creationtime"), dateTime);
     }
 
     if (m_requestRole[AccessTimeRole]) {
-        // Don't use KFileItem::timeString() as this is too expensive when
-        // having several thousands of items. Instead the formatting of the
-        // date-time will be done on-demand by the view when the date will be shown.
-        const QDateTime dateTime = item.time(KFileItem::AccessTime);
+        // Don't use KFileItem::timeString() or KFileItem::time() as this is too expensive when
+        // having several thousands of items. Instead read the raw number from UDSEntry directly
+        // and the formatting of the date-time will be done on-demand by the view when the date will be shown.
+        const long long dateTime = item.entry().numberValue(KIO::UDSEntry::UDS_ACCESS_TIME, -1);
         data.insert(sharedValue("accesstime"), dateTime);
     }
 
@@ -1712,8 +1717,8 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
     return (sortOrder() == Qt::AscendingOrder) ? result < 0 : result > 0;
 }
 
-void KFileItemModel::sort(QList<KFileItemModel::ItemData*>::iterator begin,
-                          QList<KFileItemModel::ItemData*>::iterator end) const
+void KFileItemModel::sort(const QList<KFileItemModel::ItemData*>::iterator &begin,
+                          const QList<KFileItemModel::ItemData*>::iterator &end) const
 {
     auto lambdaLessThan = [&] (const KFileItemModel::ItemData* a, const KFileItemModel::ItemData* b)
     {
@@ -1778,8 +1783,8 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
     }
 
     case ModificationTimeRole: {
-        const QDateTime dateTimeA = itemA.time(KFileItem::ModificationTime);
-        const QDateTime dateTimeB = itemB.time(KFileItem::ModificationTime);
+        const long long dateTimeA = itemA.entry().numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, -1);
+        const long long dateTimeB = itemB.entry().numberValue(KIO::UDSEntry::UDS_MODIFICATION_TIME, -1);
         if (dateTimeA < dateTimeB) {
             result = -1;
         } else if (dateTimeA > dateTimeB) {
@@ -1789,8 +1794,8 @@ int KFileItemModel::sortRoleCompare(const ItemData* a, const ItemData* b, const
     }
 
     case CreationTimeRole: {
-        const QDateTime dateTimeA = itemA.time(KFileItem::CreationTime);
-        const QDateTime dateTimeB = itemB.time(KFileItem::CreationTime);
+        const long long dateTimeA = itemA.entry().numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
+        const long long dateTimeB = itemB.entry().numberValue(KIO::UDSEntry::UDS_CREATION_TIME, -1);
         if (dateTimeA < dateTimeB) {
             result = -1;
         } else if (dateTimeA > dateTimeB) {
@@ -1977,7 +1982,7 @@ QList<QPair<int, QVariant> > KFileItemModel::sizeRoleGroups() const
     return groups;
 }
 
-QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(std::function<QDateTime(const ItemData *)> fileTimeCb) const
+QList<QPair<int, QVariant> > KFileItemModel::timeRoleGroups(const std::function<QDateTime(const ItemData *)> &fileTimeCb) const
 {
     Q_ASSERT(!m_itemData.isEmpty());