Skip to content

Commit

Permalink
Make value map searchable only if it contains more than 6 items
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Apr 22, 2024
1 parent 29a72a2 commit affead6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
15 changes: 8 additions & 7 deletions src/qml/RelationCombobox.qml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

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
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
Original file line number Diff line number Diff line change
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

0 comments on commit affead6

Please sign in to comment.