Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for translated models #971

Merged
merged 4 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion QgisModelBaker/gui/workflow_wizard/project_creation_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from QgisModelBaker.libs.modelbaker.utils.globals import OptimizeStrategy
from QgisModelBaker.libs.modelbaker.utils.qt_utils import make_file_selector
from QgisModelBaker.utils import gui_utils
from QgisModelBaker.utils.globals import CATALOGUE_DATASETNAME
from QgisModelBaker.utils.globals import CATALOGUE_DATASETNAME, displayLanguages
from QgisModelBaker.utils.gui_utils import TRANSFERFILE_MODELS_BLACKLIST, LogLevel

PAGE_UI = gui_utils.get_ui_class("workflow_wizard/project_creation.ui")
Expand All @@ -65,8 +65,10 @@ def __init__(self, parent, title):

self.existing_projecttopping_id = None
self.projecttopping_id = None
self.db_connector = None

self._update_optimize_combo()
self._update_translation_combo()

self.create_project_button.clicked.connect(self._create_project)
self.is_complete = False
Expand Down Expand Up @@ -115,6 +117,9 @@ def restore_configuration(self, configuration):
self.configuration.inheritance = self._inheritance()
self._update_optimize_combo()

# get translation languages
self._update_translation_combo()

# get existing topping
self.existing_topping_checkbox.setVisible(False)
self.existing_projecttopping_id = self._existing_projecttopping_id()
Expand Down Expand Up @@ -231,6 +236,15 @@ def _update_optimize_combo(self):
self.optimize_combo.addItem(self.tr("No optimization"), OptimizeStrategy.NONE)
self.optimize_combo.setCurrentIndex(index)

def _update_translation_combo(self):
self.translation_combo.clear()

if self.db_connector:
for lang in self.db_connector.get_available_languages():
self.translation_combo.addItem(displayLanguages.get(lang, lang), lang)

self.translation_combo.addItem(self.tr("Original model language"), "__")

def _complete_completer(self):
if self.topping_line_edit.hasFocus() and self.topping_line_edit.completer():
if not self.topping_line_edit.text():
Expand Down Expand Up @@ -341,6 +355,7 @@ def _create_project(self):
mgmt_uri=mgmt_uri,
consider_basket_handling=True,
optimize_strategy=self.optimize_combo.currentData(),
preferred_language=self.translation_combo.currentData(),
)
generator.stdout.connect(self.workflow_wizard.log_panel.print_info)
generator.new_message.connect(self.workflow_wizard.log_panel.show_message)
Expand Down
182 changes: 114 additions & 68 deletions QgisModelBaker/ui/workflow_wizard/project_creation.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>Select Files</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0">
<item row="6" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -27,6 +27,97 @@
</property>
</spacer>
</item>
<item row="5" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="description">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Generate a QGIS Project from an existing database.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="inheritance_groupbox">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="optimize_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If you don't get it - nevermind and keep the default. If it's not like expected - try again with 'No optimization'...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Project optimization strategy concerning inheritances</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="optimize_combo">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Hide unused base class layers:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- Base class layers with same named extensions will be &lt;span style=&quot; font-style:italic;&quot;&gt;hidden&lt;/span&gt; and and base class layers with multiple extensions as well. Except if the extension is in the same model, then it's will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;hidden&lt;/span&gt; but &lt;span style=&quot; font-style:italic;&quot;&gt;renamed&lt;/span&gt;.&lt;/p&gt;&lt;p&gt;- Relations of hidden layers will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;created&lt;/span&gt; and with them &lt;span style=&quot; font-style:italic;&quot;&gt;no&lt;/span&gt; widgets&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Group unused base class layers:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- Base class layers with same named extensions will be &lt;span style=&quot; font-style:italic;&quot;&gt;collected in a group&lt;/span&gt; and base class layers with multiple extensions as well. Except if the extension is in the same model, then it's will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;grouped&lt;/span&gt; but &lt;span style=&quot; font-style:italic;&quot;&gt;renamed&lt;/span&gt;.&lt;/p&gt;&lt;p&gt;- Relations of grouped layers will be &lt;span style=&quot; font-style:italic;&quot;&gt;created&lt;/span&gt; but the widgets &lt;span style=&quot; font-style:italic;&quot;&gt;not applied&lt;/span&gt; to the form.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
<string>Hide unused base class layers</string>
</property>
</item>
<item>
<property name="text">
<string>Group unused base class layers</string>
</property>
</item>
<item>
<property name="text">
<string>No optimization</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QGroupBox" name="topping_groupbox">
<property name="title">
Expand Down Expand Up @@ -92,111 +183,66 @@
</layout>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="description">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Generate a QGIS Project from an existing database.</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<widget class="QProgressBar" name="progress_bar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="inheritance_groupbox">
<item row="6" column="1">
<widget class="QCommandLinkButton" name="create_project_button">
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QGroupBox" name="translation_groupbox">
<property name="title">
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0">
<item row="0" column="0">
<widget class="QLabel" name="optimize_label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If you don't get it - nevermind and keep the default. If it's not like expected - try again with 'No optimization'...&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<widget class="QLabel" name="translation_label">
<property name="text">
<string>Project optimization strategy concerning inheritances</string>
<string>Preferred language for database objects like tables and fields</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="optimize_combo">
<widget class="QComboBox" name="translation_combo">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Hide unused base class layers:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- Base class layers with same named extensions will be &lt;span style=&quot; font-style:italic;&quot;&gt;hidden&lt;/span&gt; and and base class layers with multiple extensions as well. Except if the extension is in the same model, then it's will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;hidden&lt;/span&gt; but &lt;span style=&quot; font-style:italic;&quot;&gt;renamed&lt;/span&gt;.&lt;/p&gt;&lt;p&gt;- Relations of hidden layers will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;created&lt;/span&gt; and with them &lt;span style=&quot; font-style:italic;&quot;&gt;no&lt;/span&gt; widgets&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Group unused base class layers:&lt;/span&gt;&lt;/p&gt;&lt;p&gt;- Base class layers with same named extensions will be &lt;span style=&quot; font-style:italic;&quot;&gt;collected in a group&lt;/span&gt; and base class layers with multiple extensions as well. Except if the extension is in the same model, then it's will &lt;span style=&quot; font-style:italic;&quot;&gt;not&lt;/span&gt; be &lt;span style=&quot; font-style:italic;&quot;&gt;grouped&lt;/span&gt; but &lt;span style=&quot; font-style:italic;&quot;&gt;renamed&lt;/span&gt;.&lt;/p&gt;&lt;p&gt;- Relations of grouped layers will be &lt;span style=&quot; font-style:italic;&quot;&gt;created&lt;/span&gt; but the widgets &lt;span style=&quot; font-style:italic;&quot;&gt;not applied&lt;/span&gt; to the form.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<item>
<property name="text">
<string>Hide unused base class layers</string>
<string>English</string>
</property>
</item>
<item>
<property name="text">
<string>Group unused base class layers</string>
<string>French</string>
</property>
</item>
<item>
<property name="text">
<string>No optimization</string>
<string>German</string>
</property>
</item>
<item>
<property name="text">
<string>Italian</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="1">
<widget class="QCommandLinkButton" name="create_project_button">
<property name="text">
<string>Generate</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
7 changes: 7 additions & 0 deletions QgisModelBaker/utils/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
),
}

displayLanguages = {
"en": QCoreApplication.translate("QgisModelBaker", "English"),
"de": QCoreApplication.translate("QgisModelBaker", "German"),
"fr": QCoreApplication.translate("QgisModelBaker", "French"),
"it": QCoreApplication.translate("QgisModelBaker", "Italian"),
}


class AdministrativeDBActionTypes(Enum):
"""Defines constants for modelbaker actions that require superuser login"""
Expand Down