mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:18:07 +00:00
UI: ProgramEdit: Edit Rule
This commit is contained in:
parent
9b7597ca66
commit
f622e39e0d
@ -612,12 +612,10 @@ QLayout *ProgramEditDialog::setupRuleLayout()
|
||||
m_btSelectRule = ControlUtil::createIconToolButton(":/icons/script.png", [&] {
|
||||
const int ruleId = VariantUtil::userData(m_editRuleName).toInt();
|
||||
if (ruleId != 0) {
|
||||
// Edit the Rule
|
||||
return;
|
||||
editRuleDialog(ruleId);
|
||||
} else {
|
||||
selectRuleDialog();
|
||||
}
|
||||
|
||||
// Select a Rule
|
||||
selectRuleDialog();
|
||||
});
|
||||
|
||||
auto layout = ControlUtil::createHLayoutByWidgets({ m_editRuleName, m_btSelectRule });
|
||||
@ -858,7 +856,7 @@ bool ProgramEditDialog::isWildcard() const
|
||||
|
||||
void ProgramEditDialog::selectRuleDialog()
|
||||
{
|
||||
auto rulesDialog = RulesWindow::showRulesDialog(this);
|
||||
auto rulesDialog = RulesWindow::showRulesDialog(Rule::AppRule, this);
|
||||
|
||||
connect(rulesDialog, &RulesWindow::ruleSelected, this, [&](const RuleRow &ruleRow) {
|
||||
VariantUtil::setUserData(m_editRuleName, ruleRow.ruleId);
|
||||
@ -866,6 +864,11 @@ void ProgramEditDialog::selectRuleDialog()
|
||||
});
|
||||
}
|
||||
|
||||
void ProgramEditDialog::editRuleDialog(int ruleId)
|
||||
{
|
||||
RulesWindow::showRuleEditDialog(ruleId, Rule::AppRule, this);
|
||||
}
|
||||
|
||||
void ProgramEditDialog::warnDangerousOption() const
|
||||
{
|
||||
IoC<WindowManager>()->showErrorBox(
|
||||
|
@ -102,6 +102,7 @@ private:
|
||||
bool isWildcard() const;
|
||||
|
||||
void selectRuleDialog();
|
||||
void editRuleDialog(int ruleId);
|
||||
|
||||
void warnDangerousOption() const;
|
||||
|
||||
|
@ -390,7 +390,7 @@ void RulesWindow::openRuleEditForm(const RuleRow &ruleRow)
|
||||
|
||||
m_formRuleEdit->initialize(ruleRow);
|
||||
|
||||
WidgetWindow::showWidget(m_formRuleEdit);
|
||||
DialogUtil::showDialog(m_formRuleEdit);
|
||||
}
|
||||
|
||||
void RulesWindow::deleteSelectedRule()
|
||||
@ -411,7 +411,7 @@ QModelIndex RulesWindow::ruleListCurrentIndex() const
|
||||
return m_ruleListView->currentIndex();
|
||||
}
|
||||
|
||||
RulesWindow *RulesWindow::showRulesDialog(QWidget *parent, Rule::RuleType ruleType)
|
||||
RulesWindow *RulesWindow::showRulesDialog(Rule::RuleType ruleType, QWidget *parent)
|
||||
{
|
||||
auto w = new RulesWindow(ruleType, parent, Qt::Dialog);
|
||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||
@ -420,3 +420,24 @@ RulesWindow *RulesWindow::showRulesDialog(QWidget *parent, Rule::RuleType ruleTy
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
RuleEditDialog *RulesWindow::showRuleEditDialog(
|
||||
int ruleId, Rule::RuleType ruleType, QWidget *parent)
|
||||
{
|
||||
auto ctrl = new RulesController();
|
||||
|
||||
auto w = new RuleEditDialog(ctrl, parent);
|
||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
ctrl->setParent(w);
|
||||
|
||||
// Initialize the Rule edit dialog
|
||||
{
|
||||
const auto ruleRow = ctrl->ruleListModel()->ruleRowById(ruleId, ruleType);
|
||||
w->initialize(ruleRow);
|
||||
}
|
||||
|
||||
DialogUtil::showDialog(w);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
@ -46,7 +46,8 @@ public:
|
||||
void saveWindowState(bool wasVisible) override;
|
||||
void restoreWindowState() override;
|
||||
|
||||
static RulesWindow *showRulesDialog(QWidget *parent, Rule::RuleType ruleType = Rule::AppRule);
|
||||
static RulesWindow *showRulesDialog(Rule::RuleType ruleType, QWidget *parent);
|
||||
static RuleEditDialog *showRuleEditDialog(int ruleId, Rule::RuleType ruleType, QWidget *parent);
|
||||
|
||||
signals:
|
||||
void ruleSelected(const RuleRow &ruleRow);
|
||||
|
@ -267,6 +267,19 @@ const RuleRow &RuleListModel::ruleRowAt(const QModelIndex &index) const
|
||||
return m_ruleRow;
|
||||
}
|
||||
|
||||
RuleRow RuleListModel::ruleRowById(int ruleId, Rule::RuleType ruleType) const
|
||||
{
|
||||
setSqlRuleType(ruleType);
|
||||
|
||||
QVariantHash vars;
|
||||
fillQueryVars(vars);
|
||||
vars.insert(":rule_id", ruleId);
|
||||
|
||||
RuleRow ruleRow;
|
||||
updateRuleRow(sqlBase() + " AND t.rule_id = :rule_id;", vars, ruleRow);
|
||||
return ruleRow;
|
||||
}
|
||||
|
||||
bool RuleListModel::updateTableRow(const QVariantHash &vars, int /*row*/) const
|
||||
{
|
||||
return updateRuleRow(sql(), vars, m_ruleRow);
|
||||
@ -324,7 +337,7 @@ QString RuleListModel::sqlOrderColumn() const
|
||||
return "rule_type, lower(name)";
|
||||
}
|
||||
|
||||
void RuleListModel::setSqlRuleType(quint8 v) const
|
||||
void RuleListModel::setSqlRuleType(qint8 v) const
|
||||
{
|
||||
if (m_sqlRuleType == v)
|
||||
return;
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
Qt::ItemFlags flagHasChildren(const QModelIndex &index) const override;
|
||||
|
||||
const RuleRow &ruleRowAt(const QModelIndex &index) const;
|
||||
RuleRow ruleRowById(int ruleId, Rule::RuleType ruleType) const;
|
||||
|
||||
static QStringList ruleTypeNames();
|
||||
|
||||
@ -69,7 +70,7 @@ protected:
|
||||
QString sqlOrderColumn() const override;
|
||||
|
||||
quint8 sqlRuleType() const { return m_sqlRuleType; }
|
||||
void setSqlRuleType(quint8 v) const;
|
||||
void setSqlRuleType(qint8 v) const;
|
||||
void setSqlRuleType(const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
@ -81,7 +82,7 @@ private:
|
||||
QVariant dataEnabled(const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
mutable quint8 m_sqlRuleType = 0;
|
||||
mutable qint8 m_sqlRuleType = 0;
|
||||
|
||||
mutable RuleRow m_ruleRow;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user