Beispiel #1
0
    def create_new_document_designer(self, file_path):
        """
        Creates a new document designer and loads the document template
        defined in file path.
        :param file_path: Path to document template
        :type file_path: str
        """
        if not QFile.exists(file_path):
            QMessageBox.critical(
                self.mainWindow(),
                QApplication.translate("OpenTemplateConfig",
                                       "Open Template Error"),
                QApplication.translate(
                    "OpenTemplateConfig",
                    "The specified template does not exist."))
            return

        if not [
                i for i in self.composition().items() if isinstance(
                    i, QgsLayoutItem) and not isinstance(i, QgsLayoutItemPage)
        ]:
            self.mainWindow().close()

        layout = LayoutGuiUtils.create_unique_named_layout()
        layout.initializeDefaults()

        # Load template
        try:
            self.composition().setCustomProperty('variable_template_path',
                                                 file_path)
            self.variable_template_path = file_path
            LayoutUtils.load_template_into_layout(layout, file_path)
        except IOError as e:
            QMessageBox.critical(
                self.mainWindow(),
                QApplication.translate("ComposerWrapper",
                                       "Open Operation Error"),
                "{0}\n{1}".format(
                    QApplication.translate("ComposerWrapper",
                                           "Cannot read template file."),
                    str(e)))

        self._iface.openLayoutDesigner(layout)
Beispiel #2
0
    def xxxloadTemplate(self, filePath):
        """
        Loads a document template into the view and updates the necessary STDM-related composer items.
        """

        try:
            LayoutUtils.load_template_into_layout(self.composition(), filePath)
        except IOError as e:
            QMessageBox.critical(
                self.mainWindow(),
                QApplication.translate("ComposerWrapper",
                                       "Open Operation Error"),
                "{0}\n{1}".format(
                    QApplication.translate("ComposerWrapper",
                                           "Cannot read template file."),
                    str(e)))
            return

        if templateDoc.setContent(templateFile):
            table_config_collection = TableConfigurationCollection.create(
                templateDoc)
            '''
            First load vector layers for the table definitions in the config
            collection before loading the composition from file.
            '''
            load_table_layers(table_config_collection)

            self.clearWidgetMappings()

            # Load items into the composition and configure STDM data controls
            context = QgsReadWriteContext()
            self.composition().loadFromTemplate(templateDoc, context)

            # Load data controls
            composerDS = ComposerDataSource.create(templateDoc)

            # Set title by appending template name
            title = QApplication.translate("STDMPlugin",
                                           "STDM Document Designer")

            composer_el = templateDoc.documentElement()
            if composer_el is not None:
                template_name = ""
                if composer_el.hasAttribute("title"):
                    template_name = composer_el.attribute("title", "")
                elif composer_el.hasAttribute("_title"):
                    template_name = composer_el.attribute("_title", "")

                if template_name:
                    win_title = "{0} - {1}".format(title, template_name)
                    self.mainWindow().setWindowTitle(template_name)

            self._configure_data_controls(composerDS)

            # Load symbol editors
            spatialFieldsConfig = SpatialFieldsConfiguration.create(
                templateDoc)
            self._configureSpatialSymbolEditor(spatialFieldsConfig)

            # Load table editors
            self._configure_table_editors(table_config_collection)

            # Load chart property editors
            chart_config_collection = ChartConfigurationCollection.create(
                templateDoc)
            self._configure_chart_editors(chart_config_collection)

            # Load QR code property editors
            qrc_config_collection = QRCodeConfigurationCollection.create(
                templateDoc)
            self._configure_qr_code_editors(qrc_config_collection)