From 05aa2eb204ac3d0efb1b80139575f7a912dece7f Mon Sep 17 00:00:00 2001
From: Aurindam Jana <aurindam.jana@nokia.com>
Date: Mon, 26 Mar 2012 09:30:34 +0200
Subject: [PATCH] QmlJSInspector: Use FindToolBar instead of Filter

QtCreator uses the Find Tool Bar uniformly to search for strings.

Change-Id: I399661597120be3402432b0c99489174f7bf2d62
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
---
 src/plugins/qmljsinspector/qmljsinspector.cpp | 19 +++++------
 src/plugins/qmljsinspector/qmljsinspector.h   |  3 --
 .../qmljsinspector/qmljspropertyinspector.cpp | 32 +++----------------
 .../qmljsinspector/qmljspropertyinspector.h   | 18 -----------
 4 files changed, 13 insertions(+), 59 deletions(-)

diff --git a/src/plugins/qmljsinspector/qmljsinspector.cpp b/src/plugins/qmljsinspector/qmljsinspector.cpp
index ecc32a32f8f..c872bf2b25c 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljsinspector.cpp
@@ -86,6 +86,9 @@
 
 #include <extensionsystem/pluginmanager.h>
 
+#include <aggregation/aggregate.h>
+#include <find/treeviewfind.h>
+
 #include <QDebug>
 #include <QStringList>
 #include <QTimer>
@@ -149,7 +152,6 @@ InspectorUi::InspectorUi(QObject *parent)
     , m_listeningToEditorManager(false)
     , m_toolBar(0)
     , m_crumblePath(0)
-    , m_filterExp(0)
     , m_propertyInspector(0)
     , m_settings(new InspectorSettings(this))
     , m_clientProxy(0)
@@ -655,7 +657,6 @@ void InspectorUi::enable()
     m_toolBar->enable();
     m_crumblePath->setEnabled(true);
     m_propertyInspector->setEnabled(true);
-    m_filterExp->setEnabled(true);
 }
 
 void InspectorUi::disable()
@@ -663,7 +664,6 @@ void InspectorUi::disable()
     m_toolBar->disable();
     m_crumblePath->setEnabled(false);
     m_propertyInspector->setEnabled(false);
-    m_filterExp->setEnabled(false);
 }
 
 QmlDebugObjectReference InspectorUi::objectReferenceForLocation(const QString &fileName, int cursorPosition) const
@@ -742,15 +742,10 @@ void InspectorUi::setupDockWidgets()
     QWidget *pathAndFilterWidget = new StyledBackground;
     pathAndFilterWidget->setMaximumHeight(m_crumblePath->height());
 
-    m_filterExp = new Utils::FilterLineEdit;
-    m_filterExp->setPlaceholderText(tr("Filter properties"));
-    m_filterExp->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
-
     QHBoxLayout *pathAndFilterLayout = new QHBoxLayout(pathAndFilterWidget);
     pathAndFilterLayout->setMargin(0);
     pathAndFilterLayout->setSpacing(0);
     pathAndFilterLayout->addWidget(m_crumblePath);
-    pathAndFilterLayout->addWidget(m_filterExp);
 
     QVBoxLayout *wlay = new QVBoxLayout(inspectorWidget);
     wlay->setMargin(0);
@@ -758,10 +753,15 @@ void InspectorUi::setupDockWidgets()
     inspectorWidget->setLayout(wlay);
     wlay->addWidget(pathAndFilterWidget);
     wlay->addWidget(m_propertyInspector);
+    wlay->addWidget(new Core::FindToolBarPlaceHolder(inspectorWidget));
 
     QDockWidget *dock = mw->createDockWidget(Debugger::QmlLanguage, inspectorWidget);
     dock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
     dock->setTitleBarWidget(new QWidget(dock));
+
+    Aggregation::Aggregate *aggregate = new Aggregation::Aggregate();
+    aggregate->add(m_propertyInspector);
+    aggregate->add(new Find::TreeViewFind(m_propertyInspector));
 }
 
 void InspectorUi::crumblePathElementClicked(const QVariant &data)
@@ -893,9 +893,6 @@ void InspectorUi::connectSignals()
             m_clientProxy, SLOT(changeToSelectTool()));
     connect(m_toolBar, SIGNAL(showAppOnTopSelected(bool)),
             m_clientProxy, SLOT(showAppOnTop(bool)));
-
-    connect(m_filterExp, SIGNAL(textChanged(QString)),
-            m_propertyInspector, SLOT(filterBy(QString)));
 }
 
 void InspectorUi::disconnectSignals()
diff --git a/src/plugins/qmljsinspector/qmljsinspector.h b/src/plugins/qmljsinspector/qmljsinspector.h
index 6bebf448143..815c1dd33e6 100644
--- a/src/plugins/qmljsinspector/qmljsinspector.h
+++ b/src/plugins/qmljsinspector/qmljsinspector.h
@@ -44,8 +44,6 @@
 #include <QAction>
 #include <QObject>
 
-QT_FORWARD_DECLARE_CLASS(QLineEdit)
-
 namespace ProjectExplorer {
 class Project;
 class Environment;
@@ -155,7 +153,6 @@ private:
     bool m_listeningToEditorManager;
     QmlJsInspectorToolBar *m_toolBar;
     ContextCrumblePath *m_crumblePath;
-    QLineEdit *m_filterExp;
     QmlJSPropertyInspector *m_propertyInspector;
 
     InspectorSettings *m_settings;
diff --git a/src/plugins/qmljsinspector/qmljspropertyinspector.cpp b/src/plugins/qmljsinspector/qmljspropertyinspector.cpp
index 412b3b7511e..0c1c4d2672c 100644
--- a/src/plugins/qmljsinspector/qmljspropertyinspector.cpp
+++ b/src/plugins/qmljsinspector/qmljspropertyinspector.cpp
@@ -239,20 +239,6 @@ void ColorChooserDialog::acceptColor(const QColor &color)
     emit dataChanged(m_debugId, m_paramName, QChar('\"')+color.name()+QChar('\"'));
 }
 
-// *************************************************************************
-//  FILTER
-// *************************************************************************
-bool PropertiesFilter::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
-{
-    QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent);
-    QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
-    QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
-
-    return (sourceModel()->data(index0).toString().contains(filterRegExp())
-                    || sourceModel()->data(index1).toString().contains(filterRegExp())
-                    || sourceModel()->data(index2).toString().contains(filterRegExp()));
-}
-
 // *************************************************************************
 //  QmlJSObjectTree
 // *************************************************************************
@@ -278,15 +264,7 @@ QmlJSPropertyInspector::QmlJSPropertyInspector(QWidget *parent)
 
     setItemDelegateForColumn(1, new PropertyEditDelegate(this));
 
-    m_filter = new PropertiesFilter(this);
-    m_filter->setSourceModel(&m_model);
-    setModel(m_filter);
-}
-
-void QmlJSPropertyInspector::filterBy(const QString &expression)
-{
-    m_filter->setFilterWildcard(expression);
-    m_filter->setFilterCaseSensitivity(Qt::CaseInsensitive);
+    setModel(&m_model);
 }
 
 void QmlJSPropertyInspector::clear()
@@ -310,12 +288,12 @@ void QmlJSPropertyInspector::setCurrentObjects(const QList<QmlDebugObjectReferen
 
 QVariant QmlJSPropertyInspector::getData(int row, int column, int role) const
 {
-    return m_filter->data(m_filter->index(row, column), role);
+    return m_model.data(m_model.index(row, column), role);
 }
 
 QmlJSPropertyInspector::PropertyType QmlJSPropertyInspector::getTypeFor(int row) const
 {
-    return static_cast<QmlJSPropertyInspector::PropertyType>(m_filter->data(m_filter->index(row,2),Qt::UserRole).toInt());
+    return static_cast<QmlJSPropertyInspector::PropertyType>(m_model.data(m_model.index(row,2), Qt::UserRole).toInt());
 }
 
 void QmlJSPropertyInspector::propertyValueChanged(int debugId, const QByteArray &propertyName, const QVariant &propertyValue)
@@ -435,7 +413,7 @@ void QmlJSPropertyInspector::addRow(const QString &name,const QString &value, co
 
 void QmlJSPropertyInspector::setColorIcon(int row)
 {
-    QStandardItem *item = m_model.itemFromIndex(m_model.index(row, 1));
+    QStandardItem *item = m_model.item(row, 1);
     QColor color = colorFromExtendedName(item->data(Qt::DisplayRole).toString());
 
     int recomendedLength = viewOptions().decorationSize.height() - 2;
@@ -457,7 +435,7 @@ void QmlJSPropertyInspector::contextMenuEvent(QContextMenuEvent *ev)
     bool isEditable = false;
     bool isColor = false;
     if (itemIndex.isValid()) {
-        isEditable = m_model.itemFromIndex(m_filter->mapToSource(m_filter->index(itemIndex.row(), 1)))->isEditable();
+        isEditable = m_model.item(itemIndex.row(), 1)->isEditable();
         isColor = (getTypeFor(itemIndex.row()) == QmlJSPropertyInspector::ColorType);
     }
 
diff --git a/src/plugins/qmljsinspector/qmljspropertyinspector.h b/src/plugins/qmljsinspector/qmljspropertyinspector.h
index 7962e55ae25..6ce6027f8e8 100644
--- a/src/plugins/qmljsinspector/qmljspropertyinspector.h
+++ b/src/plugins/qmljsinspector/qmljspropertyinspector.h
@@ -35,7 +35,6 @@
 #include <qmljsprivateapi.h>
 #include <QTreeView>
 #include <QStandardItemModel>
-#include <QSortFilterProxyModel>
 
 #include <QDialog>
 #include <QDialogButtonBox>
@@ -51,21 +50,6 @@ namespace Internal {
 
 class PropertyEditDelegate;
 
-class PropertiesFilter : public QSortFilterProxyModel
-{
-    Q_OBJECT
-public:
-    explicit PropertiesFilter(QObject *parent = 0)
-        : QSortFilterProxyModel(parent)
-    {
-        setDynamicSortFilter(true);
-    }
-
-    ~PropertiesFilter() { }
-
-    bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
-};
-
 class ExpressionEdit : public QDialog
 {
     Q_OBJECT
@@ -132,7 +116,6 @@ public slots:
     void setCurrentObjects(const QList<QmlDebugObjectReference> &);
     void propertyValueEdited(const int objectId,const QString &propertyName, const QString &propertyValue);
     void propertyValueChanged(int debugId, const QByteArray &propertyName, const QVariant &propertyValue);
-    void filterBy(const QString &expression);
 
     void openExpressionEditor(const QModelIndex &itemIndex);
     void openColorSelector(const QModelIndex &itemIndex);
@@ -150,7 +133,6 @@ private:
     void contextMenuEvent(QContextMenuEvent *ev);
 
     QStandardItemModel m_model;
-    PropertiesFilter *m_filter;
     QList<int> m_currentObjects;
 };
 
-- 
GitLab