mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:46:03 +00:00
UI: RuleEdit: Hide empty Preset Rules list
This commit is contained in:
parent
8d7dcb147b
commit
78900b97b8
@ -76,6 +76,8 @@ void RuleEditDialog::initializeRuleSet()
|
||||
confRuleManager()->loadRuleSet(m_ruleRow, ruleSetNames);
|
||||
|
||||
ruleSetModel()->initialize(m_ruleRow, ruleSetNames);
|
||||
|
||||
updateRuleSetViewVisible();
|
||||
}
|
||||
|
||||
void RuleEditDialog::initializeFocus()
|
||||
@ -270,11 +272,8 @@ QLayout *RuleEditDialog::setupZonesLayout()
|
||||
|
||||
QLayout *RuleEditDialog::setupRuleSetHeaderLayout()
|
||||
{
|
||||
m_btAddPresetRule = ControlUtil::createFlatToolButton(":/icons/add.png", [&] {
|
||||
selectPresetRuleDialog();
|
||||
|
||||
// m_ruleSetView->setVisible(false);
|
||||
});
|
||||
m_btAddPresetRule =
|
||||
ControlUtil::createFlatToolButton(":/icons/add.png", [&] { selectPresetRuleDialog(); });
|
||||
m_btRemovePresetRule = ControlUtil::createFlatToolButton(
|
||||
":/icons/delete.png", [&] { ruleSetModel()->remove(ruleSetCurrentIndex()); });
|
||||
m_btUpPresetRule = ControlUtil::createIconToolButton(
|
||||
@ -298,6 +297,9 @@ void RuleEditDialog::setupRuleSetView()
|
||||
m_ruleSetView->setAlternatingRowColors(true);
|
||||
|
||||
m_ruleSetView->setModel(ruleSetModel());
|
||||
|
||||
connect(ruleSetModel(), &RuleSetModel::rowCountChanged, this,
|
||||
&RuleEditDialog::updateRuleSetViewVisible);
|
||||
}
|
||||
|
||||
QLayout *RuleEditDialog::setupButtons()
|
||||
@ -335,6 +337,13 @@ void RuleEditDialog::setupRuleSetViewChanged()
|
||||
connect(m_ruleSetView, &ListView::currentIndexChanged, this, refreshRuleSetViewChanged);
|
||||
}
|
||||
|
||||
void RuleEditDialog::updateRuleSetViewVisible()
|
||||
{
|
||||
const int ruleSetSize = ruleSetModel()->rowCount();
|
||||
|
||||
m_ruleSetView->setVisible(ruleSetSize > 0);
|
||||
}
|
||||
|
||||
int RuleEditDialog::ruleSetCurrentIndex() const
|
||||
{
|
||||
return m_ruleSetView->currentRow();
|
||||
|
@ -56,6 +56,8 @@ private:
|
||||
QLayout *setupButtons();
|
||||
void setupRuleSetViewChanged();
|
||||
|
||||
void updateRuleSetViewVisible();
|
||||
|
||||
int ruleSetCurrentIndex() const;
|
||||
|
||||
bool save();
|
||||
|
@ -15,6 +15,15 @@ const QLoggingCategory LC("model.ruleSet");
|
||||
|
||||
RuleSetModel::RuleSetModel(QObject *parent) : StringListModel(parent) { }
|
||||
|
||||
void RuleSetModel::setEdited(bool v)
|
||||
{
|
||||
m_edited = v;
|
||||
|
||||
if (m_edited) {
|
||||
emit rowCountChanged();
|
||||
}
|
||||
}
|
||||
|
||||
ConfRuleManager *RuleSetModel::confRuleManager() const
|
||||
{
|
||||
return IoC<ConfRuleManager>();
|
||||
|
@ -16,7 +16,7 @@ public:
|
||||
explicit RuleSetModel(QObject *parent = nullptr);
|
||||
|
||||
bool edited() const { return m_edited; }
|
||||
void setEdited(bool v) { m_edited = v; }
|
||||
void setEdited(bool v);
|
||||
|
||||
const RuleSetList &ruleSet() const { return m_ruleSet; }
|
||||
|
||||
@ -24,6 +24,9 @@ public:
|
||||
|
||||
void initialize(const RuleRow &ruleRow, const QStringList &ruleSetNames);
|
||||
|
||||
signals:
|
||||
void rowCountChanged();
|
||||
|
||||
public slots:
|
||||
void addRule(const RuleRow &ruleRow);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user