UI: RuleEdit: Remove Preset Rule

This commit is contained in:
Nodir Temirkhodjaev 2024-04-02 20:32:46 +03:00
parent 23eeca9ed9
commit 088293b3bb
4 changed files with 38 additions and 4 deletions

View File

@ -174,6 +174,9 @@ QLayout *RuleEditDialog::setupMainLayout()
// RuleSet View // RuleSet View
setupRuleSetView(); setupRuleSetView();
// Actions on rule set view's current changed
setupRuleSetViewChanged();
// OK/Cancel // OK/Cancel
auto buttonsLayout = setupButtons(); auto buttonsLayout = setupButtons();
@ -270,10 +273,10 @@ QLayout *RuleEditDialog::setupRuleSetHeaderLayout()
m_btAddPresetRule = ControlUtil::createFlatToolButton(":/icons/add.png", [&] { m_btAddPresetRule = ControlUtil::createFlatToolButton(":/icons/add.png", [&] {
selectPresetRuleDialog(); selectPresetRuleDialog();
m_ruleSetView->setVisible(true); // m_ruleSetView->setVisible(false);
}); });
m_btRemovePresetRule = ControlUtil::createFlatToolButton(":/icons/delete.png", [&] { m_btRemovePresetRule = ControlUtil::createFlatToolButton(":/icons/delete.png", [&] {
// TODO ruleSetModel()->remove(ruleSetCurrentIndex());
}); });
m_btUpPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_up.png", [&] { m_btUpPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_up.png", [&] {
// TODO // TODO
@ -298,8 +301,6 @@ void RuleEditDialog::setupRuleSetView()
m_ruleSetView->setAlternatingRowColors(true); m_ruleSetView->setAlternatingRowColors(true);
m_ruleSetView->setModel(ruleSetModel()); m_ruleSetView->setModel(ruleSetModel());
m_ruleSetView->setVisible(false);
} }
QLayout *RuleEditDialog::setupButtons() QLayout *RuleEditDialog::setupButtons()
@ -323,6 +324,25 @@ QLayout *RuleEditDialog::setupButtons()
return layout; return layout;
} }
void RuleEditDialog::setupRuleSetViewChanged()
{
const auto refreshRuleSetViewChanged = [&] {
const bool ruleSelected = (ruleSetCurrentIndex() >= 0);
m_btRemovePresetRule->setEnabled(ruleSelected);
m_btUpPresetRule->setEnabled(ruleSelected);
m_btDownPresetRule->setEnabled(ruleSelected);
};
refreshRuleSetViewChanged();
connect(m_ruleSetView, &ListView::currentIndexChanged, this, refreshRuleSetViewChanged);
}
int RuleEditDialog::ruleSetCurrentIndex() const
{
return m_ruleSetView->currentRow();
}
bool RuleEditDialog::save() bool RuleEditDialog::save()
{ {
if (!validateFields()) if (!validateFields())

View File

@ -54,6 +54,9 @@ private:
QLayout *setupRuleSetHeaderLayout(); QLayout *setupRuleSetHeaderLayout();
void setupRuleSetView(); void setupRuleSetView();
QLayout *setupButtons(); QLayout *setupButtons();
void setupRuleSetViewChanged();
int ruleSetCurrentIndex() const;
bool save(); bool save();
bool saveRule(Rule &rule); bool saveRule(Rule &rule);

View File

@ -50,3 +50,12 @@ void RuleSetModel::addRule(const RuleRow &ruleRow)
setEdited(true); setEdited(true);
} }
void RuleSetModel::remove(int row)
{
m_ruleSet.remove(row);
StringListModel::remove(row);
setEdited(true);
}

View File

@ -27,6 +27,8 @@ public:
public slots: public slots:
void addRule(const RuleRow &ruleRow); void addRule(const RuleRow &ruleRow);
void remove(int row = -1) override;
private: private:
bool m_edited = false; bool m_edited = false;