Make it possible to filter by function, module and file info.
authorMilian Wolff <mail@milianw.de>
Sun, 7 Jun 2015 16:59:07 +0000 (18:59 +0200)
committerMilian Wolff <mail@milianw.de>
Sun, 7 Jun 2015 16:59:07 +0000 (18:59 +0200)
gui/mainwindow.cpp
gui/mainwindow.ui
gui/proxy.cpp
gui/proxy.h

index ed8a6d4..ac4bf69 100644 (file)
@@ -43,8 +43,12 @@ MainWindow::MainWindow(QWidget* parent)
     connect(m_model, &Model::dataReady,
             this, &MainWindow::dataReady);
 
-    connect(m_ui->filter, &QLineEdit::textChanged,
-            proxy, &QSortFilterProxyModel::setFilterFixedString);
+    connect(m_ui->filterFunction, &QLineEdit::textChanged,
+            proxy, &Proxy::setFunctionFilter);
+    connect(m_ui->filterFile, &QLineEdit::textChanged,
+            proxy, &Proxy::setFileFilter);
+    connect(m_ui->filterModule, &QLineEdit::textChanged,
+            proxy, &Proxy::setModuleFilter);
 }
 
 MainWindow::~MainWindow()
index 98523d5..21e30b9 100644 (file)
      </widget>
     </item>
     <item>
-     <widget class="QLineEdit" name="filter">
-      <property name="placeholderText">
-       <string>filter...</string>
-      </property>
+     <widget class="QWidget" name="widget" native="true">
+      <layout class="QHBoxLayout" name="horizontalLayout">
+       <property name="spacing">
+        <number>0</number>
+       </property>
+       <property name="leftMargin">
+        <number>0</number>
+       </property>
+       <property name="topMargin">
+        <number>0</number>
+       </property>
+       <property name="rightMargin">
+        <number>0</number>
+       </property>
+       <property name="bottomMargin">
+        <number>0</number>
+       </property>
+       <item>
+        <widget class="QLineEdit" name="filterFunction">
+         <property name="placeholderText">
+          <string>filter by function...</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="filterFile">
+         <property name="placeholderText">
+          <string>filter by file...</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="filterModule">
+         <property name="placeholderText">
+          <string>filter by module...</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
      </widget>
     </item>
     <item>
index 4b15a80..b5ce5ff 100644 (file)
@@ -28,21 +28,47 @@ Proxy::Proxy(QObject* parent)
 
 Proxy::~Proxy() = default;
 
-bool Proxy::acceptRow(int source_row, const QModelIndex& source_parent) const
+void Proxy::setFunctionFilter(const QString& functionFilter)
+{
+    m_functionFilter = functionFilter;
+    invalidate();
+}
+
+void Proxy::setFileFilter(const QString& fileFilter)
+{
+    m_fileFilter = fileFilter;
+    invalidate();
+}
+
+void Proxy::setModuleFilter(const QString& moduleFilter)
+{
+    m_moduleFilter = moduleFilter;
+    invalidate();
+}
+
+bool Proxy::acceptRow(int sourceRow, const QModelIndex& sourceParent) const
 {
     auto source = sourceModel();
     if (!source) {
         return false;
     }
-    const auto& needle = filterRegExp().pattern();
-    if (needle.isEmpty()) {
-        return true;
+    if (!m_functionFilter.isEmpty()) {
+        const auto& function = source->index(sourceRow, Model::FunctionColumn, sourceParent).data().toString();
+        if (!function.contains(m_functionFilter)) {
+            return false;
+        }
+    }
+    if (!m_fileFilter.isEmpty()) {
+        const auto& file = source->index(sourceRow, Model::FileColumn, sourceParent).data().toString();
+        if (!file.contains(m_fileFilter)) {
+            return false;
+        }
     }
-    for (auto column : {Model::FunctionColumn, Model::FileColumn, Model::ModuleColumn}) {
-        const auto& haystack = source->index(source_row, column, source_parent).data(Qt::DisplayRole).toString();
-        if (haystack.contains(needle)) {
-            return true;
+    if (!m_moduleFilter.isEmpty()) {
+        const auto& module = source->index(sourceRow, Model::ModuleColumn, sourceParent).data().toString();
+        if (!module.contains(m_moduleFilter)) {
+            return false;
         }
     }
-    return false;
+    return true;
 }
index 2b6494c..ebc3991 100644 (file)
@@ -29,8 +29,17 @@ public:
     explicit Proxy(QObject* parent);
     virtual ~Proxy();
 
-protected:
+public slots:
+    void setFunctionFilter(const QString& functionFilter);
+    void setFileFilter(const QString& fileFilter);
+    void setModuleFilter(const QString& moduleFilter);
+
+private:
     bool acceptRow(int source_row, const QModelIndex& source_parent) const override;
+
+    QString m_functionFilter;
+    QString m_fileFilter;
+    QString m_moduleFilter;
 };
 
 #endif // PROXY_H