Skip to content

Instantly share code, notes, and snippets.

@signedav
Last active July 31, 2019 15:13
Show Gist options
  • Select an option

  • Save signedav/0d0740690a2d43b9dcfbb9aae630a65b to your computer and use it in GitHub Desktop.

Select an option

Save signedav/0d0740690a2d43b9dcfbb9aae630a65b to your computer and use it in GitHub Desktop.
Store filter expressions on attributetable

QGIS Enhancement: Store filter expressions on attributetable

Date 2019/07/31

Author David Signer @signedav

Contact david at opengis dot ch

maintainer @signedav

Version QGIS 3.10

Summary

In the attribute table the entries can be filtered.

The idea is to have the possiblity to store the expressions used for filtering, name them, and finally have them available in a submenu of the filter section of the attribute table.

Proposed Solution

filter_qep

"Save" or "Save As" button next to the "Apply" button.

The submenu could be under a section called "Stored Filter (Expression)".

-- Show Edited and New Features
-- Field Filter
   |-- fid
   |-- name
   |-- uuid
-- Advanced Filter (Expression)
-- Stored Filter (Expression)
   |-- my_stored_filter 1
   |-- another stored_filter 2

Or it would slimmer, when it's directly in the "Advanced Filter (Expression)" section. But this could lead the user to think, that "Advanced Filter (Expression)" is only a menu section and not a functionality.

-- Advanced Filter (Expression)
   |-- my_stored_filter 1
   |-- another stored_filter 2

If the user does not define a name, it appends the expression text itself to the list.

-- Stored Filter (Expression)
   |-- my_stored_filter 1
   |-- another stored_filter 2
   |-- "id" > 8 

Further Considerations/Improvements

API

Furthermore an API that provides the possiblity to load and read stored expressions or lists of them:

Functions like e.g. for adding a single expression:

/**
* Adds a expression to the stored expressions
*
*  \param name       optional name of the expression
*  \param expression the expression content 
*  \param tag        some content, maybe scope where to be shown
*/
QgsVectorLayer::addStoredExpression( const QString &name, const QString &expression, const QString &tag )

Or for adding a list of expressions:

QgsVectorLayer::addStoredExpressions( QList(< QPair< QString, QString > > namedexpressions, const QString &tag )

Or for reading:

QgsVectorLayer::addStoredExpressions( const QString &tag )

(returning a list of tuples/pairs QList(< QPair< QString, QString > > or maybe in another format)

Reading and writing will be covered with unit tests.

FTF: Other places where the filters can be used

As a future opportunity this stored expressions could be available at other places.

  • Field Calculator
  • Conditional Format rules
  • etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment