]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
Use QSortFilterProxyModel for sorting KFileItems (thanks to Fredrik for this hint...
[dolphin.git] / src / dolphinview.cpp
index 2f287f353359b4c524c9c38c0effd94c372e9f6b..c23cb2baa7197e8dbb7269c23876d2d909ede332 100644 (file)
@@ -39,6 +39,7 @@
 #include "dolphinstatusbar.h"
 #include "dolphinmainwindow.h"
 #include "dolphindirlister.h"
+#include "dolphinsortfilterproxymodel.h"
 #include "viewproperties.h"
 #include "dolphindetailsview.h"
 #include "dolphiniconsview.h"
@@ -57,12 +58,17 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
     m_refreshing(false),
     m_showProgress(false),
     m_mode(mode),
-    m_mainWindow(mainWindow),
-    m_statusBar(0),
     m_iconSize(0),
     m_folderCount(0),
     m_fileCount(0),
-    m_filterBar(0)
+    m_mainWindow(mainWindow),
+    m_topLayout(0),
+    m_urlNavigator(0),
+    m_iconsView(0),
+    m_filterBar(0),
+    m_statusBar(0),
+    m_dirLister(0),
+    m_proxyModel(0)
 {
     hide();
     setFocusPolicy(Qt::StrongFocus);
@@ -98,6 +104,11 @@ DolphinView::DolphinView(DolphinMainWindow *mainWindow,
 
     KDirModel* model = new KDirModel();
     model->setDirLister(m_dirLister);
+
+    m_proxyModel = new DolphinSortFilterProxyModel(this);
+    m_proxyModel->setSourceModel(model);
+    m_proxyModel->setDynamicSortFilter(true);
+
     m_iconsView->setModel(model);
 
     KFileItemDelegate* delegate = new KFileItemDelegate(this);
@@ -302,12 +313,12 @@ void DolphinView::renameSelectedItems()
 
 void DolphinView::selectAll()
 {
-    //fileView()->selectAll();
+    selectAll(QItemSelectionModel::Select);
 }
 
 void DolphinView::invertSelection()
 {
-    //fileView()->invertSelection();
+    selectAll(QItemSelectionModel::Toggle);
 }
 
 DolphinStatusBar* DolphinView::statusBar() const
@@ -395,8 +406,7 @@ void DolphinView::setSorting(Sorting sorting)
         ViewProperties props(url());
         props.setSorting(sorting);
 
-        KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
-        dirModel->sort(columnIndex(sorting), props.sortOrder());
+        m_proxyModel->setSorting(sorting);
 
         emit sortingChanged(sorting);
     }
@@ -404,10 +414,7 @@ void DolphinView::setSorting(Sorting sorting)
 
 DolphinView::Sorting DolphinView::sorting() const
 {
-    // TODO: instead of getting the sorting from the properties just fetch
-    // them from KDirModel, if such an interface will be offered (David?)
-    ViewProperties props(url());
-    return props.sorting();
+    return m_proxyModel->sorting();
 }
 
 void DolphinView::setSortOrder(Qt::SortOrder order)
@@ -416,8 +423,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order)
         ViewProperties props(url());
         props.setSortOrder(order);
 
-        KDirModel* dirModel = static_cast<KDirModel*>(m_iconsView->model());
-        dirModel->sort(columnIndex(props.sorting()), order);
+        m_proxyModel->setSortOrder(order);
 
         emit sortOrderChanged(order);
     }
@@ -425,10 +431,7 @@ void DolphinView::setSortOrder(Qt::SortOrder order)
 
 Qt::SortOrder DolphinView::sortOrder() const
 {
-    // TODO: instead of getting the order from the properties just fetch
-    // them from KDirModel, if such an interface will be offered (David?)
-    ViewProperties props(url());
-    return props.sortOrder();
+    return m_proxyModel->sortOrder();
 }
 
 void DolphinView::goBack()
@@ -814,23 +817,6 @@ void DolphinView::slotContentsMoving(int x, int y)
     }
 }
 
-/*KFileView* DolphinView::fileView() const
-{
-    return (m_mode == DetailsView) ? static_cast<KFileView*>(m_iconsView) :
-                                     static_cast<KFileView*>(m_iconsView);
-}*/
-
-Q3ScrollView* DolphinView::scrollView() const
-{
-    return 0; //(m_mode == DetailsView) ? static_cast<Q3ScrollView*>(m_iconsView) :
-              //                       static_cast<Q3ScrollView*>(m_iconsView);
-}
-
-ItemEffectsManager* DolphinView::itemEffectsManager() const
-{
-    return 0;
-}
-
 void DolphinView::startDirLister(const KUrl& url, bool reload)
 {
     if (!url.isValid()) {
@@ -997,19 +983,6 @@ void DolphinView::slotChangeNameFilter(const QString& nameFilter)
 
     m_dirLister->setNameFilter(adjustedFilter);
     m_dirLister->emitChanges();
-
-    // TODO: this is a workaround for QIconView: the item position
-    // stay as they are by filtering, only an inserting of an item
-    // results to an automatic adjusting of the item position. In Qt4/KDE4
-    // this workaround should get obsolete due to Interview.
-    /*KFileView* view = fileView();
-    if (view == m_iconsView) {
-        KFileItem* first = view->firstFileItem();
-        if (first != 0) {
-            view->removeItem(first);
-            view->insertItem(first);
-        }
-    }*/
 }
 
 void DolphinView::applyModeToView()
@@ -1028,11 +1001,6 @@ void DolphinView::applyModeToView()
             m_iconsView->setViewMode(QListView::ListMode);
             m_iconsView->setGridSize(QSize(256, 24));
             break;
-
-        //case PreviewsView:
-        //    m_iconsView->setViewMode(QListView::IconMode);
-        //    m_iconsView->setGridSize(QSize(128, 128));
-        //    break;
     }
 }
 
@@ -1048,4 +1016,17 @@ int DolphinView::columnIndex(Sorting sorting) const
     return index;
 }
 
+void DolphinView::selectAll(QItemSelectionModel::SelectionFlags flags)
+{
+    QItemSelectionModel* selectionModel = m_iconsView->selectionModel();
+    const QAbstractItemModel* itemModel = selectionModel->model();
+
+    const QModelIndex topLeft = itemModel->index(0, 0);
+    const QModelIndex bottomRight = itemModel->index(itemModel->rowCount() - 1,
+                                                     itemModel->columnCount() - 1);
+
+    QItemSelection selection(topLeft, bottomRight);
+    selectionModel->select(selection, flags);
+}
+
 #include "dolphinview.moc"