Skip to content

Commit dfc299e

Browse files
committed
Integrate boolean filter input and update props we send to widgets
1 parent 7f1efe3 commit dfc299e

6 files changed

Lines changed: 83 additions & 59 deletions

app/qml/filters/MMFiltersPanel.qml

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import QtQuick.Controls
1313

1414
import "../components" as MMComponents
1515

16+
//
17+
// TODO: rename this file to "MMFiltersDrawer"!
18+
//
19+
1620
MMComponents.MMDrawer {
1721
id: root
1822

@@ -68,7 +72,11 @@ MMComponents.MMDrawer {
6872
}
6973

7074
onClicked: {
75+
internal.filterValues = {}
76+
7177
__activeProject.filterController.clearAllFilters()
78+
79+
inputRepeater.model = null
7280
inputRepeater.model = __activeProject.filterController.getFilters()
7381
}
7482
}
@@ -100,6 +108,7 @@ MMComponents.MMDrawer {
100108

101109
Repeater {
102110
id: inputRepeater
111+
103112
model: __activeProject.filterController.getFilters()
104113

105114
delegate: Loader {
@@ -110,36 +119,35 @@ MMComponents.MMDrawer {
110119
width: contentColumn.width
111120

112121
Component.onCompleted: {
113-
let base = {
114-
filterName: modelData.filterName,
115-
filterId: modelData.filterId,
116-
currentValue: modelData.value
117-
}
122+
let props = { filterName: modelData.filterName }
123+
124+
const currentValue = modelData.value ? modelData.value : internal.filterValues[modelData.filterId]
125+
props['currentValue'] = currentValue
118126

119127
const filterType = modelData.filterType
120128

121129
if ( filterType === FieldFilter.TextFilter )
122130
{
123-
setSource( "components/MMFilterTextEditor.qml", base )
131+
setSource( "components/MMFilterTextEditor.qml", props )
124132
}
125133
else if ( filterType === FieldFilter.NumberFilter )
126134
{
127-
setSource( "components/MMFilterRangeInput.qml", base )
135+
setSource( "components/MMFilterRangeInput.qml", props )
128136
}
129137
else if ( filterType === FieldFilter.DateFilter )
130138
{
131-
setSource( "components/MMFilterDateRange.qml", base )
139+
setSource( "components/MMFilterDateRange.qml", props )
132140
}
133141
else if ( filterType === FieldFilter.CheckboxFilter )
134142
{
135-
setSource( "components/MMFilterBoolInput.qml", base )
143+
setSource( "components/MMFilterBoolInput.qml", props )
136144
}
137145
else if ( filterType === FieldFilter.SingleSelectFilter || filterType === FieldFilter.MultiSelectFilter )
138146
{
139147
// TODO: might be worth moving this logic to C++
140148

141149
const isMulti = filterType === FieldFilter.MultiSelectFilter
142-
base['isMultiSelect'] = isMulti
150+
props['isMultiSelect'] = isMulti
143151

144152
const dropdownConfig = __activeProject.filterController.getDropdownConfiguration( modelData.filterId )
145153

@@ -151,19 +159,19 @@ MMComponents.MMDrawer {
151159

152160
if ( dropdownConfig["type"] === "unique_values" )
153161
{
154-
base["vectorLayerId"] = dropdownConfig["layer_id"]
155-
base["fieldName"] = dropdownConfig["field_name"]
156-
setSource( "components/MMFilterDropdownUniqueValuesInput.qml", base )
162+
props["vectorLayerId"] = dropdownConfig["layer_id"]
163+
props["fieldName"] = dropdownConfig["field_name"]
164+
setSource( "components/MMFilterDropdownUniqueValuesInput.qml", props )
157165
}
158166
else if ( dropdownConfig["type"] === "value_relation" )
159167
{
160-
base["widgetConfig"] = dropdownConfig["config"]
161-
setSource( "components/MMFilterDropdownValueRelationInput.qml", base )
168+
props["widgetConfig"] = dropdownConfig["config"]
169+
setSource( "components/MMFilterDropdownValueRelationInput.qml", props )
162170
}
163171
else if ( dropdownConfig["type"] === "value_map" )
164172
{
165-
base["widgetConfig"] = dropdownConfig["config"]
166-
setSource( "components/MMFilterDropdownValueMapInput.qml", base )
173+
props["widgetConfig"] = dropdownConfig["config"]
174+
setSource( "components/MMFilterDropdownValueMapInput.qml", props )
167175
}
168176
}
169177
}

app/qml/filters/components/MMFilterBoolInput.qml

Lines changed: 55 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,85 @@
99

1010
import QtQuick
1111

12-
import "../../components"
12+
import "../../components" as MMComponents
1313

1414
Column {
1515
id: root
1616

17-
width: parent.width
18-
spacing: __style.margin8
17+
required property string filterName
1918

20-
required property string fieldDisplayName
2119
required property var currentValue
22-
required property string fieldLayerId
23-
required property string fieldName
2420

25-
property string boolTrueLabel: ""
26-
property string boolFalseLabel: ""
27-
property var boolCheckedValue: null
28-
property var boolUncheckedValue: null
21+
property string customLabelForTrue: ""
22+
property string customLabelForFalse: ""
2923

30-
property bool _initialized: false
31-
Component.onCompleted: _initialized = true
24+
property var customValueForTrue: null // can be string, number, bool
25+
property var customValueForFalse: null // can be string, number, bool
3226

33-
MMText {
27+
width: parent.width
28+
spacing: __style.margin8
29+
30+
MMComponents.MMText {
3431
width: parent.width
35-
text: root.fieldDisplayName
32+
33+
text: root.filterName
34+
3635
font: __style.p6
3736
color: __style.nightColor
38-
visible: root.fieldDisplayName !== ""
37+
visible: text
3938
}
4039

41-
MMSegmentControl {
40+
MMComponents.MMSegmentControl {
4241
id: segControl
4342

4443
width: parent.width
4544
backgroundColor: __style.lightGreenColor
4645

47-
trueText: root.boolTrueLabel !== "" ? root.boolTrueLabel : qsTr( "True" )
48-
falseText: root.boolFalseLabel !== "" ? root.boolFalseLabel : qsTr( "False" )
46+
trueText: customLabelForTrue ? customLabelForTrue : qsTr( "True" )
47+
falseText: customLabelForFalse ? customLabelForFalse : qsTr( "False" )
4948

50-
selectedIndex: {
51-
let val = root.currentValue
52-
if ( val === null || val === undefined ) return MMSegmentControl.Options.All
53-
let checkedVal = root.boolCheckedValue !== null ? root.boolCheckedValue : true
54-
return ( val == checkedVal ) ? MMSegmentControl.Options.True : MMSegmentControl.Options.False
49+
Component.onCompleted: {
50+
if ( root.currentValue && root.currentValue.length === 1 )
51+
{
52+
if ( root.currentValue[0] === internal.representationForTrue )
53+
{
54+
selectedIndex = MMComponents.MMSegmentControl.Options.True
55+
}
56+
else if ( root.currentValue[0] === internal.representationForFalse )
57+
{
58+
selectedIndex = MMComponents.MMSegmentControl.Options.False
59+
}
60+
else
61+
{
62+
selectedIndex = MMComponents.MMSegmentControl.Options.All
63+
}
64+
}
65+
else
66+
{
67+
selectedIndex = MMComponents.MMSegmentControl.Options.All
68+
}
5569
}
5670

5771
onSelectedIndexChanged: {
58-
if ( !root._initialized || !root.fieldLayerId || !root.fieldName ) return
59-
switch ( segControl.selectedIndex ) {
60-
case MMSegmentControl.Options.All:
61-
__activeProject.filterController.removeFieldFilter( root.fieldLayerId, root.fieldName )
62-
break
63-
case MMSegmentControl.Options.True:
64-
__activeProject.filterController.setFieldFilter( root.fieldLayerId, root.fieldName, "bool",
65-
root.boolCheckedValue !== null ? root.boolCheckedValue : true )
66-
break
67-
case MMSegmentControl.Options.False:
68-
__activeProject.filterController.setFieldFilter( root.fieldLayerId, root.fieldName, "bool",
69-
root.boolUncheckedValue !== null ? root.boolUncheckedValue : false )
70-
break
72+
if ( selectedIndex === MMComponents.MMSegmentControl.Options.All )
73+
{
74+
root.currentValue = undefined
75+
}
76+
else if ( selectedIndex === MMComponents.MMSegmentControl.Options.True )
77+
{
78+
root.currentValue = [internal.representationForTrue]
79+
}
80+
else if ( selectedIndex === MMComponents.MMSegmentControl.Options.False )
81+
{
82+
root.currentValue = [internal.representationForFalse]
7183
}
7284
}
7385
}
86+
87+
QtObject {
88+
id: internal
89+
90+
property var representationForTrue: root.customValueForTrue ? root.customValueForTrue : true
91+
property var representationForFalse: root.customValueForFalse ? root.customValueForFalse : false
92+
}
7493
}

app/qml/filters/components/MMFilterDropdownUniqueValuesInput.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Column {
1616
id: root
1717

1818
required property string filterName
19-
required property string filterId
2019
required property var currentValue
2120

2221
required property string vectorLayerId
@@ -54,7 +53,7 @@ Column {
5453
onRightContentClicked: {
5554
if ( root.currentValue && root.currentValue.length )
5655
{
57-
root.currentValue = []
56+
root.currentValue = undefined
5857
root.currentValueChanged()
5958
}
6059
else

app/qml/filters/components/MMFilterDropdownValueMapInput.qml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Column {
5252
onRightContentClicked: {
5353
if ( root.currentValue && root.currentValue.length )
5454
{
55-
root.currentValue = []
55+
root.currentValue = undefined
5656
root.currentValueChanged()
5757
}
5858
else

app/qml/filters/components/MMFilterDropdownValueRelationInput.qml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ Column {
1616
id: root
1717

1818
required property string filterName
19-
required property string filterId
2019
required property var currentValue
2120

2221
required property var widgetConfig
@@ -53,7 +52,7 @@ Column {
5352
onRightContentClicked: {
5453
if ( root.currentValue && root.currentValue.length )
5554
{
56-
root.currentValue = []
55+
root.currentValue = undefined
5756
root.currentValueChanged()
5857
}
5958
else

app/qml/filters/components/MMFilterTextEditor.qml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ Column {
1818
spacing: __style.margin8
1919

2020
required property string filterName
21-
required property string filterId
2221
required property var currentValue
2322

2423
MMText {

0 commit comments

Comments
 (0)