Skip to content

Commit 4ea32bb

Browse files
Enhances logging messages for missing filter fields. Add check for target field
1 parent 7598aad commit 4ea32bb

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

app/filtercontroller.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,37 @@ void FilterController::loadFilterConfig( const QgsProject *project )
131131
newFieldFilter.sqlExpression = filterObject.value( QStringLiteral( "sql_expression" ) ).toString();
132132
newFieldFilter.layerId = filterObject.value( QStringLiteral( "layer_id" ) ).toString();
133133

134+
// check for missing filter fields
135+
QStringList missingFilterFields;
136+
if ( newFieldFilter.layerId.isEmpty() ) missingFilterFields << QStringLiteral( "'layer_id'" );
137+
if ( newFieldFilter.fieldName.isEmpty() ) missingFilterFields << QStringLiteral( "'field_name'" );
138+
if ( newFieldFilter.sqlExpression.isEmpty() ) missingFilterFields << QStringLiteral( "'sql_expression'" );
139+
140+
if ( !missingFilterFields.isEmpty() )
141+
{
142+
CoreUtils::log( QStringLiteral( "Feature Filtering" ),
143+
QStringLiteral( "Filter '%1' is missing required filter field(s): %2. Skipping." )
144+
.arg( newFieldFilter.filterName, missingFilterFields.join( QStringLiteral( ", " ) ) ) );
145+
continue;
146+
}
147+
148+
// check if target layer exists
134149
const QgsVectorLayer *filterLayer = qobject_cast<QgsVectorLayer *>( project->mapLayer( newFieldFilter.layerId ) );
135150
if ( !filterLayer )
136151
{
137152
CoreUtils::log( QStringLiteral( "Feature Filtering" ),
138-
QStringLiteral( "Filter '%1' is not properly configured in the project. Skipping filter." )
139-
.arg( newFieldFilter.filterName ) );
153+
QStringLiteral( "Filter '%1' has no layer with ID '%2' found in project. Skipping." )
154+
.arg( newFieldFilter.filterName, newFieldFilter.layerId ) );
155+
continue;
156+
}
157+
158+
// check if target field of target layer exists
159+
if ( filterLayer->fields().lookupField( newFieldFilter.fieldName ) < 0 )
160+
{
161+
CoreUtils::log( QStringLiteral( "Feature Filtering" ),
162+
QStringLiteral( "Filter '%1' has no target field '%2' found on layer '%3' (%4). Skipping." )
163+
.arg( newFieldFilter.filterName, newFieldFilter.fieldName,
164+
filterLayer->name(), newFieldFilter.layerId ) );
140165
continue;
141166
}
142167

0 commit comments

Comments
 (0)