]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Interface cleanup: The DolphinView should not expose QAbstractItemView-specific thing...
authorPeter Penz <peter.penz19@gmail.com>
Thu, 4 Nov 2010 17:27:11 +0000 (17:27 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Thu, 4 Nov 2010 17:27:11 +0000 (17:27 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1193113

src/dolphinpart.cpp
src/dolphinpart.h
src/views/dolphinview.cpp
src/views/dolphinview.h

index 0691791a504bbc8562eae638320db59b19e37a3a..3d0748f844c86eb02543cb6b81a5aebef2d714ce 100644 (file)
@@ -480,49 +480,27 @@ void DolphinPart::slotSelectItemsMatchingPattern()
 {
     openSelectionDialog(i18nc("@title:window", "Select"),
                         i18n("Select all items matching this pattern:"),
-                        QItemSelectionModel::Select);
+                        true);
 }
 
 void DolphinPart::slotUnselectItemsMatchingPattern()
 {
     openSelectionDialog(i18nc("@title:window", "Unselect"),
                         i18n("Unselect all items matching this pattern:"),
-                        QItemSelectionModel::Deselect);
+                        false);
 }
 
-void DolphinPart::openSelectionDialog(const QString& title, const QString& text, QItemSelectionModel::SelectionFlags command)
+void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
 {
     bool okClicked;
     QString pattern = KInputDialog::getText(title, text, "*", &okClicked, m_view);
 
     if (okClicked && !pattern.isEmpty()) {
         QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
-        QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), patternRegExp);
-        m_view->selectionModel()->select(matchingIndexes, command);
+        m_view->setItemSelectionEnabled(patternRegExp, selectItems);
     }
 }
 
-QItemSelection DolphinPart::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& patternRegExp)
-{
-    QItemSelection matchingIndexes;
-    int numRows = m_proxyModel->rowCount(parent);
-
-    for (int row = 0; row < numRows; row++) {
-        QModelIndex index = m_proxyModel->index(row, 0, parent);
-        QModelIndex sourceIndex = m_proxyModel->mapToSource(index);
-
-        if (sourceIndex.isValid() && patternRegExp.exactMatch(m_dolphinModel->data(sourceIndex).toString())) {
-            matchingIndexes += QItemSelectionRange(index);
-        }
-
-        if (m_proxyModel->hasChildren(index)) {
-            matchingIndexes += childrenMatchingPattern(index, patternRegExp);
-        }
-    }
-
-    return matchingIndexes;
-}
-
 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
 {
     QAction* action = actionCollection()->action(viewModeName);
@@ -669,7 +647,7 @@ KFileItemList DolphinPartFileInfoExtension::queryFor(KParts::FileInfoExtension::
               return part()->view()->selectedItems();
           break;
       case KParts::FileInfoExtension::AllItems:
-          return part()->view()->allItems();
+          return part()->view()->items();
       default:
           break;
     }
index b0b01d8d8bca7f3cbc05f8e60cc1999aa43bc0f3..a23e08697c77671e7fed0aa3253c8e01980e5093 100644 (file)
@@ -225,9 +225,7 @@ private:
                         QActionGroup* actionGroup);
 
     void openSelectionDialog(const QString& title, const QString& text,
-                             QItemSelectionModel::SelectionFlags command);
-
-    QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& patternRegExp);
+                             bool selectItems);
 
 private:
     DolphinView* m_view;
index 8ed0d993e5fd695f57250be2dbd5737b18bcbc6c..2c2dbc23144be83fee9f4338cfc057716cd90ce9 100644 (file)
@@ -279,18 +279,9 @@ bool DolphinView::supportsCategorizedSorting() const
     return m_viewAccessor.supportsCategorizedSorting();
 }
 
-bool DolphinView::hasSelection() const
+KFileItemList DolphinView::items() const
 {
-    const QAbstractItemView* view = m_viewAccessor.itemView();
-    return (view != 0) && view->selectionModel()->hasSelection();
-}
-
-void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
-{
-    foreach (const KUrl& url, urls) {
-        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
-        m_selectedItems.append(item);
-    }
+    return m_viewAccessor.dirLister()->items();
 }
 
 KFileItemList DolphinView::selectedItems() const
@@ -324,9 +315,21 @@ int DolphinView::selectedItemsCount() const
     return view->selectionModel()->selectedIndexes().count();
 }
 
-QItemSelectionModel* DolphinView::selectionModel() const
+void DolphinView::markUrlsAsSelected(const QList<KUrl>& urls)
+{
+    foreach (const KUrl& url, urls) {
+        KFileItem item(KFileItem::Unknown, KFileItem::Unknown, url);
+        m_selectedItems.append(item);
+    }
+}
+
+void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled)
 {
-    return m_viewAccessor.itemView()->selectionModel();
+    const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern);
+    const QItemSelectionModel::SelectionFlags command = enabled
+                                                      ? QItemSelectionModel::Select
+                                                      : QItemSelectionModel::Deselect;
+    m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);
 }
 
 void DolphinView::setZoomLevel(int level)
@@ -948,6 +951,12 @@ void DolphinView::saveState(QDataStream& stream)
     stream << m_viewAccessor.expandedUrls();
 }
 
+bool DolphinView::hasSelection() const
+{
+    const QAbstractItemView* view = m_viewAccessor.itemView();
+    return (view != 0) && view->selectionModel()->hasSelection();
+}
+
 void DolphinView::observeCreatedItem(const KUrl& url)
 {
     m_createdItemUrl = url;
@@ -1248,6 +1257,30 @@ void DolphinView::addNewFileNames(const QMimeData* mimeData)
     }
 }
 
+QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const
+{
+    QItemSelection matchingIndexes;
+    const DolphinSortFilterProxyModel* proxyModel = m_viewAccessor.proxyModel();
+    const DolphinModel* dolphinModel = m_viewAccessor.dirModel();
+
+    const int rowCount = proxyModel->rowCount(parent);
+
+    for (int row = 0; row < rowCount; ++row) {
+        QModelIndex index = proxyModel->index(row, 0, parent);
+        QModelIndex sourceIndex = proxyModel->mapToSource(index);
+
+        if (sourceIndex.isValid() && pattern.exactMatch(dolphinModel->data(sourceIndex).toString())) {
+            matchingIndexes += QItemSelectionRange(index);
+        }
+
+        if (proxyModel->hasChildren(index)) {
+            matchingIndexes += childrenMatchingPattern(index, pattern);
+        }
+    }
+
+    return matchingIndexes;
+}
+
 DolphinView::ViewAccessor::ViewAccessor(DolphinSortFilterProxyModel* proxyModel) :
     m_iconsView(0),
     m_detailsView(0),
@@ -1458,9 +1491,4 @@ void DolphinView::restoreContentsPosition()
     }
 }
 
-KFileItemList DolphinView::allItems() const
-{
-    return m_viewAccessor.dirLister()->items();
-}
-
 #include "dolphinview.moc"
index a06105cf3c8808a0b2d3358efd785c67be0a7d43..5fcf1ab4de861606b120b254d874fc89e14885bb 100644 (file)
@@ -43,6 +43,7 @@ typedef KIO::FileUndoManager::CommandType CommandType;
 
 class DolphinColumnViewContainer;
 class DolphinDetailsView;
+class DolphinDetailsViewExpander;
 class DolphinIconsView;
 class DolphinModel;
 class DolphinSortFilterProxyModel;
@@ -53,7 +54,7 @@ class KDirLister;
 class KUrl;
 class ViewModeController;
 class ViewProperties;
-class DolphinDetailsViewExpander;
+class QRegExp;
 
 /**
  * @short Represents a view for the directory content.
@@ -181,12 +182,9 @@ public:
     bool supportsCategorizedSorting() const;
 
     /**
-     * Marks the items indicated by \p urls to get selected after the
-     * directory DolphinView::url() has been loaded. Note that nothing
-     * gets selected if no loading of a directory has been triggered
-     * by DolphinView::setUrl() or DolphinView::reload().
+     * Returns the items of the view.
      */
-    void markUrlsAsSelected(const QList<KUrl>& urls);
+    KFileItemList items() const;
 
     /**
      * Returns the selected items. The list is empty if no item has been
@@ -201,7 +199,19 @@ public:
      */
     int selectedItemsCount() const;
 
-    QItemSelectionModel* selectionModel() const;
+    /**
+     * Marks the items indicated by \p urls to get selected after the
+     * directory DolphinView::url() has been loaded. Note that nothing
+     * gets selected if no loading of a directory has been triggered
+     * by DolphinView::setUrl() or DolphinView::reload().
+     */
+    void markUrlsAsSelected(const QList<KUrl>& urls);
+
+    /**
+     * All items that match to the pattern \a pattern will get selected
+     * if \a enabled is true and deselected if  \a enabled is false.
+     */
+    void setItemSelectionEnabled(const QRegExp& pattern, bool enabled);
 
     /**
      * Sets the zoom level to \a level. It is assured that the used
@@ -324,10 +334,8 @@ public:
      */
     void saveState(QDataStream& stream);
 
-    /**
-     * Returns all the items in the current view.
-     */
-    KFileItemList allItems() const;
+    /** Returns true, if at least one item is selected. */
+    bool hasSelection() const;
 
 public slots:
     /**
@@ -349,9 +357,6 @@ public slots:
      */
     void invertSelection();
 
-    /** Returns true, if at least one item is selected. */
-    bool hasSelection() const;
-
     void clearSelection();
 
     /**
@@ -712,6 +717,12 @@ private:
      */
     void addNewFileNames(const QMimeData* mimeData);
 
+    /**
+     * Helper method for DolphinView::setItemSelectionEnabled(): Returns the selection for
+     * all items of \p parent that match with the regular expression defined by \p pattern.
+     */
+    QItemSelection childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const;
+
 private:
     /**
      * Abstracts the access to the different view implementations