本文整理汇总了Python中safe.report.template_composition.TemplateComposition.component_ids方法的典型用法代码示例。如果您正苦于以下问题:Python TemplateComposition.component_ids方法的具体用法?Python TemplateComposition.component_ids怎么用?Python TemplateComposition.component_ids使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.report.template_composition.TemplateComposition
的用法示例。
在下文中一共展示了TemplateComposition.component_ids方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_missing_elements
# 需要导入模块: from safe.report.template_composition import TemplateComposition [as 别名]
# 或者: from safe.report.template_composition.TemplateComposition import component_ids [as 别名]
def test_missing_elements(self):
"""Test if we can get missing elements correctly."""
# Copy the inasafe template to temp dir
template_path = os.path.join(
temp_dir('test'), 'inasafe-portrait-a4.qpt')
shutil.copy2(INASAFE_TEMPLATE_PATH, template_path)
template_composition = TemplateComposition(template_path=template_path)
# No missing elements here
component_ids = ['safe-logo', 'north-arrow', 'organisation-logo',
'impact-map', 'impact-legend']
template_composition.component_ids = component_ids
message = 'There should be no missing elements, but it gets: %s' % (
template_composition.missing_elements)
expected_result = []
self.assertEqual(
template_composition.missing_elements, expected_result, message)
# There are missing elements
component_ids = ['safe-logo', 'north-arrow', 'organisation-logo',
'impact-map', 'impact-legend',
'i-added-element-id-here-nooo']
template_composition.component_ids = component_ids
message = 'There should be no missing elements, but it gets: %s' % (
template_composition.missing_elements)
expected_result = ['i-added-element-id-here-nooo']
self.assertEqual(
template_composition.missing_elements, expected_result, message)
# Remove test dir
shutil.rmtree(temp_dir('test'))
示例2: load_template
# 需要导入模块: from safe.report.template_composition import TemplateComposition [as 别名]
# 或者: from safe.report.template_composition.TemplateComposition import component_ids [as 别名]
def load_template(self, map_settings):
"""Load composer template for merged report.
Validate it as well. The template needs to have:
1. QgsComposerMap with id 'impact-map' for merged impact map.
2. QgsComposerPicture with id 'safe-logo' for InaSAFE logo.
3. QgsComposerLabel with id 'summary-report' for a summary of two
impacts.
4. QgsComposerLabel with id 'aggregation-area' to indicate the area
of aggregation.
5. QgsComposerScaleBar with id 'map-scale' for impact map scale.
6. QgsComposerLegend with id 'map-legend' for impact map legend.
7. QgsComposerPicture with id 'organisation-logo' for organisation
logo.
8. QgsComposerLegend with id 'impact-legend' for map legend.
9. QgsComposerHTML with id 'merged-report-table' for the merged report.
:param map_settings: Map settings.
:type map_settings: QgsMapSettings, QgsMapRenderer
"""
# Create Composition
template_composition = TemplateComposition(
self.template_path, map_settings)
# Validate the component in the template
component_ids = ['impact-map', 'safe-logo', 'summary-report',
'aggregation-area', 'map-scale', 'map-legend',
'organisation-logo', 'merged-report-table']
template_composition.component_ids = component_ids
if len(template_composition.missing_elements) > 0:
raise ReportCreationError(self.tr(
'Components: %s could not be found' % ', '.join(
template_composition.missing_elements)))
# Prepare map substitution and set to composition
impact_title = '%s and %s' % (
self.first_impact['map_title'],
self.second_impact['map_title'])
substitution_map = {
'impact-title': impact_title,
'hazard-title': self.first_impact['hazard_title'],
'disclaimer': self.disclaimer
}
template_composition.substitution = substitution_map
# Load Template
try:
template_composition.load_template()
except TemplateLoadingError:
raise
# Draw Composition
# Set InaSAFE logo
composition = template_composition.composition
safe_logo = composition.getComposerItemById('safe-logo')
safe_logo.setPictureFile(self.safe_logo_path)
# set organisation logo
org_logo = composition.getComposerItemById('organisation-logo')
org_logo.setPictureFile(self.organisation_logo_path)
# Set Map Legend
legend = composition.getComposerItemById('map-legend')
if qgis_version() < 20400:
layers = map_settings.layerSet()
else:
layers = map_settings.layers()
if qgis_version() < 20600:
legend.model().setLayerSet(layers)
legend.synchronizeWithModel()
else:
root_group = legend.modelV2().rootGroup()
layer_ids = map_settings.layers()
for layer_id in layer_ids:
# noinspection PyUnresolvedReferences
layer = QgsMapLayerRegistry.instance().mapLayer(layer_id)
root_group.addLayer(layer)
legend.synchronizeWithModel()
return composition