]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix implementation of DolphinView::invertSelection() which assures that DolphinView...
authorPeter Penz <peter.penz19@gmail.com>
Sun, 9 Jan 2011 15:03:30 +0000 (15:03 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sun, 9 Jan 2011 15:03:30 +0000 (15:03 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1213199

src/tests/dolphinviewtest_allviewmodes.cpp
src/views/dolphinview.cpp

index 9d13c6a5c9c3c211ad6ad4d101f5a87a49cc592e..d1557be05a687ef2d647c6e8bbf9832b661ab705 100644 (file)
@@ -83,13 +83,11 @@ void DolphinViewTest_AllViewModes::testSelection() {
     m_view->selectAll();
     verifySelectedItemsCount(totalItems);
 
-    // TODO: DolphinView::invertSelection() does not work in combination with DolphinView::hasSelection(). Might
-    // be a Qt-issue - further investigations are needed.
-    //m_view->invertSelection();
-    //verifySelectedItemsCount(0);
-    //
-    //m_view->invertSelection();
-    //verifySelectedItemsCount(totalItems);
+    m_view->invertSelection();
+    verifySelectedItemsCount(0);
+
+    m_view->invertSelection();
+    verifySelectedItemsCount(totalItems);
 
     m_view->clearSelection();
     verifySelectedItemsCount(0);
@@ -149,14 +147,6 @@ void DolphinViewTest_AllViewModes::verifySelectedItemsCount(int itemsCount) cons
         QVERIFY(m_view->hasSelection());
     }
     else {
-        if (mode() == DolphinView::ColumnView &&
-            itemView()->selectionModel()->selectedIndexes().count() == 0 &&
-            itemView()->selectionModel()->hasSelection()) {
-            QEXPECT_FAIL("",
-                         "The selection model's hasSelection() method returns true, but there are no selected indexes. Needs to be investigated.",
-                         Continue);
-        }
-
         QVERIFY(!m_view->hasSelection());
     }
 }
index 2dc21b3352aba4c67c4b47c42200cbb10d4047fb..f2340fa8924c1d4bf809d5c82b9bc426e1a0efeb 100644 (file)
@@ -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);
             }
         }