]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Make the View operate on the QSortFilterProxyModel
authorHolger Freyther <holger+kde@freyther.de>
Sat, 23 Dec 2006 18:00:25 +0000 (18:00 +0000)
committerHolger Freyther <holger+kde@freyther.de>
Sat, 23 Dec 2006 18:00:25 +0000 (18:00 +0000)
Fix the crashes by using mapToSource and mapSelectionToSource
to map the QModelIndex

svn path=/trunk/playground/utils/dolphin/; revision=616118

src/dolphinview.cpp

index d66cfd9246a9be523ceee5d39d18a14ef21b97f1..1efe333844f269fc146e57735dd3ba1bf789f102 100644 (file)
@@ -109,7 +109,7 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
     m_proxyModel = new DolphinSortFilterProxyModel(this);
     m_proxyModel->setSourceModel(m_dirModel);
 
     m_proxyModel = new DolphinSortFilterProxyModel(this);
     m_proxyModel->setSourceModel(m_dirModel);
 
-    m_iconsView->setModel(m_dirModel);   // TODO: using m_proxyModel crashes when clicking on an item
+    m_iconsView->setModel(m_proxyModel);
 
     KFileItemDelegate* delegate = new KFileItemDelegate(this);
     delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
 
     KFileItemDelegate* delegate = new KFileItemDelegate(this);
     delegate->setAdditionalInformation(KFileItemDelegate::FriendlyMimeType);
@@ -478,23 +478,28 @@ bool DolphinView::hasSelection() const
     return m_iconsView->selectionModel()->hasSelection();
 }
 
     return m_iconsView->selectionModel()->hasSelection();
 }
 
+/*
+ * Our view has a selection, we will map them back to the DirModel
+ * and then fill the KFileItemList
+ */
 KFileItemList DolphinView::selectedItems() const
 {
 KFileItemList DolphinView::selectedItems() const
 {
-    QItemSelectionModel* selModel = m_iconsView->selectionModel();
-    assert(selModel != 0);
+    assert( m_iconsView && m_iconsView->selectionModel() );
 
 
+    const QItemSelection selection = m_proxyModel->mapSelectionToSource( m_iconsView->selectionModel()->selection() );
     KFileItemList itemList;
     KFileItemList itemList;
-    if (selModel->hasSelection()) {
-       const QModelIndexList indexList = selModel->selectedIndexes();
-
-        QModelIndexList::const_iterator end = indexList.end();
-        for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
-           KFileItem* item = m_dirModel->itemForIndex(*it);
-           if (item != 0) {
-               itemList.append(item);
-           }
+
+    const QModelIndexList indexList = selection.indexes();
+    QModelIndexList::const_iterator end = indexList.end();
+    for (QModelIndexList::const_iterator it = indexList.begin(); it != end; ++it) {
+        assert( (*it).isValid()  );
+
+        KFileItem* item = m_dirModel->itemForIndex(*it);
+        if (item != 0) {
+            itemList.append(item);
         }
     }
         }
     }
+
     return itemList;
 }
 
     return itemList;
 }
 
@@ -660,7 +665,7 @@ void DolphinView::loadDirectory(const KUrl& url)
 
 void DolphinView::triggerItem(const QModelIndex& index)
 {
 
 void DolphinView::triggerItem(const QModelIndex& index)
 {
-    KFileItem* item = m_dirModel->itemForIndex(index);
+    KFileItem* item = m_dirModel->itemForIndex(m_proxyModel->mapToSource(index));
     if (item == 0) {
         return;
     }
     if (item == 0) {
         return;
     }