Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions app/qml/filters/MMFiltersPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import QtQuick.Controls

import "../components" as MMComponents

//
// TODO: rename this file to "MMFiltersDrawer"!
//

MMComponents.MMDrawer {
id: root

Expand Down Expand Up @@ -68,7 +72,11 @@ MMComponents.MMDrawer {
}

onClicked: {
internal.filterValues = {}

__activeProject.filterController.clearAllFilters()

inputRepeater.model = null
inputRepeater.model = __activeProject.filterController.getFilters()
}
}
Expand Down Expand Up @@ -100,6 +108,7 @@ MMComponents.MMDrawer {

Repeater {
id: inputRepeater

model: __activeProject.filterController.getFilters()

delegate: Loader {
Expand All @@ -110,36 +119,35 @@ MMComponents.MMDrawer {
width: contentColumn.width

Component.onCompleted: {
let base = {
filterName: modelData.filterName,
filterId: modelData.filterId,
currentValue: modelData.value
}
let props = { filterName: modelData.filterName }

const currentValue = modelData.value ? modelData.value : internal.filterValues[modelData.filterId]
props['currentValue'] = currentValue

const filterType = modelData.filterType

if ( filterType === FieldFilter.TextFilter )
{
setSource( "components/MMFilterTextEditor.qml", base )
setSource( "components/MMFilterTextEditor.qml", props )
}
else if ( filterType === FieldFilter.NumberFilter )
{
setSource( "components/MMFilterRangeInput.qml", base )
setSource( "components/MMFilterRangeInput.qml", props )
}
else if ( filterType === FieldFilter.DateFilter )
{
setSource( "components/MMFilterDateRange.qml", base )
setSource( "components/MMFilterDateRange.qml", props )
}
else if ( filterType === FieldFilter.CheckboxFilter )
{
setSource( "components/MMFilterBoolInput.qml", base )
setSource( "components/MMFilterBoolInput.qml", props )
}
else if ( filterType === FieldFilter.SingleSelectFilter || filterType === FieldFilter.MultiSelectFilter )
{
// TODO: might be worth moving this logic to C++

const isMulti = filterType === FieldFilter.MultiSelectFilter
base['isMultiSelect'] = isMulti
props['isMultiSelect'] = isMulti

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

Expand All @@ -151,19 +159,19 @@ MMComponents.MMDrawer {

if ( dropdownConfig["type"] === "unique_values" )
{
base["vectorLayerId"] = dropdownConfig["layer_id"]
base["fieldName"] = dropdownConfig["field_name"]
setSource( "components/MMFilterDropdownUniqueValuesInput.qml", base )
props["vectorLayerId"] = dropdownConfig["layer_id"]
props["fieldName"] = dropdownConfig["field_name"]
setSource( "components/MMFilterDropdownUniqueValuesInput.qml", props )
}
else if ( dropdownConfig["type"] === "value_relation" )
{
base["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueRelationInput.qml", base )
props["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueRelationInput.qml", props )
}
else if ( dropdownConfig["type"] === "value_map" )
{
base["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueMapInput.qml", base )
props["widgetConfig"] = dropdownConfig["config"]
setSource( "components/MMFilterDropdownValueMapInput.qml", props )
}
}
}
Expand Down
91 changes: 55 additions & 36 deletions app/qml/filters/components/MMFilterBoolInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,66 +9,85 @@

import QtQuick

import "../../components"
import "../../components" as MMComponents

Column {
id: root

width: parent.width
spacing: __style.margin8
required property string filterName

required property string fieldDisplayName
required property var currentValue
required property string fieldLayerId
required property string fieldName

property string boolTrueLabel: ""
property string boolFalseLabel: ""
property var boolCheckedValue: null
property var boolUncheckedValue: null
property string customLabelForTrue: ""
property string customLabelForFalse: ""

property bool _initialized: false
Component.onCompleted: _initialized = true
property var customValueForTrue: null // can be string, number, bool
property var customValueForFalse: null // can be string, number, bool

MMText {
width: parent.width
spacing: __style.margin8

MMComponents.MMText {
width: parent.width
text: root.fieldDisplayName

text: root.filterName

font: __style.p6
color: __style.nightColor
visible: root.fieldDisplayName !== ""
visible: text
}

MMSegmentControl {
MMComponents.MMSegmentControl {
id: segControl

width: parent.width
backgroundColor: __style.lightGreenColor

trueText: root.boolTrueLabel !== "" ? root.boolTrueLabel : qsTr( "True" )
falseText: root.boolFalseLabel !== "" ? root.boolFalseLabel : qsTr( "False" )
trueText: customLabelForTrue ? customLabelForTrue : qsTr( "True" )
falseText: customLabelForFalse ? customLabelForFalse : qsTr( "False" )

selectedIndex: {
let val = root.currentValue
if ( val === null || val === undefined ) return MMSegmentControl.Options.All
let checkedVal = root.boolCheckedValue !== null ? root.boolCheckedValue : true
return ( val == checkedVal ) ? MMSegmentControl.Options.True : MMSegmentControl.Options.False
Component.onCompleted: {
if ( root.currentValue && root.currentValue.length === 1 )
{
if ( root.currentValue[0] === internal.representationForTrue )
{
selectedIndex = MMComponents.MMSegmentControl.Options.True
}
else if ( root.currentValue[0] === internal.representationForFalse )
{
selectedIndex = MMComponents.MMSegmentControl.Options.False
}
else
{
selectedIndex = MMComponents.MMSegmentControl.Options.All
}
}
else
{
selectedIndex = MMComponents.MMSegmentControl.Options.All
}
}

onSelectedIndexChanged: {
if ( !root._initialized || !root.fieldLayerId || !root.fieldName ) return
switch ( segControl.selectedIndex ) {
case MMSegmentControl.Options.All:
__activeProject.filterController.removeFieldFilter( root.fieldLayerId, root.fieldName )
break
case MMSegmentControl.Options.True:
__activeProject.filterController.setFieldFilter( root.fieldLayerId, root.fieldName, "bool",
root.boolCheckedValue !== null ? root.boolCheckedValue : true )
break
case MMSegmentControl.Options.False:
__activeProject.filterController.setFieldFilter( root.fieldLayerId, root.fieldName, "bool",
root.boolUncheckedValue !== null ? root.boolUncheckedValue : false )
break
if ( selectedIndex === MMComponents.MMSegmentControl.Options.All )
{
root.currentValue = undefined
}
else if ( selectedIndex === MMComponents.MMSegmentControl.Options.True )
{
root.currentValue = [internal.representationForTrue]
}
else if ( selectedIndex === MMComponents.MMSegmentControl.Options.False )
{
root.currentValue = [internal.representationForFalse]
}
}
}

QtObject {
id: internal

property var representationForTrue: root.customValueForTrue ? root.customValueForTrue : true
property var representationForFalse: root.customValueForFalse ? root.customValueForFalse : false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Column {
id: root

required property string filterName
required property string filterId
required property var currentValue

required property string vectorLayerId
Expand Down Expand Up @@ -54,7 +53,7 @@ Column {
onRightContentClicked: {
if ( root.currentValue && root.currentValue.length )
{
root.currentValue = []
root.currentValue = undefined
root.currentValueChanged()
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Column {
onRightContentClicked: {
if ( root.currentValue && root.currentValue.length )
{
root.currentValue = []
root.currentValue = undefined
root.currentValueChanged()
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Column {
id: root

required property string filterName
required property string filterId
required property var currentValue

required property var widgetConfig
Expand Down Expand Up @@ -53,7 +52,7 @@ Column {
onRightContentClicked: {
if ( root.currentValue && root.currentValue.length )
{
root.currentValue = []
root.currentValue = undefined
root.currentValueChanged()
}
else
Expand Down
1 change: 0 additions & 1 deletion app/qml/filters/components/MMFilterTextEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Column {
spacing: __style.margin8

required property string filterName
required property string filterId
required property var currentValue

MMText {
Expand Down
Loading