diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2012-09-24 17:47:01 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2012-12-10 02:48:05 +0100 |
commit | 29e891b3b146540d69a6377f1a557b246e8b8c68 (patch) | |
tree | d5cff4e1d2ad4179013aab4dcaf366597f7702ca /src/history | |
parent | setting a decent minimum size... (diff) | |
download | rekonq-29e891b3b146540d69a6377f1a557b246e8b8c68.tar.xz |
rekonq new tab page restored :)
Diffstat (limited to 'src/history')
-rw-r--r-- | src/history/historymodels.cpp | 32 | ||||
-rw-r--r-- | src/history/historymodels.h | 31 |
2 files changed, 60 insertions, 3 deletions
diff --git a/src/history/historymodels.cpp b/src/history/historymodels.cpp index 9ffc2643..48cdc78e 100644 --- a/src/history/historymodels.cpp +++ b/src/history/historymodels.cpp @@ -741,3 +741,35 @@ void HistoryTreeModel::sourceRowsRemoved(const QModelIndex &parent, int start, i endRemoveRows(); } } + + +// ---------------------------------------------------------------------------------------------------------- + + +UrlFilterProxyModel::UrlFilterProxyModel(QObject *parent) + : QSortFilterProxyModel(parent) +{ + setFilterCaseSensitivity(Qt::CaseInsensitive); +} + + +bool UrlFilterProxyModel::filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const +{ + return recursiveMatch(sourceModel()->index(source_row, 0, source_parent)); +} + + +bool UrlFilterProxyModel::recursiveMatch(const QModelIndex &index) const +{ + if (index.data().toString().contains(filterRegExp())) + return true; + + 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/history/historymodels.h b/src/history/historymodels.h index 44569fa2..be0cb442 100644 --- a/src/history/historymodels.h +++ b/src/history/historymodels.h @@ -26,8 +26,8 @@ * ============================================================ */ -#ifndef HISTORYMODELS_H -#define HISTORYMODELS_H +#ifndef HISTORY_MODELS_H +#define HISTORY_MODELS_H // Rekonq Includes @@ -40,6 +40,7 @@ #include <QHash> #include <QAbstractTableModel> #include <QAbstractProxyModel> +#include <QSortFilterProxyModel> // Forward Declarations class HistoryManager; @@ -176,4 +177,28 @@ private: }; -#endif // HISTORYMODELS_H +// ---------------------------------------------------------------------------------------------------------------------- + + +/** + * QSortFilterProxyModel hides all children which parent doesn't + * match the filter. This class is used to change this behavior. + * If a url matches the filter it'll be shown, + * even if it's parent doesn't match it. + */ +class UrlFilterProxyModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + explicit UrlFilterProxyModel(QObject *parent = 0); + +protected: + virtual bool filterAcceptsRow(const int source_row, const QModelIndex &source_parent) const; + + // returns true if index or any of his children match the filter + bool recursiveMatch(const QModelIndex &index) const; +}; + + +#endif // HISTORY_MODELS_H |