ruleitem: use std::unique_ptr

This commit is contained in:
Xaver Hugl 2022-11-14 00:37:28 +01:00
parent 65e886cde2
commit 95599d2ffd
2 changed files with 6 additions and 14 deletions

View file

@ -24,18 +24,11 @@ RuleItem::RuleItem(const QString &key,
, m_description(description) , m_description(description)
, m_flags(NoFlags) , m_flags(NoFlags)
, m_enabled(false) , m_enabled(false)
, m_policy(new RulePolicy(policyType)) , m_policy(std::make_unique<RulePolicy>(policyType))
, m_options(nullptr)
{ {
reset(); reset();
} }
RuleItem::~RuleItem()
{
delete m_policy;
delete m_options;
}
void RuleItem::reset() void RuleItem::reset()
{ {
m_enabled = hasFlag(AlwaysEnabled) || hasFlag(StartEnabled); m_enabled = hasFlag(AlwaysEnabled) || hasFlag(StartEnabled);
@ -133,7 +126,7 @@ QVariant RuleItem::options() const
if (!m_options) { if (!m_options) {
return QVariant(); return QVariant();
} }
return QVariant::fromValue(m_options); return QVariant::fromValue(m_options.get());
} }
void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data) void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
@ -142,7 +135,7 @@ void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
return; return;
} }
if (!m_options) { if (!m_options) {
m_options = new OptionsModel({}, m_type == NetTypes); m_options = std::make_unique<OptionsModel>(QList<OptionsModel::Data>{}, m_type == NetTypes);
} }
m_options->updateModelData(data); m_options->updateModelData(data);
m_options->setValue(m_value); m_options->setValue(m_value);
@ -165,7 +158,7 @@ RulePolicy::Type RuleItem::policyType() const
QVariant RuleItem::policyModel() const QVariant RuleItem::policyModel() const
{ {
return QVariant::fromValue(m_policy); return QVariant::fromValue(m_policy.get());
} }
QString RuleItem::policyKey() const QString RuleItem::policyKey() const

View file

@ -54,7 +54,6 @@ public:
const QString &section, const QString &section,
const QIcon &icon = QIcon::fromTheme("window"), const QIcon &icon = QIcon::fromTheme("window"),
const QString &description = QString("")); const QString &description = QString(""));
~RuleItem();
QString key() const; QString key() const;
QString name() const; QString name() const;
@ -103,8 +102,8 @@ private:
QVariant m_value; QVariant m_value;
QVariant m_suggestedValue; QVariant m_suggestedValue;
RulePolicy *m_policy; std::unique_ptr<RulePolicy> m_policy;
OptionsModel *m_options; std::unique_ptr<OptionsModel> m_options;
}; };
} // namespace } // namespace