diff --git a/app/filtercontroller.cpp b/app/filtercontroller.cpp index 1faea9fc5..49addf083 100644 --- a/app/filtercontroller.cpp +++ b/app/filtercontroller.cpp @@ -45,7 +45,12 @@ void FilterController::clearLayerFilters( const QString &layerId ) void FilterController::clearAllFilters() { - mFieldFilters.clear(); + for ( FieldFilter &filter : mFieldFilters ) + { + filter.value.clear(); + } + mFilteringEnabled = false; + emit hasFiltersEnabledChanged(); const QMap layers = QgsProject::instance()->mapLayers(); for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it ) @@ -63,14 +68,15 @@ void FilterController::loadFilterConfig( const QgsProject *project ) mFieldFilters.clear(); bool valueRead = false; - const bool filteringEnabled = project->readBoolEntry( QStringLiteral( "Mergin" ), QStringLiteral( "Filtering/Enabled" ), false, &valueRead ); + const bool filteringAvailable = project->readBoolEntry( QStringLiteral( "Mergin" ), QStringLiteral( "Filtering/Enabled" ), false, &valueRead ); //return early if filtering is not setup if ( !valueRead ) { return; } - mFilteringEnabled = filteringEnabled; + mFilteringAvailable = filteringAvailable; + emit hasFiltersAvailableChanged(); const QString filtersDef = project->readEntry( QStringLiteral( "Mergin" ), QStringLiteral( "Filtering/Filters" ) ); QJsonParseError jsonError; @@ -231,6 +237,12 @@ void FilterController::applyFiltersToLayer( QgsVectorLayer *layer ) const QString filterExpr = generateFilterExpression( layer->id() ); const bool success = layer->setSubsetString( filterExpr ); + if ( !filterExpr.isEmpty() && success && !mFilteringEnabled ) + { + mFilteringEnabled = true; + emit hasFiltersEnabledChanged(); + } + qDebug() << "Applied filter to layer" << layer->name() << ":" << filterExpr << "success:" << success; // Trigger a layer refresh to ensure the filter takes effect @@ -242,7 +254,9 @@ void FilterController::applyFiltersToLayer( QgsVectorLayer *layer ) void FilterController::applyFiltersToAllLayers() { - const bool hadFilters = mFilteringEnabled; + // Change filters enabled to false before enabling filters to find out if any are active + mFilteringEnabled = false; + emit hasFiltersEnabledChanged(); const QgsProject *project = QgsProject::instance(); if ( !project ) @@ -257,14 +271,6 @@ void FilterController::applyFiltersToAllLayers() applyFiltersToLayer( vectorLayer ); } } - - //TODO: probably can be removed - emit filtersChanged(); - - if ( hadFilters != mFilteringEnabled ) - { - emit hasFiltersEnabledChanged(); - } } bool FilterController::hasFiltersAvailable() const diff --git a/app/filtercontroller.h b/app/filtercontroller.h index 9218c6c55..baef4b467 100644 --- a/app/filtercontroller.h +++ b/app/filtercontroller.h @@ -123,7 +123,6 @@ class FilterController : public QObject signals: - void filtersChanged(); void hasActiveFiltersChanged(); void layerFilterChanged( const QString &layerId ); void hasFiltersAvailableChanged(); diff --git a/app/qml/filters/MMFiltersPanel.qml b/app/qml/filters/MMFiltersPanel.qml index 0c07a1709..82fed563f 100644 --- a/app/qml/filters/MMFiltersPanel.qml +++ b/app/qml/filters/MMFiltersPanel.qml @@ -58,9 +58,8 @@ MMComponents.MMDrawer { text: qsTr( "Reset" ) fontColor: __style.grapeColor bgndColor: __style.negativeLightColor - bgndColorHover: __style.negativeLightColor - fontColorHover: __style.grapeColor - iconColorHover: __style.grapeColor + bgndColorHover: __style.grapeColor + fontColorHover: __style.negativeLightColor anchors { left: parent.left @@ -70,6 +69,7 @@ MMComponents.MMDrawer { onClicked: { __activeProject.filterController.clearAllFilters() + inputRepeater.model = __activeProject.filterController.getFilters() } } diff --git a/app/qml/filters/components/MMFilterTextEditor.qml b/app/qml/filters/components/MMFilterTextEditor.qml index 8db629946..9cd759d5b 100644 --- a/app/qml/filters/components/MMFilterTextEditor.qml +++ b/app/qml/filters/components/MMFilterTextEditor.qml @@ -45,6 +45,12 @@ Column { id: debounceTimer interval: 300 repeat: false - onTriggered: root.currentValue = [filterInput.text] + onTriggered: { + if (filterInput.text) { + root.currentValue = [filterInput.text] + } else { + root.currentValue = undefined + } + } } } diff --git a/app/qml/filters/components/MMFilterTextInput.qml b/app/qml/filters/components/MMFilterTextInput.qml index 20662b1fe..360f3cec0 100644 --- a/app/qml/filters/components/MMFilterTextInput.qml +++ b/app/qml/filters/components/MMFilterTextInput.qml @@ -73,7 +73,7 @@ MMPrivateComponents.MMBaseSingleLineInput { // keep checked in sync with whether the field has a value onTextChanged: { if ( root.type === MMFilterTextInput.InputType.Text || root.type === MMFilterTextInput.InputType.Number ) { - root.checked = ( root.text !== "" ) + root.checked = false } } @@ -84,4 +84,10 @@ MMPrivateComponents.MMBaseSingleLineInput { root.checked = false } } + + Component.onCompleted: { + if ( root.text ) { + root.checked = true + } + } } diff --git a/app/qml/map/MMMapController.qml b/app/qml/map/MMMapController.qml index ca603b894..1aa023f19 100644 --- a/app/qml/map/MMMapController.qml +++ b/app/qml/map/MMMapController.qml @@ -860,7 +860,7 @@ Item { MMMapButton { id: filterIndicatorButton - visible: root.state === "view" && __activeProject.filterController?.filteringEnabled + visible: root.state === "view" && __activeProject.filterController?.filteringAvailable iconSource: __style.filterIcon bgndColor: __activeProject.filterController?.filteringEnabled ? __style.positiveColor : __style.polarColor