Skip to content

Commit 868a074

Browse files
committed
chore: merge branch 'shogun-boot' into load-layers
2 parents 1b67415 + 9b677c0 commit 868a074

14 files changed

Lines changed: 312 additions & 518 deletions

docker/docker-compose-dev.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
services:
22
qgis:
33
image: qgis/qgis:3.44
4-
command: ["/bin/bash", "-c", "qgis /root/shogun_qgis_konfigurator.qgs"]
4+
command: ["/bin/bash", "-c", "qgis"]
55
environment:
66
DISPLAY: "unix${DISPLAY}"
77
RUN_IN_DOCKER: "1"
@@ -11,4 +11,3 @@ services:
1111
- /tmp/.X11-unix:/tmp/.X11-unix
1212
- ./qgis_plugins:/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins
1313
- ../plugin_code:/root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/qgis-shogun-editor
14-
- ./shogun_qgis_konfigurator.qgs:/root/shogun_qgis_konfigurator.qgs

docker/shogun_qgis_konfigurator.qgs

Lines changed: 0 additions & 492 deletions
This file was deleted.

plugin_code/models/Application.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
123
from dataclasses import dataclass
224
from typing import Any, Dict, Optional
325

26+
from PyQt5.QtWidgets import QListWidgetItem
27+
428
from ..models.BaseEntity import BaseEntity
529

630

@@ -27,3 +51,8 @@ def from_dict(cls, data: Dict[str, Any]) -> 'Application':
2751
layer_config=data.get('layerConfig'),
2852
tool_config=data.get('toolConfig')
2953
)
54+
55+
def get_qt_list_item(self):
56+
item = QListWidgetItem(self.name or "Unnamed Application")
57+
item.application_id = self._id
58+
return item

plugin_code/models/BaseEntity.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
23+
124
from dataclasses import dataclass
225
from datetime import datetime
326
from enum import Enum

plugin_code/models/Layer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
123
from dataclasses import dataclass
224
from typing import Any, Dict, Optional
325

plugin_code/models/MutateApplication.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
123
from dataclasses import dataclass
224
from typing import Any, Dict, Optional
325

plugin_code/models/MutateLayer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""
123
from dataclasses import dataclass
224
from typing import Any, Dict, Optional
325

plugin_code/models/__init__.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
/***************************************************************************
4+
QgisShogunEditor
5+
A QGIS plugin
6+
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
7+
-------------------
8+
begin : 2025-09
9+
git sha : $Format:%H$
10+
copyright : (C) 2025 by terrestris
11+
email : info@terrestris.de
12+
***************************************************************************/
13+
14+
/***************************************************************************
15+
* *
16+
* This program is free software; you can redistribute it and/or modify *
17+
* it under the terms of the GNU General Public License as published by *
18+
* the Free Software Foundation; either version 2 of the License, or *
19+
* (at your option) any later version. *
20+
* *
21+
***************************************************************************/
22+
"""

plugin_code/qgis_shogun_editor.py

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
from qgis.core import (
2727
Qgis,
2828
QgsBrowserModel,
29+
QgsCoordinateReferenceSystem,
2930
QgsMessageLog,
3031
QgsNetworkAccessManager,
32+
QgsPointXY,
33+
QgsProject,
34+
QgsRectangle,
3135
QgsSettings,
3236
QgsRasterLayer,
3337
QgsProject,
@@ -40,10 +44,11 @@
4044
from qgis.PyQt.QtNetwork import QNetworkRequest, QSslSocket
4145
from qgis.PyQt.QtWidgets import QAction, QTreeWidgetItem, QMessageBox
4246

43-
# Import the code for the dialog
47+
from .models.Application import Application
4448
from .qgis_shogun_editor_dialog import QgisShogunEditorDialog
4549
from .service.Application import ApplicationService
4650
from .service.GraphQLClient import GraphQLClient
51+
from .service.LayerService import LayerService
4752

4853

4954
class QgisShogunEditor:
@@ -58,6 +63,9 @@ def __init__(self, iface):
5863
:type iface: QgsInterface
5964
"""
6065
# Save reference to the QGIS interface
66+
self.layer_service = None
67+
self.app_service = None
68+
self.graphql_client = None
6169
self.iface = iface
6270
# initialize plugin directory
6371
self.plugin_dir = os.path.dirname(__file__)
@@ -211,15 +219,16 @@ def run(self):
211219
"""Run method that performs all the real work"""
212220

213221
# Create the dialog with elements (after translation) and keep reference
214-
# Only create GUI ONCE in callback, so that it will only load when the plugin is started
222+
# Only create GUI ONCE in callback, so that it will only load when thie plugin is started
215223
if self.first_start:
216224
self.first_start = False
217225
self.dlg = QgisShogunEditorDialog()
218226

219227
self.dlg.entryUrl.setPlaceholderText('Please enter an URL')
220-
self.dlg.entryUrl.setText('http://192.168.100.106:8080/')
221228

222-
self.dlg.loadButton.clicked.connect(lambda: self.load_applications_graphql())
229+
self.dlg.loadButton.clicked.connect(lambda: self.initialize_graphql_and_load_app_list())
230+
231+
self.dlg.loadButton.clicked.connect(lambda: self._handle_double_click)
223232

224233
# add logo
225234
logo_path = os.path.join(os.path.dirname(__file__), "shogun_logo.png")
@@ -243,6 +252,51 @@ def run(self):
243252
# substitute with your code.
244253
pass
245254

255+
def _handle_double_click(self, item):
256+
QgsMessageLog.logMessage(
257+
f"You selected: {item.text()} - application id is: {item.application_id}", 'QgisShogunEditor',
258+
level=Qgis.Info
259+
)
260+
QgsProject.instance().setTitle(item.text())
261+
application = self.app_service.get_application_by_id(item.application_id)
262+
self.apply_mapview(application)
263+
if application is not None:
264+
if application.layer_tree is not None:
265+
try:
266+
QgsMessageLog.logMessage(
267+
f"Found layer tree {application.layer_tree}:",
268+
'QgisShogunEditor',
269+
level=Qgis.Info
270+
)
271+
except json.JSONDecodeError as e:
272+
QgsMessageLog.logMessage(
273+
f"Could not decode layer tree json: {e}", 'QgisShogunEditor',
274+
level=Qgis.Critical
275+
)
276+
else:
277+
QgsMessageLog.logMessage("Application has no layer tree", 'QgisShogunEditor', level=Qgis.Warning)
278+
279+
def apply_mapview(self, application: Application):
280+
qgis_project = QgsProject.instance()
281+
client_config = application.client_config
282+
if client_config is not None and 'mapView' in client_config:
283+
map_view = client_config.get('mapView')
284+
projection = map_view.get('projection')
285+
center = map_view.get('center')
286+
crs = QgsCoordinateReferenceSystem(projection)
287+
qgis_project.setCrs(crs)
288+
289+
map_canvas = self.iface.mapCanvas()
290+
map_canvas.setCenter(QgsPointXY(center[0], center[1]))
291+
292+
zoom = map_view.get('zoom')
293+
resolutions = map_view.get('resolutions')
294+
if resolutions is not None and zoom is not None and zoom < len(resolutions):
295+
resolution = resolutions[zoom]
296+
dpi = 25.4 / 0.28
297+
inches_per_meter = 39.37
298+
map_canvas.zoomScale(resolution * dpi * inches_per_meter)
299+
246300
def open_project_link(self, event):
247301
if event.button() == Qt.LeftButton:
248302
QDesktopServices.openUrl(QUrl("https://www.terrestris.de/de/"))
@@ -462,17 +516,20 @@ def sanitize_shogun_url(self, shogun_url):
462516
shogun_url += '/graphql'
463517
return shogun_url
464518

465-
# Example usage in your code
466-
def load_applications_graphql(self):
467-
shogun_endpoint_url = self.dlg.entryUrl.text()
468-
client = GraphQLClient(shogun_endpoint_url)
519+
def initialize_graphql_client(self):
520+
sanitized_url = self.sanitize_shogun_url(self.dlg.entryUrl.text().strip())
521+
self.graphql_client = GraphQLClient(sanitized_url)
522+
self.app_service = ApplicationService(self.graphql_client)
523+
self.layer_service = LayerService(self.graphql_client)
469524

470-
app_service = ApplicationService(client)
471-
applications = app_service.get_all_applications()
525+
# Example usage in your code
526+
def initialize_graphql_and_load_app_list(self):
527+
self.initialize_graphql_client()
528+
applications = self.app_service.get_all_applications_simple()
472529
if applications is not None:
473530
self.dlg.applicationsList.clear()
474531
for app in applications:
475-
self.dlg.applicationsList.addItem(app.name)
532+
self.dlg.applicationsList.addItem(app.get_qt_list_item())
476533

477534
def load_applications(self):
478535
inputUrl = self.dlg.entryUrl.text()

plugin_code/qgis_shogun_editor_dialog.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,4 @@ def __init__(self, parent=None):
4141
# http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
4242
# #widgets-and-dialogs-with-auto-connect
4343

44-
if self.is_pip_available():
45-
print('pip is available')
46-
4744
self.setupUi(self)
48-
49-
def is_pip_available(self) -> bool:
50-
try:
51-
import_module("pip") # noqa F401
52-
return True
53-
except ImportError:
54-
return False

0 commit comments

Comments
 (0)