summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/bookmarkspanel/bookmarkspanel.cpp26
-rw-r--r--src/bookmarkspanel/bookmarksproxy.cpp29
-rw-r--r--src/bookmarkspanel/bookmarksproxy.h48
4 files changed, 85 insertions, 19 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 6b3f9edf..4452df54 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -33,6 +33,7 @@ SET( rekonq_KDEINIT_SRCS
bookmarkspanel/bookmarkspanel.cpp
bookmarkspanel/bookmarkstreemodel.cpp
+ bookmarkspanel/bookmarksproxy.cpp
)
diff --git a/src/bookmarkspanel/bookmarkspanel.cpp b/src/bookmarkspanel/bookmarkspanel.cpp
index 1f3dff9b..a09e0058 100644
--- a/src/bookmarkspanel/bookmarkspanel.cpp
+++ b/src/bookmarkspanel/bookmarkspanel.cpp
@@ -27,6 +27,7 @@
// rekonq includes
#include "bookmarkspanel.h"
#include "bookmarkstreemodel.h"
+#include "bookmarksproxy.h"
// Auto Includes
#include "rekonq.h"
@@ -35,7 +36,6 @@
#include <QHBoxLayout>
#include <QLabel>
#include <QTreeView>
-#include <QSortFilterProxyModel>
#include <QHeaderView>
// KDE includes
@@ -74,11 +74,12 @@ void BookmarksPanel::setup()
// setup search bar
QHBoxLayout *searchLayout = new QHBoxLayout;
searchLayout->setContentsMargins(5, 0, 0, 0);
- QLabel *searchLabel = new QLabel(i18n("Search:"));
+ QLabel *searchLabel = new QLabel(i18n("&Search:"));
searchLayout->addWidget(searchLabel);
KLineEdit *search = new KLineEdit;
search->setClearButtonShown(true);
searchLayout->addWidget(search);
+ searchLabel->setBuddy( search );
// setup tree view
QTreeView *treeView = new QTreeView(ui);
@@ -100,23 +101,10 @@ void BookmarksPanel::setup()
setWidget(ui);
BookmarksTreeModel *model = new BookmarksTreeModel( this );
- treeView->setModel( model );
+ BookmarksProxy *proxy = new BookmarksProxy(ui);
+ proxy->setSourceModel( model );
+ treeView->setModel( proxy );
+ connect(search, SIGNAL(textChanged(QString)), proxy, SLOT(setFilterFixedString(QString)));
connect( treeView, SIGNAL( activated(QModelIndex) ), this, SLOT( bookmarkActivated(QModelIndex) ) );
-
-// QSortFilterProxyModel *proxy = new QSortFilterProxyModel(ui);
- //-
-// HistoryManager *historyManager = Application::historyManager();
-// QAbstractItemModel *model = historyManager->historyTreeModel();
-//
-// m_treeProxyModel->setSourceModel(model);
-// m_treeView->setModel(m_treeProxyModel);
-// m_treeView->setExpanded(m_treeProxyModel->index(0, 0), true);
-// m_treeView->header()->hideSection(1);
-// QFontMetrics fm(font());
-// int header = fm.width(QLatin1Char('m')) * 40;
-// m_treeView->header()->resizeSection(0, header);
-//
-// connect(search, SIGNAL(textChanged(QString)), m_treeProxy, SLOT(setFilterFixedString(QString)));
-// connect(m_treeView, SIGNAL(activated(const QModelIndex&)), this, SLOT(open()));
}
diff --git a/src/bookmarkspanel/bookmarksproxy.cpp b/src/bookmarkspanel/bookmarksproxy.cpp
new file mode 100644
index 00000000..87d1ce71
--- /dev/null
+++ b/src/bookmarkspanel/bookmarksproxy.cpp
@@ -0,0 +1,29 @@
+#include "bookmarksproxy.h"
+
+BookmarksProxy::BookmarksProxy( QObject *parent ):
+ QSortFilterProxyModel( parent )
+{
+}
+
+bool BookmarksProxy::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
+{
+ QModelIndex idx = sourceModel()->index( source_row, 0, source_parent );
+
+// return idx.data().toString().contains( filterRegExp() );
+ return recursiveMatch( idx );
+}
+
+bool BookmarksProxy::recursiveMatch( const QModelIndex &index ) const
+{
+ if( index.data().toString().contains( filterRegExp() ) ) {
+ return true;
+ }
+
+ for( int childRow = 0; childRow < sourceModel()->rowCount( index ); ++childRow ) {
+ if( recursiveMatch( sourceModel()->index( childRow, 0, index ) ) ) {
+ return true;
+ }
+ }
+
+ return false;
+}
diff --git a/src/bookmarkspanel/bookmarksproxy.h b/src/bookmarkspanel/bookmarksproxy.h
new file mode 100644
index 00000000..99483331
--- /dev/null
+++ b/src/bookmarkspanel/bookmarksproxy.h
@@ -0,0 +1,48 @@
+/* ============================================================
+*
+* This file is a part of the rekonq project
+*
+* Copyright (C) 2009 by Nils Weigel <nehlsen at gmail dot com>
+*
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License as
+* published by the Free Software Foundation; either version 2 of
+* the License or (at your option) version 3 or any later version
+* accepted by the membership of KDE e.V. (or its successor approved
+* by the membership of KDE e.V.), which shall act as a proxy
+* defined in Section 14 of version 3 of the license.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*
+* ============================================================ */
+
+
+#ifndef BOOKMARKSPROXY_H
+#define BOOKMARKSPROXY_H
+
+// Qt Includes
+#include <QSortFilterProxyModel>
+
+class BookmarksProxy : public QSortFilterProxyModel
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(BookmarksProxy)
+
+public:
+ BookmarksProxy( QObject *parent = 0 );
+
+protected:
+ virtual bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const;
+
+ // returns true if any child(or childs-child...) matches filter
+ bool recursiveMatch( const QModelIndex &index ) const;
+};
+
+#endif // BOOKMARKSPROXY_H