mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
This allows nice and simple, elegant construction of checks for Python. To use, Python based checks should use the decorator syntax: from qgis.core import check @check.register(type=QgsAbstractValidityCheck.TypeLayoutCheck) def my_layout_check(context, feedback): results = ... return results Or, a more complete example. This one throws a warning when attempting to export a layout with a map item set to the Web Mercator projection: @check.register(type=QgsAbstractValidityCheck.TypeLayoutCheck) def layout_map_crs_choice_check(context, feedback): layout = context.layout results = [] for i in layout.items(): if isinstance(i, QgsLayoutItemMap) and i.crs().authid() == 'EPSG:3857': res = QgsValidityCheckResult() res.type = QgsValidityCheckResult.Warning res.title='Map projection is misleading' res.detailedDescription='The projection for the map item {} is set to <i>Web Mercator (EPSG:3857)</i> which misrepresents areas and shapes. Consider using an appropriate local projection instead.'.format(i.displayName()) results.append(res) return results
55 lines
2.6 KiB
Python
55 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
***************************************************************************
|
|
__init__.py
|
|
---------------------
|
|
Date : May 2014
|
|
Copyright : (C) 2014 by Nathan Woodrow
|
|
Email : woodrow dot nathan at gmail dot com
|
|
***************************************************************************
|
|
* *
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
***************************************************************************
|
|
"""
|
|
|
|
__author__ = 'Nathan Woodrow'
|
|
__date__ = 'May 2014'
|
|
__copyright__ = '(C) 2014, Nathan Woodrow'
|
|
# This will get replaced with a git SHA1 when you do a git archive
|
|
__revision__ = '$Format:%H$'
|
|
|
|
from qgis.PyQt.QtCore import NULL
|
|
from qgis._core import *
|
|
|
|
from .additions.edit import edit, QgsEditError
|
|
from .additions.fromfunction import fromFunction
|
|
from .additions.metaenum import metaEnumFromType, metaEnumFromValue
|
|
from .additions.processing import processing_output_layer_repr, processing_source_repr
|
|
from .additions.projectdirtyblocker import ProjectDirtyBlocker
|
|
from .additions.qgsfeature import mapping_feature
|
|
from .additions.qgsfunction import register_function, qgsfunction
|
|
from .additions.qgsgeometry import _geometryNonZero, mapping_geometry
|
|
from .additions.qgssettings import _qgssettings_enum_value, _qgssettings_set_enum_value, _qgssettings_flag_value
|
|
from .additions.qgstaskwrapper import QgsTaskWrapper
|
|
from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory
|
|
from .additions.validitycheck import check
|
|
|
|
# Injections into classes
|
|
QgsFeature.__geo_interface__ = property(mapping_feature)
|
|
QgsGeometry.__bool__ = _geometryNonZero
|
|
QgsGeometry.__geo_interface__ = property(mapping_geometry)
|
|
QgsGeometry.__nonzero__ = _geometryNonZero
|
|
QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr
|
|
QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr
|
|
QgsProject.blockDirtying = ProjectDirtyBlocker
|
|
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
|
|
QgsSettings.enumValue = _qgssettings_enum_value
|
|
QgsSettings.setEnumValue = _qgssettings_set_enum_value
|
|
QgsSettings.flagValue = _qgssettings_flag_value
|
|
QgsTask.fromFunction = fromFunction
|