UI: RuleEdit: Hide empty Preset Rules list

This commit is contained in:
Nodir Temirkhodjaev 2024-04-03 10:56:57 +03:00
parent 8d7dcb147b
commit 78900b97b8
4 changed files with 29 additions and 6 deletions

View File

@ -76,6 +76,8 @@ void RuleEditDialog::initializeRuleSet()
confRuleManager()->loadRuleSet(m_ruleRow, ruleSetNames); confRuleManager()->loadRuleSet(m_ruleRow, ruleSetNames);
ruleSetModel()->initialize(m_ruleRow, ruleSetNames); ruleSetModel()->initialize(m_ruleRow, ruleSetNames);
updateRuleSetViewVisible();
} }
void RuleEditDialog::initializeFocus() void RuleEditDialog::initializeFocus()
@ -270,11 +272,8 @@ QLayout *RuleEditDialog::setupZonesLayout()
QLayout *RuleEditDialog::setupRuleSetHeaderLayout() QLayout *RuleEditDialog::setupRuleSetHeaderLayout()
{ {
m_btAddPresetRule = ControlUtil::createFlatToolButton(":/icons/add.png", [&] { m_btAddPresetRule =
selectPresetRuleDialog(); ControlUtil::createFlatToolButton(":/icons/add.png", [&] { selectPresetRuleDialog(); });
// m_ruleSetView->setVisible(false);
});
m_btRemovePresetRule = ControlUtil::createFlatToolButton( m_btRemovePresetRule = ControlUtil::createFlatToolButton(
":/icons/delete.png", [&] { ruleSetModel()->remove(ruleSetCurrentIndex()); }); ":/icons/delete.png", [&] { ruleSetModel()->remove(ruleSetCurrentIndex()); });
m_btUpPresetRule = ControlUtil::createIconToolButton( m_btUpPresetRule = ControlUtil::createIconToolButton(
@ -298,6 +297,9 @@ void RuleEditDialog::setupRuleSetView()
m_ruleSetView->setAlternatingRowColors(true); m_ruleSetView->setAlternatingRowColors(true);
m_ruleSetView->setModel(ruleSetModel()); m_ruleSetView->setModel(ruleSetModel());
connect(ruleSetModel(), &RuleSetModel::rowCountChanged, this,
&RuleEditDialog::updateRuleSetViewVisible);
} }
QLayout *RuleEditDialog::setupButtons() QLayout *RuleEditDialog::setupButtons()
@ -335,6 +337,13 @@ void RuleEditDialog::setupRuleSetViewChanged()
connect(m_ruleSetView, &ListView::currentIndexChanged, this, refreshRuleSetViewChanged); connect(m_ruleSetView, &ListView::currentIndexChanged, this, refreshRuleSetViewChanged);
} }
void RuleEditDialog::updateRuleSetViewVisible()
{
const int ruleSetSize = ruleSetModel()->rowCount();
m_ruleSetView->setVisible(ruleSetSize > 0);
}
int RuleEditDialog::ruleSetCurrentIndex() const int RuleEditDialog::ruleSetCurrentIndex() const
{ {
return m_ruleSetView->currentRow(); return m_ruleSetView->currentRow();

View File

@ -56,6 +56,8 @@ private:
QLayout *setupButtons(); QLayout *setupButtons();
void setupRuleSetViewChanged(); void setupRuleSetViewChanged();
void updateRuleSetViewVisible();
int ruleSetCurrentIndex() const; int ruleSetCurrentIndex() const;
bool save(); bool save();

View File

@ -15,6 +15,15 @@ const QLoggingCategory LC("model.ruleSet");
RuleSetModel::RuleSetModel(QObject *parent) : StringListModel(parent) { } RuleSetModel::RuleSetModel(QObject *parent) : StringListModel(parent) { }
void RuleSetModel::setEdited(bool v)
{
m_edited = v;
if (m_edited) {
emit rowCountChanged();
}
}
ConfRuleManager *RuleSetModel::confRuleManager() const ConfRuleManager *RuleSetModel::confRuleManager() const
{ {
return IoC<ConfRuleManager>(); return IoC<ConfRuleManager>();

View File

@ -16,7 +16,7 @@ public:
explicit RuleSetModel(QObject *parent = nullptr); explicit RuleSetModel(QObject *parent = nullptr);
bool edited() const { return m_edited; } bool edited() const { return m_edited; }
void setEdited(bool v) { m_edited = v; } void setEdited(bool v);
const RuleSetList &ruleSet() const { return m_ruleSet; } const RuleSetList &ruleSet() const { return m_ruleSet; }
@ -24,6 +24,9 @@ public:
void initialize(const RuleRow &ruleRow, const QStringList &ruleSetNames); void initialize(const RuleRow &ruleRow, const QStringList &ruleSetNames);
signals:
void rowCountChanged();
public slots: public slots:
void addRule(const RuleRow &ruleRow); void addRule(const RuleRow &ruleRow);