diff options
| author | Peter Penz <[email protected]> | 2010-11-04 17:27:11 +0000 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2010-11-04 17:27:11 +0000 |
| commit | 7e311509a4ac89ebe95f3d81928fe78a9f398aa9 (patch) | |
| tree | 5a906b0f4df2e2bb37dcd31c80dc97285fba131d /src/views | |
| parent | bd7416d0af9d498d0f2b6611fabd16e8e508f094 (diff) | |
Interface cleanup: The DolphinView should not expose QAbstractItemView-specific things like QItemSelectionModel. Just providing interfaces for KFileItem and KUrl will make it easier in future to change the view-implementations internally to QML-specific itemviews or whatever.
svn path=/trunk/KDE/kdebase/apps/; revision=1193113
Diffstat (limited to 'src/views')
| -rw-r--r-- | src/views/dolphinview.cpp | 64 | ||||
| -rw-r--r-- | src/views/dolphinview.h | 39 |
2 files changed, 71 insertions, 32 deletions
diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index 8ed0d993e..2c2dbc231 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -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" diff --git a/src/views/dolphinview.h b/src/views/dolphinview.h index a06105cf3..5fcf1ab4d 100644 --- a/src/views/dolphinview.h +++ b/src/views/dolphinview.h @@ -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 |
