Skip to content

Commit

Permalink
Merge pull request #5201 from opengisch/seachOnlyBigMaps
Browse files Browse the repository at this point in the history
Make value map searchable only if it contains more than 6 items
  • Loading branch information
nirvn committed Apr 30, 2024
2 parents d321cbd + b0e7de8 commit 6201cfe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
15 changes: 8 additions & 7 deletions src/qml/RelationCombobox.qml
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/qml/editorwidgets/RelationReference.qml
Expand Up @@ -44,8 +44,7 @@ EditorWidgetBase {
enabled: isEnabled
useSearch: true
allowAddFeature: config['AllowAddFeatures'] !== undefined && config['AllowAddFeatures'] === true

property var _relation: _rel
relation: _rel
}

QfToolButton {
Expand Down
6 changes: 5 additions & 1 deletion src/qml/editorwidgets/ValueMap.qml
Expand Up @@ -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
visible: enabled && comboBox.count >= minimumItemCount

onClicked: {
searchFeaturePopup.open()
Expand Down
17 changes: 8 additions & 9 deletions src/qml/editorwidgets/ValueRelation.qml
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

1 comment on commit 6201cfe

@qfield-fairy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.