Browse Source

Better filtering

Minor fixes on how filters are set on the model and what columns to show in the TailTableEditWidget
Felix Turowsky 1 year ago
parent
commit
204567260f

+ 1 - 0
src/gui/widgets/airporttableeditwidget.cpp

@@ -64,6 +64,7 @@ EntryEditDialog *AirportTableEditWidget::getEntryEditDialog(QWidget *parent)
 void AirportTableEditWidget::filterTextChanged(const QString &filterString)
 {
     if(filterString.isEmpty()) {
+        model->setFilter(QString());
         return;
     }
 

+ 12 - 0
src/gui/widgets/tableeditwidget.h

@@ -113,7 +113,15 @@ private:
     void setupHorizontalUI();
     void setupVerticalUI();
     void setupSignalsAndSlots();
+
+    /*!
+     * \brief Place the filter items in a widget to facilitate easier placement in parent layout
+     */
     void setupFilterWidget();
+
+    /*!
+     * \brief Place the new and edit buttons in a widget to facilitate easier placement in parent layout
+     */
     void setupButtonWidget();
 
 private slots:
@@ -121,6 +129,10 @@ private slots:
     void editEntryRequested(const QModelIndex &selectedIndex);
     void deleteEntryRequested();
     void sortColumnChanged(int newSortColumn);
+
+    /*!
+     * \brief Set a filter on the model
+     */
     virtual void filterTextChanged(const QString &filterString) = 0;
 
 public slots:

+ 13 - 1
src/gui/widgets/tailtableeditwidget.cpp

@@ -95,5 +95,17 @@ EntryEditDialog *TailTableEditWidget::getEntryEditDialog(QWidget *parent)
 
 void TailTableEditWidget::filterTextChanged(const QString &filterString)
 {
-    TODO << "not implemented.";
+    if(filterString.isEmpty()) {
+        model->setFilter(QString());
+        return;
+    }
+
+    int i = filterSelectionComboBox->currentIndex();
+    const QString filter =
+        QLatin1Char('\"')
+        + FILTER_COLUMN_NAMES.at(i)
+        + QLatin1String("\" LIKE '%")
+        + filterString
+        + QLatin1String("%'");
+    model->setFilter(filter);
 }

+ 9 - 2
src/gui/widgets/tailtableeditwidget.h

@@ -2,6 +2,7 @@
 #define TAILTABLEEDITWIDGET_H
 
 #include "tableeditwidget.h"
+#include "src/database/tailentry.h"
 
 class TailTableEditWidget : public TableEditWidget
 {
@@ -21,9 +22,9 @@ private:
     const int COL_ROWID = 0;
     const int COL_REGISTRATION = 1;
     const int COL_TYPE = 10;
-    const int COL_COMPANY = 3;
+    const int COL_COMPANY = 2;
 
-    const int COLS_TO_HIDE[8] = {0, 2, 4, 5, 6, 7, 8, 9};
+    const int COLS_TO_HIDE[8] = {0, 3, 4, 5, 6, 7, 8, 9};
 
     const QString COLUMN_NAME_REGISTRATION = tr("Registration");
     const QString COLUMN_NAME_TYPE = tr("Type");
@@ -35,6 +36,12 @@ private:
         COLUMN_NAME_COMPANY,
     };
 
+    const static inline QStringList FILTER_COLUMN_NAMES = {
+        OPL::TailEntry::REGISTRATION,
+        OPL::TailEntry::TYPE_STRING,
+        OPL::TailEntry::COMPANY
+    };
+
 private slots:
 
     virtual void filterTextChanged(const QString &filterString) override;