mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:57:24 +00:00
UI: Rules: Add "Search" field
This commit is contained in:
parent
9ec02b4e81
commit
2c2268ea1f
@ -1,6 +1,7 @@
|
||||
#include "ruleswindow.h"
|
||||
|
||||
#include <QHeaderView>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
@ -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();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <form/windowtypes.h>
|
||||
#include <util/window/widgetwindow.h>
|
||||
|
||||
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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user