Skip to content

Commit ff752ca

Browse files
committed
Simplify value relation conversion logic + cleanup in qml
1 parent b3abccc commit ff752ca

2 files changed

Lines changed: 16 additions & 29 deletions

File tree

app/qml/filters/components/MMFilterDropdownUniqueValuesInput.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import QtQuick
1111

1212
import MMInput as MM
13-
import "../../components"
13+
import "../../components" as MMComponents
1414

1515
Column {
1616
id: root
@@ -28,7 +28,7 @@ Column {
2828

2929
spacing: __style.margin8
3030

31-
MMText {
31+
MMComponents.MMText {
3232
width: parent.width
3333

3434
text: root.filterName
@@ -72,7 +72,7 @@ Column {
7272
// TODO: add indication that model is loading features
7373
// TODO: add animation when drawer height is changed
7474

75-
sourceComponent: MMListMultiselectDrawer {
75+
sourceComponent: MMComponents.MMListMultiselectDrawer {
7676
drawerHeader.title: root.filterName
7777

7878
withSearch: true

app/qml/filters/components/MMFilterDropdownValueRelationInput.qml

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import QtQuick
1111

1212
import mm 1.0 as MM
13-
import "../../components"
13+
import "../../components" as MMComponents
1414

1515
Column {
1616
id: root
@@ -27,7 +27,7 @@ Column {
2727

2828
spacing: __style.margin8
2929

30-
MMText {
30+
MMComponents.MMText {
3131
width: parent.width
3232

3333
text: root.filterName
@@ -71,10 +71,10 @@ Column {
7171
// TODO: add indication that model is loading features
7272
// TODO: add animation when drawer height is changed
7373

74-
sourceComponent: MMListMultiselectDrawer {
74+
sourceComponent: MMComponents.MMListMultiselectDrawer {
7575
drawerHeader.title: root.filterName
7676

77-
withSearch: true
77+
withSearch: vrDropdownModel.count > 5
7878
multiSelect: root.isMultiSelect
7979

8080
list.model: MM.ValueRelationFeaturesModel {
@@ -88,36 +88,23 @@ Column {
8888

8989
onSelectionFinished: function( selectedItems ) {
9090

91-
if ( root.isMultiSelect )
92-
{
93-
let isNull = selectedItems.length === 0
94-
95-
if ( !isNull )
96-
{
97-
// We need to convert feature id to string prior to sending it to C++ in order to
98-
// avoid conversion to scientific notation.
99-
selectedItems = selectedItems.map( function(x) { return x.toString() } )
100-
}
101-
102-
root.currentValue = vrDropdownModel.convertToQgisType( selectedItems ).replace( "{","" ).replace( "}","" ).split( ',' ).filter( x => x )
103-
}
104-
else
105-
{
106-
// We need to convert feature id to string prior to sending it to C++ in order to
107-
// avoid conversion to scientific notation.
108-
selectedItems = selectedItems.toString()
109-
110-
root.currentValue = [vrDropdownModel.convertToKey( selectedItems )]
111-
}
91+
//
92+
// We need to convert from feature IDs to key-column.
93+
// Large fids could be converted to scientific notation on their way to cpp,
94+
// so we convert them to string first in JS.
95+
//
96+
selectedItems = selectedItems.map( x => x.toString() ).map( x => vrDropdownModel.convertToKey( x ) )
11297

113-
console.log("--> selected items:", selectedItems)
98+
root.currentValue = selectedItems
11499

115100
// TODO: this is just a hack, we need to add a dedicated signal instead, Qt does not always get that array length has changed
116101
root.currentValueChanged()
117102

118103
close()
119104
}
120105

106+
onSearchTextChanged: ( searchText ) => vrDropdownModel.searchExpression = searchText
107+
121108
onClosed: dropdownDrawerLoader.active = false
122109

123110
Component.onCompleted: {

0 commit comments

Comments
 (0)