From d14423159aa1b9873af4d6c0ec7d470ce8dc54c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Ander=20Pe=C3=B1alba?= Date: Mon, 16 Aug 2010 11:43:57 +0200 Subject: Made the bookmark search case insensitive and added some comments to the BookmarksProxy class. --- src/bookmarks/bookmarksproxy.cpp | 11 ++++++----- src/bookmarks/bookmarksproxy.h | 12 ++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/bookmarks/bookmarksproxy.cpp b/src/bookmarks/bookmarksproxy.cpp index 4e4b4f06..1e4da877 100644 --- a/src/bookmarks/bookmarksproxy.cpp +++ b/src/bookmarks/bookmarksproxy.cpp @@ -27,19 +27,18 @@ // Self Includes #include "bookmarksproxy.h" -#include "bookmarksproxy.moc" BookmarksProxy::BookmarksProxy(QObject *parent) : QSortFilterProxyModel(parent) { + setFilterCaseSensitivity(Qt::CaseInsensitive); } -bool BookmarksProxy::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const +bool BookmarksProxy::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const { - QModelIndex idx = sourceModel()->index(source_row, 0, source_parent); - return recursiveMatch(idx); + return recursiveMatch( sourceModel()->index(source_row, 0, source_parent) ); } @@ -48,10 +47,12 @@ bool BookmarksProxy::recursiveMatch(const QModelIndex &index) const if (index.data().toString().contains(filterRegExp())) return true; - for (int childRow = 0; childRow < sourceModel()->rowCount(index); ++childRow) + int numChildren = sourceModel()->rowCount(index); + for (int childRow = 0; childRow < numChildren; ++childRow) { if (recursiveMatch(sourceModel()->index(childRow, 0, index))) return true; } + return false; } diff --git a/src/bookmarks/bookmarksproxy.h b/src/bookmarks/bookmarksproxy.h index e7b50d8e..b4554d2b 100644 --- a/src/bookmarks/bookmarksproxy.h +++ b/src/bookmarks/bookmarksproxy.h @@ -33,9 +33,13 @@ #include "rekonq_defines.h" // Qt Includes -#include - +#include +/** + * QSortFilterProxyModel hides all children which parent doesn't + * match the filter. This class is used to change this behavior. + * If a bookmark matches the filter it'll be shown, even if it's parent doesn't match it. + */ class REKONQ_TESTS_EXPORT BookmarksProxy : public QSortFilterProxyModel { Q_OBJECT @@ -45,9 +49,9 @@ public: BookmarksProxy(QObject *parent = 0); protected: - virtual bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const; + virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const; - // returns true if any child(or children-child...) matches filter + // returns true if index or any of his children match the filter bool recursiveMatch(const QModelIndex &index) const; }; -- cgit v1.2.1