Skip to content

Commit

Permalink
refactor: some QML clean-ups
Browse files Browse the repository at this point in the history
- Remove unnecessary bindings to enabled: Properties that are not
  enabled are not shown in the list anyway, and it fixes QML warnings:

  RuleItemDelegate.qml:16:5: Unable to assign [undefined] to bool
  RuleItemDelegate.qml:93:17: Unable to assign [undefined] to bool

- Remove unnecessary colorSet
- Port away from javascript `var`
- Remove outdated comment
  • Loading branch information
ismailof authored and romangg committed Sep 23, 2024
1 parent 301bc23 commit eecddc3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
7 changes: 0 additions & 7 deletions kcms/rules/ui/RuleItemDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import org.kde.kcmutils as KCM
QQC2.ItemDelegate {
id: ruleDelegate

property bool ruleEnabled: model.enabled

Kirigami.Theme.colorSet: Kirigami.Theme.View

width: ListView.view.width
highlighted: false
hoverEnabled: false
Expand Down Expand Up @@ -76,7 +72,6 @@ QQC2.ItemDelegate {
Layout.alignment: Qt.AlignVCenter

visible: count > 0
enabled: ruleEnabled

model: policyModel
onActivated: {
Expand All @@ -90,8 +85,6 @@ QQC2.ItemDelegate {
Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter | Qt.AlignRight

enabled: model.enabled

ruleValue: model.value
ruleOptions: model.options
controlType: model.type
Expand Down
14 changes: 7 additions & 7 deletions kcms/rules/ui/RulesEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ KCM.ScrollViewKCM {
case RuleItem.Option:
return options.textOfValue(value);
case RuleItem.NetTypes:
var selectedValue = value.toString(2).length - 1;
const selectedValue = value.toString(2).length - 1;
return options.textOfValue(selectedValue);
case RuleItem.OptionList:
return Array.from(value, item => options.textOfValue(item) ).join(", ");
Expand All @@ -309,7 +309,7 @@ KCM.ScrollViewKCM {
id: enabledRulesModel
sourceModel: kcm.rulesModel
filterRowCallback: (source_row, source_parent) => {
var index = sourceModel.index(source_row, 0, source_parent);
const index = sourceModel.index(source_row, 0, source_parent);
return sourceModel.data(index, RulesModel.EnabledRole);
}
}
Expand All @@ -325,13 +325,13 @@ KCM.ScrollViewKCM {

filterString: searchField.text.trim().toLowerCase()
filterRowCallback: (source_row, source_parent) => {
var index = sourceModel.index(source_row, 0, source_parent);
const index = sourceModel.index(source_row, 0, source_parent);

var hasSuggestion = sourceModel.data(index, RulesModel.SuggestedValueRole) != null;
var isOptional = sourceModel.data(index, RulesModel.SelectableRole);
var isEnabled = sourceModel.data(index, RulesModel.EnabledRole);
const hasSuggestion = sourceModel.data(index, RulesModel.SuggestedValueRole) != null;
const isOptional = sourceModel.data(index, RulesModel.SelectableRole);
const isEnabled = sourceModel.data(index, RulesModel.EnabledRole);

var showItem = hasSuggestion || (!onlySuggestions && isOptional && !isEnabled);
const showItem = hasSuggestion || (!onlySuggestions && isOptional && !isEnabled);

if (!showItem) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion kcms/rules/ui/ValueEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Loader {
multipleChoice: true

onActivated: {
let selectionList = []
const selectionList = []
for (let i = 0; i < count; i++) {
if (selectionMask & (1 << i)) {
selectionList.push(model.data(model.index(i,0), Qt.UserRole))
Expand Down
1 change: 0 additions & 1 deletion kcms/rules/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import org.kde.kirigami 2.12 as Kirigami
KCM.ScrollViewKCM {
id: rulesListKCM

// FIXME: ScrollViewKCM.qml:73:13: QML Control: Binding loop detected for property "implicitHeight"
implicitWidth: Kirigami.Units.gridUnit * 35
implicitHeight: Kirigami.Units.gridUnit * 35

Expand Down

0 comments on commit eecddc3

Please sign in to comment.