Skip to content

Commit

Permalink
Merge pull request #269 from isogeo/add_layers
Browse files Browse the repository at this point in the history
Adding layer from PostGIS table
  • Loading branch information
SimonSAMPERE committed Oct 7, 2019
2 parents 8329a6f + e18d7f6 commit 57d23a1
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
10 changes: 1 addition & 9 deletions isogeo.py
Expand Up @@ -42,8 +42,7 @@
from qgis.core import (
QgsCoordinateReferenceSystem,
QgsMessageLog,
QgsRectangle,
QgsApplication,
QgsRectangle
)


Expand Down Expand Up @@ -850,12 +849,6 @@ def run(self):
self.auth_slot
)


""" ------ CUSTOM CONNECTIONS ------------------------------------- """
# get shares only if user switch on tabs
# catch QGIS log messages - see: https://gis.stackexchange.com/a/223965/19817
QgsApplication.messageLog().messageReceived.connect(plg_tools.error_catcher)

""" ------- EXECUTED AFTER PLUGIN IS LAUNCHED --------------------- """
self.form_mng.setWindowTitle("Isogeo - {}".format(self.plg_version))
# add translator method in others modules
Expand All @@ -872,7 +865,6 @@ def run(self):
# launch authentication
self.user_authentication()


# #############################################################################
# ##### Stand alone program ########
# ##################################
Expand Down
9 changes: 7 additions & 2 deletions modules/layer/add_layer.py
Expand Up @@ -20,6 +20,7 @@
QgsVectorLayer,
QgsRasterLayer,
QgsMessageLog,
QgsApplication
)
from qgis.utils import iface

Expand Down Expand Up @@ -101,6 +102,11 @@ def __init__(self):
self.tr = None
self.md_sync = MetadataSynchronizer()

# add layer from PostGIS table
self.PostGISdict = object
# catch QGIS log messages - see: https://gis.stackexchange.com/a/223965/19817
QgsApplication.messageLog().messageReceived.connect(plg_tools.error_catcher)

def build_efs_url(
self, api_layer, srv_details, rsc_type="ds_dyn_lyr_srv", mode="complete"
):
Expand Down Expand Up @@ -693,7 +699,6 @@ def adding(self, layer_info):
layer_info = layer_info[1]
else:
pass

self.md_sync.tr = self.tr

if type(layer_info) == list:
Expand Down Expand Up @@ -904,7 +909,7 @@ def adding(self, layer_info):
pass

# If the data is a PostGIS table
elif type(layer_info) == dict:
elif isinstance(layer_info, dict):
logger.debug("Data type: PostGIS")
# Give aliases to the data passed as arguement
base_name = layer_info.get("base_name", "")
Expand Down
4 changes: 2 additions & 2 deletions modules/layer/metadata_sync.py
Expand Up @@ -27,9 +27,8 @@ def __init__(self):

def basic_sync(self, layer, info):
logger.debug("Filling {} layer's properties from : {}".format(layer.name, info))
layer_type = info[0]
# If the data is a PostGIS table
if type(info) == dict:
if isinstance(info, dict):
self.filling_field(
layer,
info.get("title", "notitle"),
Expand All @@ -38,6 +37,7 @@ def basic_sync(self, layer, info):
)
# If the data is a file or a service
else:
layer_type = info[0]
# vector or raster file
if layer_type in file_types:
self.filling_field(layer, info[2], info[3], info[4])
Expand Down
1 change: 1 addition & 0 deletions modules/results/display.py
Expand Up @@ -103,6 +103,7 @@ def __init__(self, search_form_manager: object):
self.layer_adder.tbl_result = self.tbl_result
self.add_layer = self.layer_adder.adding
self.pg_connections = self.build_postgis_dict(qsettings)
self.layer_adder.PostGISdict = self.pg_connections

self.cache_mng = CacheManager()
self.cache_mng.tr = self.tr
Expand Down
8 changes: 4 additions & 4 deletions modules/tools.py
Expand Up @@ -47,8 +47,8 @@ class IsogeoPlgTools(IsogeoUtils):
"""Inheritance from Isogeo Python SDK utils class. It adds some
specific tools for QGIS plugin."""

last_error = None
tr = object
last_error = list

def __init__(self):
"""Check and manage authentication credentials."""
Expand All @@ -58,11 +58,11 @@ def __init__(self):
def error_catcher(self, msg, tag, level):
"""Catch QGIS error messages for introspection."""
if tag == "WMS" and level != 0:
self.last_error = "wms", msg
self.last_error = ["wms", msg]
elif tag == "WFS" and level != 0:
self.last_error = "wfs", msg
self.last_error = ["wfs", msg]
elif tag == "PostGIS" and level != 0:
self.last_error = "postgis", msg
self.last_error = ["postgis", msg]
else:
pass

Expand Down

0 comments on commit 57d23a1

Please sign in to comment.