mirror of
https://github.com/tnodir/fort
synced 2024-11-15 07:45:22 +00:00
UI: RuleEdit: Remove Preset Rule
This commit is contained in:
parent
23eeca9ed9
commit
088293b3bb
@ -174,6 +174,9 @@ QLayout *RuleEditDialog::setupMainLayout()
|
||||
// RuleSet View
|
||||
setupRuleSetView();
|
||||
|
||||
// Actions on rule set view's current changed
|
||||
setupRuleSetViewChanged();
|
||||
|
||||
// OK/Cancel
|
||||
auto buttonsLayout = setupButtons();
|
||||
|
||||
@ -270,10 +273,10 @@ QLayout *RuleEditDialog::setupRuleSetHeaderLayout()
|
||||
m_btAddPresetRule = ControlUtil::createFlatToolButton(":/icons/add.png", [&] {
|
||||
selectPresetRuleDialog();
|
||||
|
||||
m_ruleSetView->setVisible(true);
|
||||
// m_ruleSetView->setVisible(false);
|
||||
});
|
||||
m_btRemovePresetRule = ControlUtil::createFlatToolButton(":/icons/delete.png", [&] {
|
||||
// TODO
|
||||
ruleSetModel()->remove(ruleSetCurrentIndex());
|
||||
});
|
||||
m_btUpPresetRule = ControlUtil::createIconToolButton(":/icons/bullet_arrow_up.png", [&] {
|
||||
// TODO
|
||||
@ -298,8 +301,6 @@ void RuleEditDialog::setupRuleSetView()
|
||||
m_ruleSetView->setAlternatingRowColors(true);
|
||||
|
||||
m_ruleSetView->setModel(ruleSetModel());
|
||||
|
||||
m_ruleSetView->setVisible(false);
|
||||
}
|
||||
|
||||
QLayout *RuleEditDialog::setupButtons()
|
||||
@ -323,6 +324,25 @@ QLayout *RuleEditDialog::setupButtons()
|
||||
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()
|
||||
{
|
||||
if (!validateFields())
|
||||
|
@ -54,6 +54,9 @@ private:
|
||||
QLayout *setupRuleSetHeaderLayout();
|
||||
void setupRuleSetView();
|
||||
QLayout *setupButtons();
|
||||
void setupRuleSetViewChanged();
|
||||
|
||||
int ruleSetCurrentIndex() const;
|
||||
|
||||
bool save();
|
||||
bool saveRule(Rule &rule);
|
||||
|
@ -50,3 +50,12 @@ void RuleSetModel::addRule(const RuleRow &ruleRow)
|
||||
|
||||
setEdited(true);
|
||||
}
|
||||
|
||||
void RuleSetModel::remove(int row)
|
||||
{
|
||||
m_ruleSet.remove(row);
|
||||
|
||||
StringListModel::remove(row);
|
||||
|
||||
setEdited(true);
|
||||
}
|
||||
|
@ -27,6 +27,8 @@ public:
|
||||
public slots:
|
||||
void addRule(const RuleRow &ruleRow);
|
||||
|
||||
void remove(int row = -1) override;
|
||||
|
||||
private:
|
||||
bool m_edited = false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user