Skip to content

Commit

Permalink
set layer's crs added by the plugin to the selected crs
Browse files Browse the repository at this point in the history
  • Loading branch information
myarjunar committed Jun 6, 2017
1 parent c04257b commit 21c0c5e
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def remove_plugin_toolbar(self):
self.iface.mainWindow().removeToolBar(self.plugin_toolbar)
self.plugin_toolbar.hide()

def set_database_connection(self, connection=None):
def set_database_connection(self, connection=None, crs=None):
""" Create a database connection
"""
# fetch settings
Expand All @@ -171,20 +171,23 @@ def set_database_connection(self, connection=None):
settings_plugin.beginGroup(metadata.name().replace(" ", "_"))
settings_postgis.beginGroup('PostgreSQL/connections')
self.connection = connection
self.crs = crs
if not bool(self.connection):
# fetch pre-chosen database connection
self.connection = settings_plugin.value("DatabaseConnection", None)
# check if still exists
if bool(self.connection):
if self.connection not in settings_postgis.childGroups():
settings_plugin.setValue("DatabaseConnection", "")
connection = None
self.connection = None
# fetch from user if necessary
if not bool(self.connection):
dialog = DatabaseConnectionDialog()
dialog.show()
if bool(dialog.exec_()):
self.connection = dialog.get_database_connection()
self.crs = QgsCoordinateReferenceSystem(
dialog.get_crs().get('auth_id'))
settings_plugin.setValue("DatabaseConnection", self.connection)
# validate database connection
if bool(self.connection):
Expand Down Expand Up @@ -299,6 +302,8 @@ def refresh_layers(self):
required_layer.layer = layer
self.iface.legendInterface().setLayerVisible(
layer, True)
if self.crs:
layer.setCrs(self.crs)
self.iface.zoomToActiveLayer()

def manage_beacons(self):
Expand Down Expand Up @@ -345,9 +350,10 @@ def manage_database_connection(self):
""" Action to select the db connection to work with.
"""
database_manager = DatabaseManager()
connection = database_manager.current_connection
connection = database_manager.get_current_connection()
crs = database_manager.get_current_crs()
if connection:
self.set_database_connection(connection=connection)
self.set_database_connection(connection=connection, crs=crs)


class DatabaseManager():
Expand All @@ -356,13 +362,23 @@ def __init__(self):
self.dialog = DatabaseConnectionDialog()
self.dialog.show()
self.current_connection = None
self.current_crs = None
if bool(self.dialog.exec_()):
self.current_connection = self.dialog.get_database_connection()
self.current_crs = self.dialog.get_crs()
settings_plugin = QSettings()
settings_plugin.beginGroup(metadata.name().replace(" ", "_"))
settings_plugin.setValue(
"DatabaseConnection", self.current_connection)

def get_current_connection(self):

return self.current_connection

def get_current_crs(self):

return self.current_crs


class BeaconManager():

Expand Down

0 comments on commit 21c0c5e

Please sign in to comment.