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
30 changes: 18 additions & 12 deletions app/filtercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, QgsMapLayer *> layers = QgsProject::instance()->mapLayers();
for ( auto it = layers.constBegin(); it != layers.constEnd(); ++it )
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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 )
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/filtercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class FilterController : public QObject


signals:
void filtersChanged();
void hasActiveFiltersChanged();
void layerFilterChanged( const QString &layerId );
void hasFiltersAvailableChanged();
Expand Down
6 changes: 3 additions & 3 deletions app/qml/filters/MMFiltersPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,6 +69,7 @@ MMComponents.MMDrawer {

onClicked: {
__activeProject.filterController.clearAllFilters()
inputRepeater.model = __activeProject.filterController.getFilters()
}
}

Expand Down
8 changes: 7 additions & 1 deletion app/qml/filters/components/MMFilterTextEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
8 changes: 7 additions & 1 deletion app/qml/filters/components/MMFilterTextInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand All @@ -84,4 +84,10 @@ MMPrivateComponents.MMBaseSingleLineInput {
root.checked = false
}
}

Component.onCompleted: {
if ( root.text ) {
root.checked = true
}
}
}
2 changes: 1 addition & 1 deletion app/qml/map/MMMapController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading