Skip to content

Commit

Permalink
Merge pull request #4398 from opengisch/autocomplete
Browse files Browse the repository at this point in the history
Value relation editor widget autocomplete fixes and improvements
  • Loading branch information
nirvn authored Jul 7, 2023
2 parents 215a9f3 + c23aa1a commit 45287b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/qml/FeatureForm.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Page {
}
}

clip: true
states: [
State {
name: 'ReadOnly'
Expand Down
38 changes: 26 additions & 12 deletions src/qml/RelationCombobox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,11 @@ Item {
property bool useCompleter: false
property string completer: ''

anchors.verticalCenter: parent.verticalCenter
topPadding: 0
leftPadding: 5
rightPadding: 5
bottomPadding: 0
width: parent.width - dropDownArrowCanvas.width - dropDownArrowCanvas.anchors.rightMargin * 2
height: fontMetrics.height + 12
text: useCompleter ? completer : comboBox.displayText
Expand All @@ -398,8 +401,10 @@ Item {
property string typedFilter: ''

anchors.verticalCenter: parent.verticalCenter
padding: 5
topPadding: fontMetrics.ascent - 1
topPadding: 0
rightPadding: 5
leftPadding: 5
bottomPadding: 0
topInset: 0
bottomInset: 0
width: parent.width - dropDownArrowCanvas.width - dropDownArrowCanvas.anchors.rightMargin * 2
Expand All @@ -420,14 +425,16 @@ Item {
onDisplayTextChanged: {
if (activeFocus) {
if (text != comboBox.displayText) {
var trimmedText = text.trim();
var trimmedText = text.trim()
var matches = featureListModel.findDisplayValueMatches(trimmedText)
if (matches.length > 0) {
var remainder = featureListModel.dataFromRowIndex(matches[0], featureListModel.DisplayStringRole).substring(trimmedText.length)
searchableLabel.completer = '<span style="color:rgba(0,0,0,0);">' + trimmedText + '</span><span style="font-weight:'
+ (matches.length === 1 ? 'bold' : 'normal' ) + ';">' + remainder + '</span>'
color = Theme.mainTextColor
} else {
searchableLabel.completer = ''
color = Theme.warningColor
}
} else {
searchableLabel.completer = ''
Expand All @@ -441,24 +448,31 @@ Item {
if (text === '') {
if (!featureListModel.addNull || comboBox.currentIndex != 0) {
text = comboBox.displayText
searchableLabel.completer = ''
} else {
searchableLabel.completer = ''
color = Theme.mainTextColor
}
searchableLabel.completer = ''
}
} else {
if (text === '' && featureListModel.addNull) {
comboBox.currentIndex = 0;
searchableLabel.completer = comboBox.displayText
} else {
applyAutoCompletion(true)
if (!isLastKeyPressedReturn) {
if (text === '' && featureListModel.addNull) {
comboBox.currentIndex = 0;
searchableLabel.completer = comboBox.displayText
} else {
applyAutoCompletion(true)
}
}
}
}

property bool isLastKeyPressedReturn: false
Keys.onPressed: {
if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
applyAutoCompletion()
if (!isLastKeyPressedReturn) {
applyAutoCompletion()
}
isLastKeyPressedReturn = true
} else {
isLastKeyPressedReturn = false
}
}

Expand Down

1 comment on commit 45287b3

@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.