Skip to content

Commit 4d26e10

Browse files
authoredNov 29, 2020
Merge pull request #40321 from elpaso/bugfix-gh40316-filtering-error
Do not silently fail while filtering on exp error
2 parents 61e9e29 + d79e1a9 commit 4d26e10

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed
 

‎python/gui/auto_generated/attributetable/qgsattributetablefiltermodel.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ Emitted when the filtering of the features has been done
234234
void visibleReloaded();
235235
%Docstring
236236
Emitted when the the visible features on extend are reloaded (the list is created)
237+
%End
238+
239+
void filterError( const QString &errorMessage );
240+
%Docstring
241+
Emitted when an error occurred while filtering features
242+
243+
.. versionadded:: 3.18
237244
%End
238245

239246
protected:

‎src/gui/attributetable/qgsattributetablefiltermodel.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,20 @@ void QgsAttributeTableFilterModel::filterFeatures()
503503

504504
QgsFeature f;
505505

506+
// Record the first evaluation error
507+
QString error;
508+
506509
while ( featIt.nextFeature( f ) )
507510
{
508511
mFilterExpressionContext.setFeature( f );
509512
if ( mFilterExpression.evaluate( &mFilterExpressionContext ).toInt() != 0 )
510513
filteredFeatures << f.id();
511514

512515
// check if there were errors during evaluating
513-
if ( mFilterExpression.hasEvalError() )
514-
break;
516+
if ( mFilterExpression.hasEvalError() && error.isEmpty() )
517+
{
518+
error = mFilterExpression.evalErrorString( );
519+
}
515520
}
516521

517522
featIt.close();
@@ -521,6 +526,12 @@ void QgsAttributeTableFilterModel::filterFeatures()
521526
QApplication::restoreOverrideCursor();
522527

523528
emit featuresFiltered();
529+
530+
if ( ! error.isEmpty() )
531+
{
532+
emit filterError( error );
533+
}
534+
524535
}
525536

526537

‎src/gui/attributetable/qgsattributetablefiltermodel.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,12 @@ class GUI_EXPORT QgsAttributeTableFilterModel: public QSortFilterProxyModel, pub
258258
*/
259259
void visibleReloaded();
260260

261+
/**
262+
* Emitted when an error occurred while filtering features
263+
* \since QGIS 3.18
264+
*/
265+
void filterError( const QString &errorMessage );
266+
261267
protected:
262268

263269
/**

‎src/gui/attributetable/qgsdualview.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "qgsshortcutsmanager.h"
4545
#include "qgsfieldconditionalformatwidget.h"
4646
#include "qgsmapcanvasutils.h"
47+
#include "qgsmessagebar.h"
4748

4849

4950
QgsDualView::QgsDualView( QWidget *parent )
@@ -293,6 +294,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
293294
case QgsAttributeTableFilterModel::ShowEdited:
294295
case QgsAttributeTableFilterModel::ShowFilteredList:
295296
disconnect( mFilterModel, &QgsAttributeTableFilterModel::featuresFiltered, this, &QgsDualView::filterChanged );
297+
disconnect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
296298
break;
297299

298300
case QgsAttributeTableFilterModel::ShowSelected:
@@ -332,6 +334,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
332334
case QgsAttributeTableFilterModel::ShowEdited:
333335
case QgsAttributeTableFilterModel::ShowFilteredList:
334336
connect( mFilterModel, &QgsAttributeTableFilterModel::featuresFiltered, this, &QgsDualView::filterChanged );
337+
connect( mFilterModel, &QgsAttributeTableFilterModel::filterError, this, &QgsDualView::filterError );
335338
break;
336339

337340
case QgsAttributeTableFilterModel::ShowSelected:
@@ -599,6 +602,14 @@ void QgsDualView::flashButtonClicked( bool clicked )
599602
canvas->flashFeatureIds( mLayer, mFeatureListView->currentEditSelection() );
600603
}
601604

605+
void QgsDualView::filterError( const QString &errorMessage )
606+
{
607+
if ( mEditorContext.mainMessageBar() )
608+
{
609+
mEditorContext.mainMessageBar()->pushWarning( tr( "An error occurred while filtering features" ), errorMessage );
610+
}
611+
}
612+
602613
void QgsDualView::featureListAboutToChangeEditSelection( bool &ok )
603614
{
604615
if ( mLayer->isEditable() && !mAttributeForm->save() )

‎src/gui/attributetable/qgsdualview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
388388

389389
void flashButtonClicked( bool clicked );
390390

391+
void filterError( const QString &errorMessage );
392+
391393
private:
392394

393395
/**

0 commit comments

Comments
 (0)
Please sign in to comment.