Class: QgsAbstractValidityCheck¶
Abstract base class for individual validity checks.
Validity checks represent objects which can run a test using a
QgsValidityCheckContext
, and return the results of the check
via QgsValidityCheckResult
objects.
Checks can be used for many different use cases, e.g. validating a layout’s contents before allowing an export to occur, or validating the contents of a Processing model (and warning if required plugin based providers are not available or if compulsory algorithm parameters have not been populated).
Subclasses must indicate the type of check they represent via the
checkType()
method. When checks are performed, all the
registered checks with a matching check type are performed sequentially.
The check type also dictates the subclass of the
QgsValidityCheckContext
which is given to the subclass’
runCheck method.
Checks must be registered in the application’s
QgsValidityCheckRegistry
, which is accessible via
QgsApplication.validityCheckRegistry()
.
See also
Added in version 3.6.
Note
This is an abstract class, with methods which must be implemented by a subclass.
The following methods must be implemented: checkType()
, create()
, id()
, runCheck()
Enums
Check types |
Abstract Methods
Returns the type of the check. |
|
Creates a new instance of the check and returns it. |
|
Returns the unique ID of the check. |
|
Runs the check and returns a list of results. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsAbstractValidityCheck. See the FAQ for more details.
Prepares the check for execution, and returns |
- class qgis.core.QgsAbstractValidityCheck[source]¶
Bases:
object
- class Type(*values)¶
Bases:
IntEnum
Check types
LayoutCheck
: Print layout validity check, triggered on exporting a print layoutAvailable as
QgsAbstractValidityCheck.TypeLayoutCheck
in older QGIS releases.UserCheck
: Starting point for custom user typesAvailable as
QgsAbstractValidityCheck.TypeUserCheck
in older QGIS releases.
- abstract create(self) QgsAbstractValidityCheck | None [source]¶
Creates a new instance of the check and returns it.
- Return type:
Optional[QgsAbstractValidityCheck]
- abstract id(self) str [source]¶
Returns the unique ID of the check.
This is a non-translated, non-user visible string identifying the check.
- Return type:
str
- virtual prepareCheck(self, context: QgsValidityCheckContext | None, feedback: QgsFeedback | None) bool [source]¶
Prepares the check for execution, and returns
True
if the check can be run.This method is always called from the main thread, and subclasses can implement it to do preparatory steps which are not thread safe (e.g. obtaining feature sources from vector layers). It is followed by a call to
runCheck()
, which may be performed in a background thread.Individual calls to
prepareCheck()
/runCheck()
are run on a new instance of the check (seecreate()
), so subclasses can safely store state from theprepareCheck()
method ready for the subsequentrunCheck()
method.The
context
argument gives the wider in which the check is being run.- Parameters:
context (Optional[QgsValidityCheckContext])
feedback (Optional[QgsFeedback])
- Return type:
bool
- abstract runCheck(self, context: QgsValidityCheckContext | None, feedback: QgsFeedback | None) List[QgsValidityCheckResult] ¶
Runs the check and returns a list of results. If the check is “passed” and no warnings or errors are generated, then an empty list should be returned.
This method may be called in a background thread, so subclasses should take care to ensure that only thread-safe methods are used. It is always preceded by a call to
prepareCheck()
.If a check needs to perform non-thread-safe tests, these should be implemented within
prepareCheck()
and stored in the subclass instance to be returned by this method.The
context
argument gives the wider in which the check is being run.- Parameters:
context (Optional[QgsValidityCheckContext])
feedback (Optional[QgsFeedback])
- Return type:
List[QgsValidityCheckResult]