Skip to content

Commit

Permalink
Allow importing without interlis file
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 26, 2017
1 parent 319dd1c commit 208458f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 53 deletions.
56 changes: 37 additions & 19 deletions projectgenerator/gui/generate_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,49 @@ def __init__(self, parent=None):
self.buttonBox.addButton(QDialogButtonBox.Cancel)
self.buttonBox.addButton(self.tr('Create'), QDialogButtonBox.AcceptRole)
self.ili_file_browse_button.clicked.connect(make_file_selector(self.ili_file_line_edit, title=self.tr('Open Interlis Model'), file_filter=self.tr('Interlis Model File (*.ili)')))
self.type_combo_box.clear()
self.type_combo_box.addItem(self.tr('Interlis'), 'ili')
self.type_combo_box.addItem(self.tr('Postgis'), 'pg')
self.type_combo_box.currentIndexChanged.connect(self.type_changed)

self.restore_configuration()

def accepted(self):
importer = iliimporter.Importer()
configuration = iliimporter.Configuration()

configuration.ilifile = self.ili_file_line_edit.text()
configuration.host = self.pg_host_line_edit.text()
configuration.user = self.pg_user_line_edit.text()
configuration.database = self.pg_database_line_edit.text()
configuration.schema = self.pg_schema_line_edit.text()
configuration.password = self.pg_password_line_edit.text()

importer.configuration = configuration
if self.type_combo_box.currentData() == 'ili':
configuration.ilifile = self.ili_file_line_edit.text()

self.save_configuration(configuration)
importer = iliimporter.Importer()

importer.stdout.connect(self.print_info)
importer.stderr.connect(self.on_stderr)
importer.process_started.connect(self.on_process_started)
importer.process_finished.connect(self.on_process_finished)
if importer.run() == iliimporter.Importer.SUCCESS:
generator = Generator(configuration.uri)
available_layers = generator.layers()
relations = generator.relations(available_layers)
importer.configuration = configuration

project = Project()
project.layers = available_layers
project.relations = relations
self.save_configuration(configuration)

qgis_project = QgsProject.instance()
project.layer_added.connect(self.print_info)
project.create(None, qgis_project)
importer.stdout.connect(self.print_info)
importer.stderr.connect(self.on_stderr)
importer.process_started.connect(self.on_process_started)
importer.process_finished.connect(self.on_process_finished)
if importer.run() != iliimporter.Importer.SUCCESS:
return

generator = Generator(configuration.uri)
available_layers = generator.layers()
relations = generator.relations(available_layers)

project = Project()
project.layers = available_layers
project.relations = relations

qgis_project = QgsProject.instance()
project.layer_added.connect(self.print_info)
project.create(None, qgis_project)

def print_info(self, text):
self.txtStdout.append(text)
Expand Down Expand Up @@ -92,6 +101,7 @@ def save_configuration(self, configuration):
settings.setValue('QgsProjectGenerator/ili2pg/database', configuration.database)
settings.setValue('QgsProjectGenerator/ili2pg/schema', configuration.schema)
settings.setValue('QgsProjectGenerator/ili2pg/password', configuration.password)
settings.setValue('QgsProjectGenerator/importtype', self.type_combo_box.currentData())

def restore_configuration(self):
settings = QSettings()
Expand All @@ -102,6 +112,8 @@ def restore_configuration(self):
self.pg_database_line_edit.setText(settings.value('QgsProjectGenerator/ili2pg/database'))
self.pg_schema_line_edit.setText(settings.value('QgsProjectGenerator/ili2pg/schema'))
self.pg_password_line_edit.setText(settings.value('QgsProjectGenerator/ili2pg/password'))
self.type_combo_box.setCurrentIndex(self.type_combo_box.findData(settings.value('QgsProjectGenerator/importtype', 'pg')))
self.type_changed()

def disable(self):
self.pg_config.setEnabled(False)
Expand All @@ -111,4 +123,10 @@ def disable(self):
def enable(self):
self.pg_config.setEnabled(True)
self.ili_config.setEnabled(True)
self.buttonBox.setEnabled(True)
self.buttonBox.setEnabled(True)

def type_changed(self):
if self.type_combo_box.currentData() == 'ili':
self.ili_config.show()
else:
self.ili_config.hide()
4 changes: 2 additions & 2 deletions projectgenerator/libqgsprojectgen/dataobjects/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ def dump(self):
definition['relations'] = relations

return definition


def load(self, definition):
self.crs = definition['crs']

self.layers=list()
self.layers = list()
for layer_definition in definition['layers']:
layer = Layer()
layer.load(layer_definition)
self.layers.append(layer)


def create(self, path, qgis_project):
for layer in self.layers:
qgis_layer = layer.create()
Expand Down
51 changes: 19 additions & 32 deletions projectgenerator/ui/generate_project.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,19 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<width>718</width>
<height>674</height>
</rect>
</property>
<property name="windowTitle">
<string>Import Interlis</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QComboBox" name="comboBox">
<property name="enabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Interlis</string>
</property>
</item>
<item>
<property name="text">
<string>Postgis</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="2">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout_3">
<item row="3" column="0" colspan="2">
Expand Down Expand Up @@ -206,10 +179,24 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QComboBox" name="type_combo_box">
<item>
<property name="text">
<string>Interlis</string>
</property>
</item>
<item>
<property name="text">
<string>Postgis</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>comboBox</tabstop>
<tabstop>type_combo_box</tabstop>
<tabstop>pg_host_line_edit</tabstop>
<tabstop>pg_user_line_edit</tabstop>
<tabstop>pg_database_line_edit</tabstop>
Expand Down

0 comments on commit 208458f

Please sign in to comment.