]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kfileitemmodel.cpp
Fix keyboard issues when groups are enabled
[dolphin.git] / src / kitemviews / kfileitemmodel.cpp
index baf168ddf1df3050903aec365a2a13bffd172701..3fd40e9d453c35c2949f2182fba2062655430322 100644 (file)
@@ -367,6 +367,7 @@ void KFileItemModel::setRoles(const QSet<QByteArray>& roles)
         }
     }
 
+    m_groups.clear();
     resetRoles();
 
     QSetIterator<QByteArray> it(roles);
@@ -606,20 +607,19 @@ void KFileItemModel::resortAllItems()
     }
     
     // Determine the indexes that have been moved
-    bool emitItemsMoved = false;
     QList<int> movedToIndexes;
     movedToIndexes.reserve(itemCount);
     for (int i = 0; i < itemCount; i++) {
         const int newIndex = m_items.value(oldUrls.at(i).url());
         movedToIndexes.append(newIndex);
-        if (!emitItemsMoved && newIndex != i) {
-            emitItemsMoved = true;
-        }
     }   
 
-    if (emitItemsMoved) {
-        emit itemsMoved(KItemRange(0, itemCount), movedToIndexes);
-    }
+    // Don't check whether items have really been moved and always emit a
+    // itemsMoved() signal after resorting: In case of grouped items
+    // the groups might change even if the items themselves don't change their
+    // position. Let the receiver of the signal decide whether a check for moved
+    // items makes sense.
+    emit itemsMoved(KItemRange(0, itemCount), movedToIndexes);
     
 #ifdef KFILEITEMMODEL_DEBUG
     kDebug() << "[TIME] Resorting of" << itemCount << "items:" << timer.elapsed();
@@ -1157,12 +1157,16 @@ QHash<QByteArray, QVariant> KFileItemModel::retrieveData(const KFileItem& item)
     }
 
     if (m_requestRole[PathRole]) {
+        QString path;
         if (item.url().protocol() == QLatin1String("trash")) {
-            const KIO::UDSEntry udsEntry = item.entry();
-            data.insert("path", udsEntry.stringValue(KIO::UDSEntry::UDS_EXTRA));
+            path = item.entry().stringValue(KIO::UDSEntry::UDS_EXTRA);
         } else {
-            data.insert("path", item.localPath());
+            path = item.localPath();
         }
+
+        const int index = path.lastIndexOf(item.text());
+        path = path.mid(0, index - 1);
+        data.insert("path", path);
     }
 
     if (m_requestRole[IsExpandedRole]) {
@@ -1527,16 +1531,16 @@ int KFileItemModel::expansionLevelsCompare(const ItemData* a, const ItemData* b)
 
     // Compare the items of the parents that represent the first
     // different path after the common path.
-    const KUrl parentUrlA(pathA.left(index) + subPathA);
-    const KUrl parentUrlB(pathB.left(index) + subPathB);
+    const QString parentPathA = pathA.left(index) + subPathA;
+    const QString parentPathB = pathB.left(index) + subPathB;
 
     const ItemData* parentA = a;
-    while (parentA && parentA->item.url() != parentUrlA) {
+    while (parentA && parentA->item.url().path() != parentPathA) {
         parentA = parentA->parent;
     }
 
     const ItemData* parentB = b;
-    while (parentB && parentB->item.url() != parentUrlB) {
+    while (parentB && parentB->item.url().path() != parentPathB) {
         parentB = parentB->parent;
     }
 
@@ -1841,12 +1845,12 @@ QList<QPair<int, QVariant> > KFileItemModel::ratingRoleGroups() const
     const int maxIndex = count() - 1;
     QList<QPair<int, QVariant> > groups;
 
-    int groupValue;
+    int groupValue = -1;
     for (int i = 0; i <= maxIndex; ++i) {
         if (isChildItem(i)) {
             continue;
         }
-        const int newGroupValue = m_itemData.at(i)->values.value("rating").toInt();
+        const int newGroupValue = m_itemData.at(i)->values.value("rating", 0).toInt();
         if (newGroupValue != groupValue) {
             groupValue = newGroupValue;
             groups.append(QPair<int, QVariant>(i, newGroupValue));
@@ -1863,15 +1867,17 @@ QList<QPair<int, QVariant> > KFileItemModel::genericStringRoleGroups(const QByte
     const int maxIndex = count() - 1;
     QList<QPair<int, QVariant> > groups;
 
+    bool isFirstGroupValue = true;
     QString groupValue;
     for (int i = 0; i <= maxIndex; ++i) {
         if (isChildItem(i)) {
             continue;
         }
         const QString newGroupValue = m_itemData.at(i)->values.value(role).toString();
-        if (newGroupValue != groupValue) {
+        if (newGroupValue != groupValue || isFirstGroupValue) {
             groupValue = newGroupValue;
             groups.append(QPair<int, QVariant>(i, newGroupValue));
+            isFirstGroupValue = false;
         }
     }