diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/CMakeLists.txt b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/CMakeLists.txt index 3e7111047f3..41e201b14d8 100644 --- a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/CMakeLists.txt +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/CMakeLists.txt @@ -3,5 +3,5 @@ SET (DB_MANAGER_POSTGIS_TOPOVIEW_DIR ${DB_MANAGER_POSTGIS_DIR}/plugins/qgis_topo FILE(GLOB PY_FILES *.py) INSTALL(FILES ${PY_FILES} DESTINATION ${DB_MANAGER_POSTGIS_TOPOVIEW_DIR}) -INSTALL(FILES topoview_template.qgs DESTINATION ${DB_MANAGER_POSTGIS_TOPOVIEW_DIR}) +ADD_SUBDIRECTORY(templates) diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py index e6439264bc2..02f3c74f0e2 100644 --- a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/__init__.py @@ -23,6 +23,7 @@ Based on qgis_pgis_topoview by Sandro Santilli from PyQt4.QtCore import * from PyQt4.QtGui import * +from qgis.core import * import os current_path = os.path.dirname(__file__) @@ -58,6 +59,7 @@ def run(item, action, mainwindow): db = item.database() uri = db.uri() conninfo = uri.connectionInfo() + iface = mainwindow.iface # check if the selected item is a topology schema isTopoSchema = False @@ -72,40 +74,62 @@ def run(item, action, mainwindow): QMessageBox.critical(mainwindow, "Invalid topology", u'Schema "%s" is not registered in topology.topology.' % item.schema().name) return False - # create the new project from the template one - tpl_name = u'topoview_template.qgs' + # load layers into the current project toponame = item.schema().name - project_name = u'topoview_%s_%s.qgs' % (uri.database(), toponame) + template_dir = os.path.join(current_path, 'templates') + registry = QgsMapLayerRegistry.instance() + legend = iface.legendInterface() - template_file = os.path.join(current_path, tpl_name) - inf = QFile( template_file ) - if not inf.exists(): - QMessageBox.critical(mainwindow, "Error", u'Template "%s" not found!' % template_file) - return False + group = legend.addGroup(toponame + ' topology') - project_file = os.path.join(current_path, project_name) - outf = QFile( project_file ) - if not outf.open( QIODevice.WriteOnly ): - QMessageBox.critical(mainwindow, "Error", u'Unable to open "%s"' % project_file) - return False + # node + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".node', 'geom', 'node_id', toponame + '.nodes') + layer.loadNamedStyle(os.path.join(template_dir, 'node.qml')) + registry.addMapLayer(layer) + legend.moveLayer(layer, group) - if not inf.open( QIODevice.ReadOnly ): - QMessageBox.critical(mainwindow, "Error", u'Unable to open "%s"' % template_file) - return False + # edge + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".edge_data', 'geom', 'edge_id', toponame + '.edges') + layer.loadNamedStyle(os.path.join(template_dir, 'edge_style.qml')) + registry.addMapLayer(layer) + legend.moveLayer(layer, group) - while not inf.atEnd(): - l = inf.readLine() - l = l.replace( u"dbname='@@DBNAME@@'", conninfo.toUtf8() ) - l = l.replace( u'@@TOPONAME@@', toponame ) - outf.write( l ) + # face_left + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".edge_data', 'geom', 'edge_id', toponame + '.face_left') + layer.loadNamedStyle(os.path.join(template_dir, 'face_left.qml')) + registry.addMapLayer(layer) + legend.moveLayer(layer, group) - inf.close() - outf.close() + # face_right + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".edge_data', 'geom', 'edge_id', toponame + '.face_right') + layer.loadNamedStyle(os.path.join(template_dir, 'face_right.qml')) + registry.addMapLayer(layer) + legend.moveLayer(layer, group) + + # next_left + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".edge_data', 'geom', 'edge_id', toponame + '.next_left') + layer.loadNamedStyle(os.path.join(template_dir, 'next_left.qml')) + registry.addMapLayer(layer) + legend.setLayerVisible(layer, False) + legend.moveLayer(layer, group) + + # next_right + layer = db.toSqlLayer('SELECT * FROM "' + toponame + '".edge_data', 'geom', 'edge_id', toponame + '.next_right') + layer.loadNamedStyle(os.path.join(template_dir, 'next_right.qml')) + registry.addMapLayer(layer) + legend.setLayerVisible(layer, False) + legend.moveLayer(layer, group) + + # face_seed + layer = db.toSqlLayer('SELECT face_id, ST_PointOnSurface(topology.ST_GetFaceGeometry(\'' + toponame + '\', face_id)) as geom FROM "' + toponame + '".face WHERE face_id > 0', 'geom', 'face_id', toponame + '.face_seed') + layer.loadNamedStyle(os.path.join(template_dir, 'face_seed.qml')) + registry.addMapLayer(layer) + legend.setLayerVisible(layer, False) + legend.moveLayer(layer, group) + + # TODO: add full faces ? + # TODO: add polygon0, polygon1 and polygon2 ? + # TODO: disable signals while adding all layers, then send a single one - # load the project on QGis canvas - iface = mainwindow.iface - iface.newProject( True ) - if iface.mapCanvas().layerCount() == 0: - iface.addProject( project_file ) return True diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/CMakeLists.txt b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/CMakeLists.txt new file mode 100644 index 00000000000..be934aa3148 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/CMakeLists.txt @@ -0,0 +1,5 @@ +SET (DB_MANAGER_POSTGIS_TOPOVIEW_TEMPLATE_DIR ${DB_MANAGER_POSTGIS_DIR}/plugins/qgis_topoview/templates) + +FILE(GLOB QML_FILES *.qml) + +INSTALL(FILES ${QML_FILES} DESTINATION ${DB_MANAGER_POSTGIS_TOPOVIEW_TEMPLATE_DIR}) diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/edge_style.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/edge_style.qml new file mode 100644 index 00000000000..0817f7c3cf6 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/edge_style.qml @@ -0,0 +1,293 @@ + + + 255 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edge_id + + + + + + + + + + + + + + + . + + . + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_left.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_left.qml new file mode 100644 index 00000000000..f716081c48e --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_left.qml @@ -0,0 +1,136 @@ + + + 0 + + + + + + hard:circle + 2 + pixels + + + + + SolidLine + 0.26 + + NoBrush + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edge_id + + + + + + + + + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_right.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_right.qml new file mode 100644 index 00000000000..e4670fc1ed1 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_right.qml @@ -0,0 +1,136 @@ + + + 0 + + + + + + hard:circle + 2 + pixels + + + + + SolidLine + 0.26 + + NoBrush + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edge_id + + + + + + + + + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_seed.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_seed.qml new file mode 100644 index 00000000000..abb6ba91be3 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/face_seed.qml @@ -0,0 +1,128 @@ + + + 255 + + + + + + hard:regular_star + 2.3 + pixels + + + + + SolidLine + 0.26 + + SolidPattern + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + face_id + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_left.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_left.qml new file mode 100644 index 00000000000..1989c36e6f9 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_left.qml @@ -0,0 +1,136 @@ + + + 0 + + + + + + hard:circle + 2 + pixels + + + + + SolidLine + 0.26 + + NoBrush + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edge_id + + + + + + + + + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_right.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_right.qml new file mode 100644 index 00000000000..7d5c6ea0420 --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/next_right.qml @@ -0,0 +1,136 @@ + + + 0 + + + + + + hard:circle + 2 + pixels + + + + + SolidLine + 0.26 + + NoBrush + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + edge_id + + + + + + + + + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/node.qml b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/node.qml new file mode 100644 index 00000000000..6af64d1ed7a --- /dev/null +++ b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/templates/node.qml @@ -0,0 +1,129 @@ + + + 255 + + + + + + hard:circle + 4 + pixels + + + + + SolidLine + 0.26 + + SolidPattern + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + node_id + + + + + + + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + ../../../../../../../../../src/qgis/plugins/db_manager/db_manager/db_plugins/postgis/plugins/qgis_topoview + + diff --git a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/topoview_template.qgs b/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/topoview_template.qgs deleted file mode 100644 index 51da32d3398..00000000000 --- a/python/plugins/db_manager/db_plugins/postgis/plugins/qgis_topoview/topoview_template.qgs +++ /dev/null @@ -1,1121 +0,0 @@ - - - - - degrees - - 32.062776 - -4.396154 - 49.384339 - 6.416827 - - 0 - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - degrees - - 0.000000 - 0.000000 - 0.000000 - 0.000000 - - 0 - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - - - - Query1Layer20110526144457416 - dbname='@@DBNAME@@' key='face_id' table="(SELECT face_id, ST_PointOnSurface(topology.ST_GetFaceGeometry('@@TOPONAME@@', face_id)) from @@TOPONAME@@.face where face_id > 0 -)" (st_pointonsurface) sql= - face seed - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 255 - postgres - - - - - - - hard:regular_star - 2.3 - pixels - - - - - SolidLine - 0.26 - - SolidPattern - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - face_id - - - - - - - - - - - - - edge_data20110504083012449 - dbname='@@DBNAME@@' key='edge_id' table="@@TOPONAME@@"."edge_data" (geom) sql= - edge - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 255 - postgres - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edge_id - - - - - - - - - - - - - - - - - - - - - edge_data20110504094415605 - dbname='@@DBNAME@@' key='edge_id' table="@@TOPONAME@@"."edge_data" (geom) sql= - face_left - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 0 - postgres - - - - - - - hard:circle - 2 - pixels - - - - - SolidLine - 0.26 - - NoBrush - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edge_id - - - - - - - - - - - - - - - - - - - - - edge_data20110504094539733 - dbname='@@DBNAME@@' key='edge_id' table="@@TOPONAME@@"."edge_data" (geom) sql= - face_right - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 0 - postgres - - - - - - - hard:circle - 2 - pixels - - - - - SolidLine - 0.26 - - NoBrush - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edge_id - - - - - - - - - - - - - - - - - - - - - edge_data20110504112431391 - dbname='@@DBNAME@@' key='edge_id' table="@@TOPONAME@@"."edge_data" (geom) sql= - next_left_face - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 0 - postgres - - - - - - - hard:circle - 2 - pixels - - - - - SolidLine - 0.26 - - NoBrush - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edge_id - - - - - - - - - - - - - - - - - - - - - edge_data20110504112636129 - dbname='@@DBNAME@@' key='edge_id' table="@@TOPONAME@@"."edge_data" (geom) sql= - next_right_face - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 0 - postgres - - - - - - - hard:circle - 2 - pixels - - - - - SolidLine - 0.26 - - NoBrush - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - edge_id - - - - - - - - - - - - - - - - - - - - - node20110504083015129 - dbname='@@DBNAME@@' key='node_id' table="@@TOPONAME@@"."node" (geom) sql= - node - - - +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs - 3452 - 4326 - EPSG:4326 - WGS 84 - longlat - WGS84 - true - - - 255 - postgres - - - - - - - hard:circle - 4 - pixels - - - - - SolidLine - 0.26 - - SolidPattern - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - node_id - - - - - - - - - - - - - - - - EPSG:4326 - - - 0 - 255 - 255 - 255 - 255 - 255 - 255 - - - 2 - true - - -