from qgis.core import QgsComposition, QgsCompositionChecker # create a new composition comp = QgsComposition() # add a map to the composition map_item = QgsComposerMap(comp, 0, 0, 10, 10) comp.addItem(map_item) # create a composition checker checker = QgsCompositionChecker() # run the validity check result = checker.testComposition(comp) # print the result print(result.isValid)
from qgis.core import QgsComposition, QgsComposerLabel, QgsCompositionChecker # create a new composition comp = QgsComposition() # add a label to the composition label_item = QgsComposerLabel(comp) comp.addItem(label_item) # create a composition checker checker = QgsCompositionChecker() # run the validity check result = checker.testComposition(comp) # print the result print(result.errors)This example creates a new composition and adds a label element to it. It then creates a `QgsCompositionChecker` instance and runs the `testComposition` method on the composition. The validity of the composition is checked and any errors are printed. The package library in use here is the QGIS Python library.