diff --git a/src/ui/form/rule/ruleswindow.cpp b/src/ui/form/rule/ruleswindow.cpp index 66247027..5d8b3823 100644 --- a/src/ui/form/rule/ruleswindow.cpp +++ b/src/ui/form/rule/ruleswindow.cpp @@ -1,6 +1,7 @@ #include "ruleswindow.h" #include +#include #include #include #include @@ -111,6 +112,7 @@ void RulesWindow::retranslateUi() m_actAddRule->setText(tr("Add")); m_actEditRule->setText(tr("Edit")); m_actRemoveRule->setText(tr("Remove")); + m_editSearch->setPlaceholderText(tr("Search")); ruleListModel()->refresh(); @@ -173,14 +175,30 @@ QLayout *RulesWindow::setupHeader() m_btEdit = ControlUtil::createButton(":/icons/pencil.png"); m_btEdit->setMenu(editMenu); + // Search field + setupEditSearch(); + // Menu button m_btMenu = windowManager()->createMenuButton(); - auto layout = ControlUtil::createHLayoutByWidgets({ m_btEdit, /*stretch*/ nullptr, m_btMenu }); + auto layout = ControlUtil::createHLayoutByWidgets({ m_btEdit, ControlUtil::createVSeparator(), + m_editSearch, /*stretch*/ nullptr, m_btMenu }); return layout; } +void RulesWindow::setupEditSearch() +{ + m_editSearch = ControlUtil::createLineEdit( + QString(), [&](const QString &text) { ruleListModel()->setFtsFilter(text); }); + m_editSearch->setClearButtonEnabled(true); + m_editSearch->setMaxLength(200); + m_editSearch->setMinimumWidth(100); + m_editSearch->setMaximumWidth(200); + + connect(this, &RulesWindow::aboutToShow, m_editSearch, qOverload<>(&QWidget::setFocus)); +} + void RulesWindow::setupTableRules() { m_ruleListView = new TableView(); diff --git a/src/ui/form/rule/ruleswindow.h b/src/ui/form/rule/ruleswindow.h index 6f97cbac..8baf0f94 100644 --- a/src/ui/form/rule/ruleswindow.h +++ b/src/ui/form/rule/ruleswindow.h @@ -4,6 +4,7 @@ #include
#include +QT_FORWARD_DECLARE_CLASS(QLineEdit) QT_FORWARD_DECLARE_CLASS(QPushButton) QT_FORWARD_DECLARE_CLASS(QToolButton) @@ -48,6 +49,7 @@ private: void setupUi(); QLayout *setupHeader(); + void setupEditSearch(); void setupTableRules(); void setupTableRulesHeader(); void setupTableRulesChanged(); @@ -71,6 +73,7 @@ private: QAction *m_actAddRule = nullptr; QAction *m_actEditRule = nullptr; QAction *m_actRemoveRule = nullptr; + QLineEdit *m_editSearch = nullptr; QPushButton *m_btMenu = nullptr; TableView *m_ruleListView = nullptr; diff --git a/src/ui/model/rulelistmodel.cpp b/src/ui/model/rulelistmodel.cpp index 86b55e5d..9bd4436f 100644 --- a/src/ui/model/rulelistmodel.cpp +++ b/src/ui/model/rulelistmodel.cpp @@ -184,23 +184,33 @@ const RuleRow &RuleListModel::ruleRowAt(int row) const } bool RuleListModel::updateTableRow(int row) const +{ + QVariantList vars; + fillSqlVars(vars); + vars.append(row); // must be a last one for :OFFSET + + return updateRuleRow(sql(), vars, m_ruleRow); +} + +bool RuleListModel::updateRuleRow( + const QString &sql, const QVariantList &vars, RuleRow &ruleRow) const { SqliteStmt stmt; - if (!(sqliteDb()->prepare(stmt, sql(), { row }) && stmt.step() == SqliteStmt::StepRow)) { - m_ruleRow.invalidate(); + if (!(sqliteDb()->prepare(stmt, sql, vars) && stmt.step() == SqliteStmt::StepRow)) { + ruleRow.invalidate(); return false; } - m_ruleRow.ruleId = stmt.columnInt(0); - m_ruleRow.enabled = stmt.columnBool(1); - m_ruleRow.blocked = stmt.columnBool(2); - m_ruleRow.exclusive = stmt.columnBool(3); - m_ruleRow.ruleName = stmt.columnText(4); - m_ruleRow.notes = stmt.columnText(5); - m_ruleRow.ruleText = stmt.columnText(6); - m_ruleRow.acceptZones = stmt.columnUInt(7); - m_ruleRow.rejectZones = stmt.columnUInt(8); - m_ruleRow.modTime = stmt.columnDateTime(9); + ruleRow.ruleId = stmt.columnInt(0); + ruleRow.enabled = stmt.columnBool(1); + ruleRow.blocked = stmt.columnBool(2); + ruleRow.exclusive = stmt.columnBool(3); + ruleRow.ruleName = stmt.columnText(4); + ruleRow.notes = stmt.columnText(5); + ruleRow.ruleText = stmt.columnText(6); + ruleRow.acceptZones = stmt.columnUInt(7); + ruleRow.rejectZones = stmt.columnUInt(8); + ruleRow.modTime = stmt.columnDateTime(9); return true; } diff --git a/src/ui/model/rulelistmodel.h b/src/ui/model/rulelistmodel.h index 5f71ad1a..3a3f312d 100644 --- a/src/ui/model/rulelistmodel.h +++ b/src/ui/model/rulelistmodel.h @@ -44,6 +44,8 @@ protected: bool updateTableRow(int row) const override; TableRow &tableRow() const override { return m_ruleRow; } + bool updateRuleRow(const QString &sql, const QVariantList &vars, RuleRow &ruleRow) const; + QString sqlBase() const override; QString sqlWhereFts() const override; QString sqlOrderColumn() const override;