Closed nyalldawson closed 4 years ago
Sounds like a good case to use a decorator here as well to make the API nice for Python.
@nathanw2 I'm open to that - got an idea of a possible API?
@nyalldawson
@prwelcome
def valid_check():
pass
:)
no but really something like this I guess:
@validity_check(id="checkid", name="Check name")
def runMyCheck( context, feedback):
pass
Yeah ok
Implemented at https://github.com/qgis/QGIS/pull/8589
QGIS Enhancement: An interface and registry for custom validity checks
Date 2018/11/25
Author Nyall Dawson (@nyalldawson )
Contact nyall dot dawson at gmail dot com
Version QGIS 3.6
Summary
Upfront: This is NOT related to geometry validity!!!
This proposal concerns an interface for custom "validity checks", along with a corresponding registry of custom checks and GUI widgets for summarising check results.
Initially the proposal is focused toward print layout validity checks, but the interface has been designed to be generic enough to allow alternative types of validity checks (e.g. project save validity checks, processing model validity checks, etc. More details later).
The API is designed to be used both by internal validity checks and also to be extended by custom, organisation-specific validity checks. E.g., for print layout validity checks we could have:
In built checks:
Possible organisation specific checks, implemented via Python
The checks would be performed by iterating through the validity checks of the corresponding type which have been registered in the registry, and collating the results. A reusable gui widget would then present a summary of the checks which failed/triggered warnings, along with detailed explanatory text.
In the initial use case, BEFORE exporting a print layout, the layout designer will run through all registered layout related checks and if any errors or warnings are found present a dialog summarising these to the user. If errors were found, the export will be blocked until these errors are resolved.
API
QgsAbstractValidityCheck
QgsAbstractValidityCheck
is the abstract base class for validity checks. Individual checks must implement this interface.QgsValidityCheckContext
QgsValidityCheckContext
gives the context under which the check is being run. Much likeQEvent
, it is designed to be subclassed for each individual check type. E.g.QgsLayoutValidityCheckContext
would subclassQgsValidityCheckContext
.QgsValidityCheckResult
QgsValidityCheckResult
encapsulates the result of a validity check.QgsValidityCheckRegistry
QgsValidityCheckRegistry
contains instances of all the inbuilt and custom (Python plugin based) checks. It will follow the same format as the existing QGIS registry classes, and an instance will be attached toQgsApplication
.One specialised method will be available in
QgsValidityCheckResult
which runs all checks of the specified type and returns the collated results:Widgets
A custom, reusable widget
QgsValidityCheckResultsWidget
will be created which shows a summary of the results of checks (with icons showing the result type, e.g. warnings only or critical errors).Example
An example check,
QgsLayoutMapCrsValidityCheck
, could be implemented using the following psuedo-code:Further Considerations/Improvements
In future, when the need arises, the check API could be extended to allow for custom actions for check results. These would allow users easy access to fix problems which have automated solutions available. This API could be modelled of the current QgsGeometryCheck API, which covers a similar use case.
Backwards Compatibility
N/A
Votes
(required)