diff --git a/QgisModelBaker/gui/ili2db_options.py b/QgisModelBaker/gui/ili2db_options.py index d4fa8a377..7859c18d3 100644 --- a/QgisModelBaker/gui/ili2db_options.py +++ b/QgisModelBaker/gui/ili2db_options.py @@ -16,6 +16,8 @@ * * ***************************************************************************/ """ +from osgeo import gdal +from qgis.core import Qgis from qgis.gui import QgsGui, QgsMessageBar from qgis.PyQt.QtCore import QSettings, Qt from qgis.PyQt.QtGui import QValidator @@ -137,6 +139,21 @@ def __init__(self, parent=None, remove_create_tid_group=True): self.create_import_tid_groupbox.setHidden(remove_create_tid_group) + # on gdal versions that dont support multiple geometries per table it's disabled + if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: + self.create_gpkg_multigeom_groupbox.setHidden(True) + else: + self.create_gpkg_multigeom_groupbox.setHidden(False) + self.create_gpkg_multigeom_checkbox.setToolTip( + """ +

If the INTERLIS model has classes that contain multiple geometries, tables with multiple geometry columns can be created in GeoPackage.

+

This function is not standardized and such tables with multiple geometries require GDAL version >= 3.8 to run in QGIS (your current QGIS version is {qgis_version} with GDAL {gdal_version}, but note that others with lower 3.8 versions will not be able to read such tables in the created QGIS project.

+ """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) + ) + self.bar = QgsMessageBar() self.bar.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed) self.layout().addWidget(self.bar, 0, 0, Qt.AlignTop) @@ -177,6 +194,9 @@ def create_import_tid(self): def create_basket_col(self): return self.create_basket_col_checkbox.isChecked() + def create_gpkg_multigeom(self): + return self.create_gpkg_multigeom_checkbox.isChecked() + def inheritance_type(self): if self.smart1_radio_button.isChecked(): return "smart1" @@ -215,6 +235,9 @@ def save_configuration(self): settings.setValue( "QgisModelBaker/ili2db/create_import_tid", self.create_import_tid() ) + settings.setValue( + "QgisModelBaker/ili2db/create_gpkg_multigeom", self.create_gpkg_multigeom() + ) settings.setValue("QgisModelBaker/ili2db/stroke_arcs", self.stroke_arcs()) def restore_configuration(self): @@ -230,12 +253,21 @@ def restore_configuration(self): create_import_tid = settings.value( "QgisModelBaker/ili2db/create_import_tid", defaultValue=True, type=bool ) + create_gpkg_multigeom = settings.value( + "QgisModelBaker/ili2db/create_gpkg_multigeom", + defaultValue=True, + type=bool, + ) stroke_arcs = settings.value( "QgisModelBaker/ili2db/stroke_arcs", defaultValue=True, type=bool ) self.create_basket_col_checkbox.setChecked(create_basket_col) self.create_import_tid_checkbox.setChecked(create_import_tid) + if int(gdal.VersionInfo("VERSION_NUM")) >= 3080000: + self.create_gpkg_multigeom_checkbox.setChecked(create_gpkg_multigeom) + else: + self.create_gpkg_multigeom_checkbox.setChecked(False) self.stroke_arcs_checkbox.setChecked(stroke_arcs) self.toml_file_line_edit.setText(settings.value(self.toml_file_key)) @@ -258,6 +290,10 @@ def load_metaconfig(self, metaconfig_ili2db): self.create_import_tid_checkbox.setChecked( self.current_metaconfig_ili2db.getboolean("importTid") ) + if "gpkgMultiGeomPerTable" in self.current_metaconfig_ili2db: + self.create_gpkg_multigeom.setChecked( + self.current_metaconfig_ili2db.getboolean("gpkgMultiGeomPerTable") + ) if "strokeArcs" in self.current_metaconfig_ili2db: self.stroke_arcs_checkbox.setChecked( self.current_metaconfig_ili2db.getboolean("strokeArcs") @@ -333,6 +369,18 @@ def _restyle_concerning_metaconfig(self): self.create_import_tid_checkbox.setStyleSheet( f"color:{self.COLOR_WARNING}" ) + if "gpkgMultiGeomPerTable" in self.current_metaconfig_ili2db: + if ( + self.current_metaconfig_ili2db.getboolean("gpkgMultiGeomPerTable") + == self.create_gpkg_multigeom_checkbox.isChecked() + ): + self.create_gpkg_multigeom_checkbox.setStyleSheet( + f"color:{self.COLOR_TOPPING}" + ) + else: + self.create_gpkg_multigeom_checkbox.setStyleSheet( + f"color:{self.COLOR_WARNING}" + ) if "strokeArcs" in self.current_metaconfig_ili2db: if ( self.current_metaconfig_ili2db.getboolean("strokeArcs") diff --git a/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py b/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py index 837f2ee65..cbc847daf 100644 --- a/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py +++ b/QgisModelBaker/gui/workflow_wizard/import_schema_configuration_page.py @@ -136,6 +136,9 @@ def update_configuration(self, configuration): configuration.inheritance = self.ili2db_options.inheritance_type() configuration.create_basket_col = self.ili2db_options.create_basket_col() configuration.create_import_tid = self.ili2db_options.create_import_tid() + configuration.create_gpkg_multigeom = ( + self.ili2db_options.create_gpkg_multigeom() + ) configuration.stroke_arcs = self.ili2db_options.stroke_arcs() configuration.pre_script = self.ili2db_options.pre_script() configuration.post_script = self.ili2db_options.post_script() diff --git a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py index 013a20e85..f2efe478a 100644 --- a/QgisModelBaker/gui/workflow_wizard/project_creation_page.py +++ b/QgisModelBaker/gui/workflow_wizard/project_creation_page.py @@ -22,6 +22,7 @@ import re import yaml +from osgeo import gdal from qgis.core import Qgis, QgsProject from qgis.PyQt.QtCore import Qt from qgis.PyQt.QtWidgets import QCompleter, QWizardPage @@ -93,6 +94,7 @@ def __init__(self, parent, title): self.fileValidator = gui_utils.FileValidator( pattern=["*." + ext for ext in self.ValidExtensions], allow_empty=False ) + self.gpkg_multigeometry_frame.setVisible(False) def isComplete(self): return self.is_complete @@ -125,6 +127,8 @@ def restore_configuration(self, configuration): else: self._use_existing(False) + self.gpkg_multigeometry_frame.setVisible(self._multigeom_gpkg()) + self.workflow_wizard.busy(self, False) def _use_existing(self, state): @@ -712,6 +716,50 @@ def _inheritance(self): if setting_record["tag"] == "ch.ehi.ili2db.inheritanceTrafo": return setting_record["setting"] + def _multigeom_gpkg(self): + # this concerns only geopackage + if not (self.workflow_wizard.import_schema_configuration.tool & DbIliMode.gpkg): + return False + + # and when this geopackage has multiple geometry columns in a table + if len(self.db_connector.multiple_geometry_tables()) == 0: + return False + + if int(gdal.VersionInfo("VERSION_NUM")) < 3080000: + self.gpkg_multigeometry_label.setText( + """ + +

This GeoPackage contains at least one table with multiple geometries

+

These tables require GDAL version >= 3.8 to run in QGIS.
Your current QGIS version is {qgis_version} with GDAL {gdal_version}.

+

Means this won't work.

+ + """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) + ) + self.create_project_button.setDisabled(True) + else: + self.gpkg_multigeometry_label.setText( + """ + +

This GeoPackage contains at least one table with multiple geometries

+

These tables require GDAL version >= 3.8 to run in QGIS.
Your current QGIS version is {qgis_version} with GDAL {gdal_version}.

+

But note that others with lower 3.8 version will not be able to read such tables in the created QGIS project.

+ + """.format( + qgis_version=Qgis.QGIS_VERSION, + gdal_version=gdal.VersionInfo("RELEASE_NAME"), + ) + ) + return True + + def _multiple_geometry_gpkg_table(self): + if self.db_connector.multiple_geometry_tables() > 0: + return True + + return false + def help_text(self): logline = self.tr( "Most of the time you won't need to change anything here.
Just press Generate :-)" diff --git a/QgisModelBaker/ui/ili2db_options.ui b/QgisModelBaker/ui/ili2db_options.ui index 57c255756..58d91fc58 100644 --- a/QgisModelBaker/ui/ili2db_options.ui +++ b/QgisModelBaker/ui/ili2db_options.ui @@ -7,7 +7,7 @@ 0 0 552 - 557 + 622 @@ -17,62 +17,58 @@ true - - - - Stroke arcs + + + + <html><head/><body><p><span style=" font-size:large; color:#341d5c;">▪ </span><span style=" color:#341d5c;">corresponds to the metaconfig </span><span style=" font-size:large; color:#c64600;">▪ </span><span style=" color:#c64600;">deviates from the metaconfig</span></p></body></html> + + + Qt::RichText - - - - - If this option is activated, circular arcs are stroked when importing the data - - - Stroke Arcs - - - - - - + + - Inheritance type + Create Import Tid - - - + + + - Form the inheritance hierarchy with a dynamic strategy. The NewClass strategy is used for classes that are -referenced and whose base classes are not mapped using a NewClass strategy. Abstract classes are mapped -using a SubClass strategy. Concrete classes, without a base class or their direct base classes with a SubClass -strategy are mapped using a NewClass strategy. All other classes are mapped using a SuperClass strategy. + <html><head/><body><p>Creates a new column t_ili_tid in all classes, which is mandatory and should be unique, not only for across the current database, but across the whole system.</p><p>Normally you should not enable this option directly, but rely on the INTERLIS model and ili2db. The former should have a line enabling OIDs (preferably with UUIDs) and the latter will make sure the database updates the new column every time a new record is created.</p><p><br/></p></body></html> - smart1Inheritance + Create Import Tid true - - + + + + + + + Create Basket Column + + + + - Form the inheritance hierarchy with a dymamic strategy. Abstract classes are mapped using a SubClass -strategy. Concrete classes are mapped using a NewAndSubClass strategy. + <html><head/><body><p>Creates a new column t_basket in class tables which references entries in the additional table t_ili2db_basket.</p><p>The T_basket column needs to be filled with the basket to which an object belongs.</p><p><span style=" font-weight:600;">Warning</span></p><p>If this option is enabled, it is required to make sure that this column is filled by the database, by default values on QGIS side or manually from the user.</p><p>If<span style=" font-style:italic;"> BASKET OID</span> is defined in the model, it's required to use the basket handling in QGIS. This is currently not automatically detected by the Model Baker and needs to be assured by the user.</p></body></html> - smart2Inheritance + Create Basket Column - + SQL scripts @@ -141,7 +137,36 @@ strategy. Concrete classes are mapped using a NewAndSubClass strategy. - + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Stroke arcs + + + + + + If this option is activated, circular arcs are stroked when importing the data + + + Stroke Arcs + + + + + + + QFrame::StyledPanel @@ -180,67 +205,61 @@ strategy. Concrete classes are mapped using a NewAndSubClass strategy. - - + + - Create Basket Column + Inheritance type - - - + + + - <html><head/><body><p>Creates a new column t_basket in class tables which references entries in the additional table t_ili2db_basket.</p><p>The T_basket column needs to be filled with the basket to which an object belongs.</p><p><span style=" font-weight:600;">Warning</span></p><p>If this option is enabled, it is required to make sure that this column is filled by the database, by default values on QGIS side or manually from the user.</p><p>If<span style=" font-style:italic;"> BASKET OID</span> is defined in the model, it's required to use the basket handling in QGIS. This is currently not automatically detected by the Model Baker and needs to be assured by the user.</p></body></html> + Form the inheritance hierarchy with a dynamic strategy. The NewClass strategy is used for classes that are +referenced and whose base classes are not mapped using a NewClass strategy. Abstract classes are mapped +using a SubClass strategy. Concrete classes, without a base class or their direct base classes with a SubClass +strategy are mapped using a NewClass strategy. All other classes are mapped using a SuperClass strategy. - Create Basket Column + smart1Inheritance + + + true + + + + + + + Form the inheritance hierarchy with a dymamic strategy. Abstract classes are mapped using a SubClass +strategy. Concrete classes are mapped using a NewAndSubClass strategy. + + + smart2Inheritance - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - + + - Create Import Tid + Multiple Geometries per Table in GeoPackage - + - + - <html><head/><body><p>Creates a new column t_ili_tid in all classes, which is mandatory and should be unique, not only for across the current database, but across the whole system.</p><p>Normally you should not enable this option directly, but rely on the INTERLIS model and ili2db. The former should have a line enabling OIDs (preferably with UUIDs) and the latter will make sure the database updates the new column every time a new record is created.</p><p><br/></p></body></html> + <html><head/><body><p>If the INTERLIS model has classes that contain <span style=" font-weight:600;">multiple geometries</span>, tables with multiple geometry columns can be created in <span style=" font-weight:600;">GeoPackage</span>.</p></body></html> - Create Import Tid - - - true + Create Multiple Geometry Columns per Table - - - - <html><head/><body><p><span style=" font-size:large; color:#341d5c;">▪ </span><span style=" color:#341d5c;">corresponds to the metaconfig </span><span style=" font-size:large; color:#c64600;">▪ </span><span style=" color:#c64600;">deviates from the metaconfig</span></p></body></html> - - - Qt::RichText - - - diff --git a/QgisModelBaker/ui/workflow_wizard/project_creation.ui b/QgisModelBaker/ui/workflow_wizard/project_creation.ui index 4478ecc5f..ae71b09b2 100644 --- a/QgisModelBaker/ui/workflow_wizard/project_creation.ui +++ b/QgisModelBaker/ui/workflow_wizard/project_creation.ui @@ -14,18 +14,37 @@ Select Files - - - - Qt::Horizontal - - + + + - 40 - 20 + 0 + 0 - + + + 75 + true + + + + Generate a QGIS Project from an existing database. + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + true + + + + + + + Generate + + @@ -92,51 +111,19 @@ - - - - - 0 - 0 - - - - - 75 - true - - - - Generate a QGIS Project from an existing database. - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - true - - - - - + + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 - - - - 0 - - - @@ -190,11 +177,52 @@ - - - - Generate + + + + 0 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + background-color: rgb(255, 200, 0); + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + GPKG info + + + true + + + +