Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make value map searchable only if it contains more than 6 items #5201

Merged
merged 3 commits into from Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
3 changes: 1 addition & 2 deletions src/qml/editorwidgets/ValueMap.qml
Expand Up @@ -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
domi4484 marked this conversation as resolved.
Show resolved Hide resolved

onClicked: {
searchFeaturePopup.open()
Expand Down Expand Up @@ -272,7 +272,6 @@ EditorWidgetBase {
font: parent.font
width: parent.width
verticalAlignment: Text.AlignVCenter
leftPadding: parent.indicator.width + parent.spacing
domi4484 marked this conversation as resolved.
Show resolved Hide resolved
elide: Text.ElideRight
color: searchField.displayText !== '' ? Theme.secondaryTextColor : Theme.mainTextColor
textFormat: Text.RichText
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