]> cloud.milkyroute.net Git - dolphin.git/commitdiff
- restore functionality that selections are kept when changing the view mode
authorPeter Penz <peter.penz19@gmail.com>
Sat, 29 Aug 2009 12:51:04 +0000 (12:51 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Sat, 29 Aug 2009 12:51:04 +0000 (12:51 +0000)
- some minor cleanups

svn path=/trunk/KDE/kdebase/apps/; revision=1016955

src/dolphindetailsview.cpp
src/dolphiniconsview.cpp
src/dolphinview.cpp
src/dolphinview.h
src/viewextensionsfactory.cpp

index f8e5898596b05611c152417a0dd7235b08a6ad7e..9d37fa674c098eef63100cde12d94b2ce6895732 100644 (file)
@@ -139,7 +139,6 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
     connect(view, SIGNAL(showPreviewChanged()),
             this, SLOT(slotShowPreviewChanged()));
 
-    updateDecorationSize(view->showPreview());
 
     setFocus();
     viewport()->installEventFilter(this);
@@ -156,6 +155,8 @@ DolphinDetailsView::DolphinDetailsView(QWidget* parent,
 
     m_extensionsFactory = new ViewExtensionsFactory(this, controller);
     m_extensionsFactory->fileItemDelegate()->setMinimizedNameColumn(true);
+
+    updateDecorationSize(view->showPreview());
 }
 
 DolphinDetailsView::~DolphinDetailsView()
index efbcfd6fb460a77194572898851680e2ce35a718..10ffd9d42413806f9d445eb414aca36403822243 100644 (file)
@@ -104,7 +104,6 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
     }
 
     setWordWrap(settings->numberOfTextlines() > 1);
-    updateGridSize(view->showPreview(), 0);
 
     if (settings->arrangement() == QListView::TopToBottom) {
         setFlow(QListView::LeftToRight);
@@ -125,6 +124,7 @@ DolphinIconsView::DolphinIconsView(QWidget* parent,
             this, SLOT(slotGlobalSettingsChanged(int)));
 
     m_extensionsFactory = new ViewExtensionsFactory(this, controller);
+    updateGridSize(view->showPreview(), 0);
 }
 
 DolphinIconsView::~DolphinIconsView()
index 929a3ed1c61eb063b612c0cf352d07c91366c9f8..19e01cb900499aee715906dfdaf06518dd4cc8aa 100644 (file)
@@ -92,6 +92,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_topLayout(0),
     m_controller(0),
     m_viewAccessor(proxyModel),
+    m_selectionModel(0),
     m_selectionChangedTimer(0),
     m_versionControlObserver(0),
     m_rootUrl(),
@@ -1300,45 +1301,16 @@ void DolphinView::createView()
     deleteView();
     Q_ASSERT(m_viewAccessor.itemView() == 0);
     m_viewAccessor.createView(this, m_controller, m_mode);
-    initializeView();
-    m_topLayout->insertWidget(1, m_viewAccessor.layoutTarget());
-}
 
-void DolphinView::deleteView()
-{
-    QAbstractItemView* view = m_viewAccessor.itemView();
-    if (view != 0) {
-        // It's important to set the keyboard focus to the parent
-        // before deleting the view: Otherwise when having a split
-        // view the other view will get the focus and will request
-        // an activation (see DolphinView::eventFilter()).
-        setFocusProxy(0);
-        setFocus();
-
-        m_topLayout->removeWidget(view);
-        view->close();
-
-        disconnect(view);
-        m_controller->disconnect(view);
-        view->disconnect();
-
-        // TODO: move this code into ViewAccessor::deleteView()
-        deleteWhenNotDragSource(view);
-        view = 0;
-
-        m_viewAccessor.deleteView();
-    }
-}
-
-void DolphinView::initializeView()
-{
     QAbstractItemView* view = m_viewAccessor.itemView();
     Q_ASSERT(view != 0);
     view->installEventFilter(this);
     view->viewport()->installEventFilter(this);
     setFocusProxy(view);
 
-    //if (m_mode != ColumnView) {
+    /* TODO: enable folder expanding again later
+
+    if (m_mode != ColumnView) {
         // Give the view the ability to auto-expand its directories on hovering
         // (the column view takes care about this itself). If the details view
         // uses expandable folders, the auto-expanding should be used always.
@@ -1347,8 +1319,7 @@ void DolphinView::initializeView()
         connect(folderExpander, SIGNAL(enterDir(const QModelIndex&)),
                 m_controller, SLOT(triggerItem(const QModelIndex&)));
 
-    // TODO: enable again later
-    /*}
+    }
     else {
         // Listen out for requests to delete the current column.
         connect(m_viewAccessor.columnsContainer(), SIGNAL(requestColumnDeletion(QAbstractItemView*)),
@@ -1357,23 +1328,21 @@ void DolphinView::initializeView()
 
     m_controller->setItemView(view);
 
-    // TODO: reactivate selection model
-    /*view->setModel(m_viewAccessor.proxyModel());
-    if (m_selectionModel != 0) {
-        view->setSelectionModel(m_selectionModel);
-    } else {
-        m_selectionModel = view->selectionModel();
-    }*/
-
     m_selectionChangedTimer = new QTimer(this);
     m_selectionChangedTimer->setSingleShot(true);
     m_selectionChangedTimer->setInterval(300);
     connect(m_selectionChangedTimer, SIGNAL(timeout()),
             this, SLOT(emitSelectionChangedSignal()));
 
-    // reparent the selection model, as it should not be deleted
-    // when deleting the model
-    //m_selectionModel->setParent(this);
+    // When changing the view mode, the selection is lost due to reinstantiating
+    // a new item view with a custom selection model. Pass the ownership of the
+    // selection model to DolphinView, so that it can be shared by all item views.
+    if (m_selectionModel != 0) {
+        view->setSelectionModel(m_selectionModel);
+    } else {
+        m_selectionModel = view->selectionModel();
+    }
+    m_selectionModel->setParent(this);
 
     view->setSelectionMode(QAbstractItemView::ExtendedSelection);
 
@@ -1391,6 +1360,34 @@ void DolphinView::initializeView()
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
+
+    m_topLayout->insertWidget(1, m_viewAccessor.layoutTarget());
+}
+
+void DolphinView::deleteView()
+{
+    QAbstractItemView* view = m_viewAccessor.itemView();
+    if (view != 0) {
+        // It's important to set the keyboard focus to the parent
+        // before deleting the view: Otherwise when having a split
+        // view the other view will get the focus and will request
+        // an activation (see DolphinView::eventFilter()).
+        setFocusProxy(0);
+        setFocus();
+
+        m_topLayout->removeWidget(view);
+        view->close();
+
+        disconnect(view);
+        m_controller->disconnect(view);
+        view->disconnect();
+
+        // TODO: move this code into ViewAccessor::deleteView()
+        deleteWhenNotDragSource(view);
+        view = 0;
+
+        m_viewAccessor.deleteView();
+    }
 }
 
 void DolphinView::pasteToUrl(const KUrl& url)
index 08fe70e5f116cf92686dc20c00ffd1a1f8cbb8f9..b8c91333d0bfa2d79fdb79c2b4580d95ba038e74 100644 (file)
@@ -719,8 +719,6 @@ private:
 
     void deleteView();
 
-    void initializeView();
-
     /**
      * Helper method for DolphinView::paste() and DolphinView::pasteIntoFolder().
      * Pastes the clipboard data into the URL \a url.
@@ -825,7 +823,7 @@ private:
     DolphinController* m_controller;
     ViewAccessor m_viewAccessor;
 
-    QItemSelectionModel* m_selectionModel;
+    QItemSelectionModel* m_selectionModel; // allow to switch views without losing the selection
     QTimer* m_selectionChangedTimer;
 
     VersionControlObserver* m_versionControlObserver;
index 198883d900c0b6803a8717a5909dc2ff79ac57e0..baaf3524a76dceecff0600b3b6c8d8997d193559 100644 (file)
@@ -75,8 +75,6 @@ ViewExtensionsFactory::ViewExtensionsFactory(QAbstractItemView* view,
 
     // initialize auto scroller
     m_autoScroller = new DolphinViewAutoScroller(view);
-    connect(controller, SIGNAL(currentIndexChanged(QModelIndex, QModelIndex)),
-            m_autoScroller, SLOT(handleCurrentIndexChanged(QModelIndex, QModelIndex)));
 
     // initialize file item delegate
     m_fileItemDelegate = new DolphinFileItemDelegate(view);