Provide a mask for flag-type properties (window types)
This commit is contained in:
parent
8b9472e0bf
commit
ad3d2f5acf
5 changed files with 31 additions and 14 deletions
|
@ -118,8 +118,8 @@ Loader {
|
||||||
flat: true
|
flat: true
|
||||||
model: ruleOptions
|
model: ruleOptions
|
||||||
multipleChoice: true
|
multipleChoice: true
|
||||||
// If NET::AllTypesMask (-1), select everything
|
// Filter the provided value with the options mask
|
||||||
selectionMask: (ruleValue == -1) ? 0x3BF : ruleValue
|
selectionMask: ruleValue & optionsMask
|
||||||
onActivated: {
|
onActivated: {
|
||||||
valueEditor.valueEdited(selectionMask);
|
valueEditor.valueEdited(selectionMask);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ RuleItem::RuleItem(const QString &key,
|
||||||
, m_enabled(false)
|
, m_enabled(false)
|
||||||
, m_policy(new RulePolicy(policyType))
|
, m_policy(new RulePolicy(policyType))
|
||||||
, m_options(nullptr)
|
, m_options(nullptr)
|
||||||
|
, m_optionsMask(0U - 1)
|
||||||
{
|
{
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
@ -54,7 +55,7 @@ RuleItem::~RuleItem()
|
||||||
void RuleItem::reset()
|
void RuleItem::reset()
|
||||||
{
|
{
|
||||||
m_enabled = hasFlag(AlwaysEnabled) | hasFlag(StartEnabled);
|
m_enabled = hasFlag(AlwaysEnabled) | hasFlag(StartEnabled);
|
||||||
m_value = typedValue(QVariant(), m_type);
|
m_value = typedValue(QVariant());
|
||||||
m_suggestedValue = QVariant();
|
m_suggestedValue = QVariant();
|
||||||
m_policy->resetValue();
|
m_policy->resetValue();
|
||||||
if (m_options) {
|
if (m_options) {
|
||||||
|
@ -130,7 +131,7 @@ void RuleItem::setValue(QVariant value)
|
||||||
if (m_options && m_type == Option) {
|
if (m_options && m_type == Option) {
|
||||||
m_options->setValue(value);
|
m_options->setValue(value);
|
||||||
}
|
}
|
||||||
m_value = typedValue(value, m_type);
|
m_value = typedValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RuleItem::suggestedValue() const
|
QVariant RuleItem::suggestedValue() const
|
||||||
|
@ -143,7 +144,7 @@ void RuleItem::setSuggestedValue(QVariant value, bool forceValue)
|
||||||
if (forceValue) {
|
if (forceValue) {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
}
|
}
|
||||||
m_suggestedValue = value.isNull() ? QVariant() : typedValue(value, m_type);
|
m_suggestedValue = value.isNull() ? QVariant() : typedValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RuleItem::options() const
|
QVariant RuleItem::options() const
|
||||||
|
@ -164,6 +165,18 @@ void RuleItem::setOptionsData(const QList<OptionsModel::Data> &data)
|
||||||
}
|
}
|
||||||
m_options->updateModelData(data);
|
m_options->updateModelData(data);
|
||||||
m_options->setValue(m_value);
|
m_options->setValue(m_value);
|
||||||
|
|
||||||
|
if (m_type == NetTypes) {
|
||||||
|
m_optionsMask = 0;
|
||||||
|
for (const OptionsModel::Data &dataItem : data) {
|
||||||
|
m_optionsMask += 1 << dataItem.value.toUInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint RuleItem::optionsMask() const
|
||||||
|
{
|
||||||
|
return m_optionsMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
int RuleItem::policy() const
|
int RuleItem::policy() const
|
||||||
|
@ -191,9 +204,9 @@ QString RuleItem::policyKey() const
|
||||||
return m_policy->policyKey(m_key);
|
return m_policy->policyKey(m_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant RuleItem::typedValue(const QVariant &value, const RuleItem::Type type)
|
QVariant RuleItem::typedValue(const QVariant &value) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type()) {
|
||||||
case Undefined:
|
case Undefined:
|
||||||
case Option:
|
case Option:
|
||||||
return value;
|
return value;
|
||||||
|
@ -203,11 +216,11 @@ QVariant RuleItem::typedValue(const QVariant &value, const RuleItem::Type type)
|
||||||
case Percentage:
|
case Percentage:
|
||||||
return value.toInt();
|
return value.toInt();
|
||||||
case NetTypes: {
|
case NetTypes: {
|
||||||
const int usefulTypes = value.toInt() & 0x3BF; // remove NET::Override=0x040 (deprecated)
|
const uint typesMask = value.toUInt() & optionsMask(); // filter by the allowed mask in the model
|
||||||
if (usefulTypes == 0 || usefulTypes == 0x3BF) { // if no flags or all of them are selected
|
if (typesMask == 0 || typesMask == optionsMask()) { // if no types or all of them are selected
|
||||||
return -1; // return NET:AllTypesMask
|
return 0U - 1; // return an all active mask (NET:AllTypesMask)
|
||||||
}
|
}
|
||||||
return value.toInt();
|
return typesMask;
|
||||||
}
|
}
|
||||||
case Point:
|
case Point:
|
||||||
return value.toPoint();
|
return value.toPoint();
|
||||||
|
|
|
@ -91,6 +91,7 @@ public:
|
||||||
|
|
||||||
QVariant options() const;
|
QVariant options() const;
|
||||||
void setOptionsData(const QList<OptionsModel::Data> &data);
|
void setOptionsData(const QList<OptionsModel::Data> &data);
|
||||||
|
uint optionsMask() const;
|
||||||
|
|
||||||
RulePolicy::Type policyType() const;
|
RulePolicy::Type policyType() const;
|
||||||
int policy() const; // int belongs to anonymous enum in Rules::
|
int policy() const; // int belongs to anonymous enum in Rules::
|
||||||
|
@ -98,12 +99,10 @@ public:
|
||||||
QVariant policyModel() const;
|
QVariant policyModel() const;
|
||||||
QString policyKey() const;
|
QString policyKey() const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QVariant typedValue(const QVariant &value, const Type type);
|
QVariant typedValue(const QVariant &value) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_key;
|
QString m_key;
|
||||||
|
@ -121,6 +120,7 @@ private:
|
||||||
|
|
||||||
RulePolicy *m_policy;
|
RulePolicy *m_policy;
|
||||||
OptionsModel *m_options;
|
OptionsModel *m_options;
|
||||||
|
uint m_optionsMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|
|
@ -71,6 +71,7 @@ QHash< int, QByteArray > RulesModel::roleNames() const
|
||||||
{PolicyRole, QByteArrayLiteral("policy")},
|
{PolicyRole, QByteArrayLiteral("policy")},
|
||||||
{PolicyModelRole, QByteArrayLiteral("policyModel")},
|
{PolicyModelRole, QByteArrayLiteral("policyModel")},
|
||||||
{OptionsModelRole, QByteArrayLiteral("options")},
|
{OptionsModelRole, QByteArrayLiteral("options")},
|
||||||
|
{OptionsMaskRole, QByteArrayLiteral("optionsMask")},
|
||||||
{SuggestedValueRole, QByteArrayLiteral("suggested")},
|
{SuggestedValueRole, QByteArrayLiteral("suggested")},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -118,6 +119,8 @@ QVariant RulesModel::data(const QModelIndex &index, int role) const
|
||||||
return rule->policyModel();
|
return rule->policyModel();
|
||||||
case OptionsModelRole:
|
case OptionsModelRole:
|
||||||
return rule->options();
|
return rule->options();
|
||||||
|
case OptionsMaskRole:
|
||||||
|
return rule->optionsMask();
|
||||||
case SuggestedValueRole:
|
case SuggestedValueRole:
|
||||||
return rule->suggestedValue();
|
return rule->suggestedValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ public:
|
||||||
PolicyRole,
|
PolicyRole,
|
||||||
PolicyModelRole,
|
PolicyModelRole,
|
||||||
OptionsModelRole,
|
OptionsModelRole,
|
||||||
|
OptionsMaskRole,
|
||||||
SuggestedValueRole
|
SuggestedValueRole
|
||||||
};
|
};
|
||||||
Q_ENUM(RulesRole)
|
Q_ENUM(RulesRole)
|
||||||
|
|
Loading…
Reference in a new issue