]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/views/dolphinview.cpp
Use capitalized KDE includes
[dolphin.git] / src / views / dolphinview.cpp
index 2dc21b3352aba4c67c4b47c42200cbb10d4047fb..a4e97bf6e6593a24ddee56c49c7964a352e259d0 100644 (file)
 #include <QTimer>
 #include <QScrollBar>
 
-#include <kactioncollection.h>
-#include <kcolorscheme.h>
-#include <kdirlister.h>
-#include <kiconeffect.h>
-#include <kfileitem.h>
-#include <kfileitemlistproperties.h>
-#include <klocale.h>
-#include <kio/deletejob.h>
-#include <kio/netaccess.h>
-#include <kio/previewjob.h>
-#include <kjob.h>
-#include <kmenu.h>
-#include <kmessagebox.h>
+#include <KActionCollection>
+#include <KColorScheme>
+#include <KDirLister>
+#include <KIconEffect>
+#include <KFileItem>
+#include <KFileItemListProperties>
+#include <KLocale>
+#include <KIO/DeleteJob>
+#include <KIO/NetAccess>
+#include <KIO/PreviewJob>
+#include <KJob>
+#include <KMenu>
+#include <KMessageBox>
 #include <konq_fileitemcapabilities.h>
 #include <konq_operations.h>
 #include <konqmimedata.h>
-#include <ktoggleaction.h>
-#include <kurl.h>
+#include <KToggleAction>
+#include <KUrl>
 
 #include "additionalinfoaccessor.h"
 #include "dolphindirlister.h"
@@ -566,15 +566,23 @@ void DolphinView::selectAll()
 
 void DolphinView::invertSelection()
 {
-    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
-    const QAbstractItemModel* itemModel = selectionModel->model();
-
-    const QModelIndex topLeft = itemModel->index(0, 0);
-    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
-                                                     itemModel->columnCount() - 1);
+    // Implementation note: Using selectionModel->select(selection, QItemSelectionModel::Toggle) does not
+    // work, as QItemSelectionModel::hasSelection() provides invalid values in this case. This might be a Qt-issue -
+    // when changing the implementation with an updated Qt-version don't forget to run the Dolphin-unit-tests that
+    // verify this usecase.
+    const KFileItemList selItems = selectedItems();
+    clearSelection();
+
+    QItemSelection invertedSelection;
+    foreach (const KFileItem& item, items()) {
+        if (!selItems.contains(item)) {
+            const QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+            invertedSelection.select(index, index);
+        }
+    }
 
-    const QItemSelection selection(topLeft, bottomRight);
-    selectionModel->select(selection, QItemSelectionModel::Toggle);
+    QItemSelectionModel* selectionModel = m_viewAccessor.itemView()->selectionModel();
+    selectionModel->select(invertedSelection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Current);
 }
 
 void DolphinView::clearSelection()
@@ -1100,7 +1108,7 @@ void DolphinView::slotLoadingCompleted()
         foreach(const KFileItem& item, m_selectedItems) {
             url = item.url().upUrl();
             if (baseUrl.equals(url, KUrl::CompareWithoutTrailingSlash)) {
-                QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
+                const QModelIndex index = m_viewAccessor.proxyModel()->mapFromSource(m_viewAccessor.dirModel()->indexForItem(item));
                 newSelection.select(index, index);
             }
         }
@@ -1338,7 +1346,6 @@ void DolphinView::connectViewAccessor()
     connect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
     connect(dirLister, SIGNAL(started(KUrl)),          this, SLOT(slotDirListerStarted(KUrl)));
     connect(dirLister, SIGNAL(completed()),            this, SLOT(slotDirListerCompleted()));
-    connect(dirLister, SIGNAL(canceled()),             this, SLOT(slotDirListerCompleted()));
     connect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
             this, SLOT(slotRefreshItems()));
 
@@ -1361,7 +1368,6 @@ void DolphinView::disconnectViewAccessor()
     disconnect(dirLister, SIGNAL(redirection(KUrl,KUrl)), this, SLOT(slotRedirection(KUrl,KUrl)));
     disconnect(dirLister, SIGNAL(started(KUrl)),          this, SLOT(slotDirListerStarted(KUrl)));
     disconnect(dirLister, SIGNAL(completed()),            this, SLOT(slotDirListerCompleted()));
-    disconnect(dirLister, SIGNAL(canceled()),             this, SLOT(slotDirListerCompleted()));
     disconnect(dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
                this, SLOT(slotRefreshItems()));