X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/58ab93541c70de4fa7cbb90dc3423cfec556dc38..2f0ceedae088158b8af24a5e94500a7d1c0edecb:/src/views/dolphinview.cpp diff --git a/src/views/dolphinview.cpp b/src/views/dolphinview.cpp index f429529de..a3e1a082e 100644 --- a/src/views/dolphinview.cpp +++ b/src/views/dolphinview.cpp @@ -297,13 +297,22 @@ void DolphinView::markUrlsAsSelected(const QList& urls) void DolphinView::setItemSelectionEnabled(const QRegExp& pattern, bool enabled) { - Q_UNUSED(pattern); - Q_UNUSED(enabled); - /*const QItemSelection matchingIndexes = childrenMatchingPattern(QModelIndex(), pattern); - const QItemSelectionModel::SelectionFlags command = enabled - ? QItemSelectionModel::Select - : QItemSelectionModel::Deselect; - m_viewAccessor.itemView()->selectionModel()->select(matchingIndexes, command);*/ + const KItemListSelectionManager::SelectionMode mode = enabled + ? KItemListSelectionManager::Select + : KItemListSelectionManager::Deselect; + const KFileItemModel* model = fileItemModel(); + KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); + + for (int index = 0; index < model->count(); index++) { + const KFileItem item = model->fileItem(index); + if (pattern.exactMatch(item.name())) { + // An alternative approach would be to store the matching items in a QSet and + // select them in one go after the loop, but we'd need a new function + // KItemListSelectionManager::setSelected(QSet, SelectionMode mode) + // for that. + selectionManager->setSelected(index, 1, mode); + } + } } void DolphinView::setZoomLevel(int level) @@ -529,23 +538,13 @@ void DolphinView::selectAll() void DolphinView::invertSelection() { - KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); - const QSet selectedItems = selectionManager->selectedItems(); - QSet invertedSelectedItems; - - const int maxIndex = fileItemModel()->count() - 1; - for (int i = 0; i <= maxIndex; ++i) { - if (!selectedItems.contains(i)) { - invertedSelectedItems.insert(i); - } - } - - selectionManager->setSelectedItems(invertedSelectedItems); + KItemListSelectionManager* selectionManager = m_container->controller()->selectionManager(); + selectionManager->setSelected(0, fileItemModel()->count(), KItemListSelectionManager::Toggle); } void DolphinView::clearSelection() { - //m_viewAccessor.itemView()->clearSelection(); + m_container->controller()->selectionManager()->clearSelection(); } void DolphinView::renameSelectedItems() @@ -1172,32 +1171,6 @@ void DolphinView::markPastedUrlsAsSelected(const QMimeData* mimeData) markUrlsAsSelected(urls); } -QItemSelection DolphinView::childrenMatchingPattern(const QModelIndex& parent, const QRegExp& pattern) const -{ - Q_UNUSED(parent); - Q_UNUSED(pattern); - 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; -} - void DolphinView::updateWritableState() { const bool wasFolderWritable = m_isFolderWritable;