From affead619fd640aecd27c02bde92417b6e278ebb Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Mon, 22 Apr 2024 18:05:09 +0200 Subject: [PATCH 1/3] Make value map searchable only if it contains more than 6 items --- src/qml/RelationCombobox.qml | 15 ++++++++------- src/qml/editorwidgets/RelationReference.qml | 3 +-- src/qml/editorwidgets/ValueMap.qml | 3 +-- src/qml/editorwidgets/ValueRelation.qml | 17 ++++++++--------- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/qml/RelationCombobox.qml b/src/qml/RelationCombobox.qml index 34ea8d4dd2..e79ecd20da 100644 --- a/src/qml/RelationCombobox.qml +++ b/src/qml/RelationCombobox.qml @@ -14,10 +14,11 @@ Item { property bool useCompleter: false property bool useSearch: false property bool allowAddFeature: false + property var relation: undefined Component.onCompleted: { comboBox.currentIndex = featureListModel.findKey(value) - invalidWarning.visible = _relation !== undefined ? !(_relation.isValid) : false + invalidWarning.visible = relation !== undefined ? !(relation.isValid) : false } anchors { @@ -42,7 +43,7 @@ Item { codeReader: form.codeReader onFeatureSaved: { - var referencedValue = addFeaturePopup.attributeFormModel.attribute(relationCombobox._relation.resolveReferencedField(field.name)) + var referencedValue = addFeaturePopup.attributeFormModel.attribute(relationCombobox.relation.resolveReferencedField(field.name)) var index = featureListModel.findKey(referencedValue) if ( index < 0 ) { // model not yet reloaded - keep the value and set it onModelReset @@ -98,7 +99,7 @@ Item { anchors.left: parent.left anchors.right: parent.right - placeholderText: !focus && displayText == '' ? qsTr("Search…") : '' + placeholderText: !focus && displayText === '' ? qsTr("Search…") : '' placeholderTextColor: Theme.mainColor height: fontMetrics.height * 2.5 @@ -293,7 +294,7 @@ Item { ComboBox { id: comboBox - visible: !enabled || (!useSearch && !useCompleter && (_relation !== undefined ? _relation.isValid : true)) + visible: !enabled || (!useSearch && !useCompleter && (relation !== undefined ? relation.isValid : true)) Layout.fillWidth: true property var _cachedCurrentValue @@ -631,11 +632,11 @@ Item { iconSource: Theme.getThemeIcon("ic_add_black_48dp") iconColor: Theme.mainTextColor - visible: enabled && allowAddFeature && _relation !== undefined && _relation.isValid + visible: enabled && allowAddFeature && relation !== undefined && relation.isValid onClicked: { embeddedPopup.state = 'Add' - embeddedPopup.currentLayer = relationCombobox._relation ? relationCombobox._relation.referencedLayer : null + embeddedPopup.currentLayer = relationCombobox.relation ? relationCombobox.relation.referencedLayer : null embeddedPopup.open() } } @@ -656,7 +657,7 @@ Item { codeReader: form.codeReader onFeatureSaved: { - var referencedValue = embeddedPopup.attributeFormModel.attribute(relationCombobox._relation.resolveReferencedField(field.name)) + var referencedValue = embeddedPopup.attributeFormModel.attribute(relationCombobox.relation.resolveReferencedField(field.name)) var index = featureListModel.findKey(referencedValue) if ( ( featureListModel.addNull == true && index < 1 ) || index < 0 ) { // model not yet reloaded - keep the value and set it onModelReset diff --git a/src/qml/editorwidgets/RelationReference.qml b/src/qml/editorwidgets/RelationReference.qml index b74fcd0037..61abe98837 100644 --- a/src/qml/editorwidgets/RelationReference.qml +++ b/src/qml/editorwidgets/RelationReference.qml @@ -44,8 +44,7 @@ EditorWidgetBase { enabled: isEnabled useSearch: true allowAddFeature: config['AllowAddFeatures'] !== undefined && config['AllowAddFeatures'] === true - - property var _relation: _rel + relation: _rel } QfToolButton { diff --git a/src/qml/editorwidgets/ValueMap.qml b/src/qml/editorwidgets/ValueMap.qml index 2f5edc17f8..837706ae13 100644 --- a/src/qml/editorwidgets/ValueMap.qml +++ b/src/qml/editorwidgets/ValueMap.qml @@ -125,7 +125,7 @@ EditorWidgetBase { iconSource: Theme.getThemeIcon("ic_baseline_search_black") iconColor: Theme.mainTextColor - visible: enabled + visible: enabled && comboBox.count > 6 // Make value map searchable only if it contains more than 6 items onClicked: { searchFeaturePopup.open() @@ -272,7 +272,6 @@ EditorWidgetBase { font: parent.font width: parent.width verticalAlignment: Text.AlignVCenter - leftPadding: parent.indicator.width + parent.spacing elide: Text.ElideRight color: searchField.displayText !== '' ? Theme.secondaryTextColor : Theme.mainTextColor textFormat: Text.RichText diff --git a/src/qml/editorwidgets/ValueRelation.qml b/src/qml/editorwidgets/ValueRelation.qml index bc3b64ec85..bec6163a21 100644 --- a/src/qml/editorwidgets/ValueRelation.qml +++ b/src/qml/editorwidgets/ValueRelation.qml @@ -32,13 +32,13 @@ EditorWidgetBase { attributeField: field currentLayer: layerResolver.currentLayer currentFormFeature: currentFeature - keyField: config['Key'] - displayValueField: config['Value'] - groupField: config['Group'] - displayGroupName: config['DisplayGroupName'] - addNull: config['AllowNull'] - orderByValue: config['OrderByValue'] - filterExpression: config['FilterExpression'] + keyField: config['Key'] ? config['Key'] : "" + displayValueField: config['Value'] ? config['Value'] : "" + groupField: config['Group'] ? config['Group'] : "" + displayGroupName: config['DisplayGroupName'] ? config['DisplayGroupName'] : "" + addNull: config['AllowNull'] ? config['AllowNull'] : "" + orderByValue: config['OrderByValue'] ? config['OrderByValue'] : "" + filterExpression: config['FilterExpression'] ? config['FilterExpression'] : "" // passing "" instead of undefined, so the model is cleared on adding new features // attributeValue has to be the last property set to make sure its given value is handled properly (e.g. allow multiple) @@ -53,11 +53,10 @@ EditorWidgetBase { id: valueRelationCombobox featureListModel: listModel - property var _relation: undefined - useCompleter: !!config['UseCompleter'] enabled: isEnabled visible: Number(config['AllowMulti']) !== 1 + relation: undefined } Rectangle { From f9a98b469398f246be8ffe41d6a181576f80a79f Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Tue, 23 Apr 2024 10:51:42 +0200 Subject: [PATCH 2/3] Revert removal of leftpadding --- src/qml/editorwidgets/ValueMap.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qml/editorwidgets/ValueMap.qml b/src/qml/editorwidgets/ValueMap.qml index 837706ae13..dd30bbf0a0 100644 --- a/src/qml/editorwidgets/ValueMap.qml +++ b/src/qml/editorwidgets/ValueMap.qml @@ -272,6 +272,7 @@ EditorWidgetBase { font: parent.font width: parent.width verticalAlignment: Text.AlignVCenter + leftPadding: parent.indicator.width + parent.spacing elide: Text.ElideRight color: searchField.displayText !== '' ? Theme.secondaryTextColor : Theme.mainTextColor textFormat: Text.RichText From b0e7de8c6a1b62929509bb1435aaf98271368f75 Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Tue, 23 Apr 2024 14:58:22 +0200 Subject: [PATCH 3/3] Use a readonly property and document minimum item count limit --- src/qml/editorwidgets/ValueMap.qml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qml/editorwidgets/ValueMap.qml b/src/qml/editorwidgets/ValueMap.qml index dd30bbf0a0..8cd2a829b1 100644 --- a/src/qml/editorwidgets/ValueMap.qml +++ b/src/qml/editorwidgets/ValueMap.qml @@ -121,11 +121,15 @@ EditorWidgetBase { Layout.preferredWidth: enabled ? 48 : 0 Layout.preferredHeight: 48 + // Using the search when there are less than X items in the dropdown proves to be poor UI on normally + // sized and oriented phones. Some empirical tests proved 6 to be a good number for now. + readonly property int minimumItemCount: 6 + bgcolor: "transparent" iconSource: Theme.getThemeIcon("ic_baseline_search_black") iconColor: Theme.mainTextColor - visible: enabled && comboBox.count > 6 // Make value map searchable only if it contains more than 6 items + visible: enabled && comboBox.count >= minimumItemCount onClicked: { searchFeaturePopup.open()