Commit 288c9c02 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

modified MapView writeXml / readXml to saves QgsTextFormat


Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow <benjamin.jakimow@geo.hu-berlin.de>
parent 6e22706d
Pipeline #12469 failed
......@@ -709,6 +709,10 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
root = doc.documentElement()
node = root.firstChildElement('EOTSV')
if node.nodeName() == 'EOTSV':
self.timeSeries().clear()
mapviews = self.mapViews()
for mv in mapviews:
self.mapWidget().removeMapView(mv)
self.timeSeries().readXml(node)
self.mapWidget().readXml(node)
......
......@@ -163,6 +163,10 @@ class MapView(QFrame):
self.mIsVisible = True
self.setTitle(name)
self.optionShowDate: QAction
self.optionShowSensorName: QAction
self.optionShowMapViewName: QAction
m = QMenu()
m.addAction(self.optionShowDate)
m.addAction(self.optionShowSensorName)
......@@ -174,6 +178,80 @@ class MapView(QFrame):
fixMenuButtons(self)
@staticmethod
def readXml(node: QDomNode):
if node.nodeName() == 'MapView':
nodeMapView = node
else:
nodeMapView = node.firstChildElement('MapView')
if nodeMapView.nodeName() != 'MapView':
return None
context = QgsReadWriteContext()
mapView = MapView()
def to_bool(value) -> bool:
return str(value).lower() in ['1', 'true']
mapView.setName(nodeMapView.attribute('name'))
mapView.setMapBackgroundColor(QColor(nodeMapView.attribute('bg')))
mapView.setVisibility(to_bool(nodeMapView.attribute('visible')))
mapView.optionShowDate.setChecked(to_bool(nodeMapView.attribute('showDate')))
mapView.optionShowSensorName.setChecked(to_bool(nodeMapView.attribute('showSensorName')))
mapView.optionShowMapViewName.setChecked(to_bool(nodeMapView.attribute('showMapViewName')))
#nodeMapView.setAttribute('showDate', str(self.optionShowDate.checked()))
#nodeMapView.setAttribute('showSensorName', str(self.optionShowSensorName.checked()))
#nodeMapView.setAttribute('showMapViewName', str(self.optionShowMapViewName.checked()))
textFormat = mapView.mapTextFormat()
textFormat.readXml(nodeMapView, context)
lyrNode = node.firstChildElement('MapViewProxyLayer').toElement()
while lyrNode.nodeName() == 'MapViewProxyLayer':
sid = lyrNode.attribute('sensor_id')
styleNode = lyrNode.firstChildElement('LayerStyle')
style = QgsMapLayerStyle()
style.readXml(styleNode)
sensor = SensorInstrument(sid)
mapView.addSensor(sensor)
lyr = mapView.sensorProxyLayer(sensor)
lyr.setMapLayerStyle(style)
lyrNode = lyrNode.nextSibling().toElement()
return mapView
def writeXml(self, node: QDomNode, doc: QDomDocument):
nodeMapView = doc.createElement('MapView')
nodeMapView.setAttribute('name', self.name())
nodeMapView.setAttribute('bg', self.mapBackgroundColor().name())
nodeMapView.setAttribute('visible', str(self.isVisible()))
nodeMapView.setAttribute('showDate', str(self.optionShowDate.isChecked()))
nodeMapView.setAttribute('showSensorName', str(self.optionShowSensorName.isChecked()))
nodeMapView.setAttribute('showMapViewName', str(self.optionShowMapViewName.isChecked()))
"""
m.addAction(self.optionShowDate)
m.addAction(self.optionShowSensorName)
m.addAction(self.optionShowMapViewName)
"""
context = QgsReadWriteContext()
nodeTextStyle = self.mapTextFormat().writeXml(doc, context)
nodeMapView.appendChild(nodeTextStyle)
for sensor in self.sensors():
lyr = self.sensorProxyLayer(sensor)
if isinstance(lyr, SensorProxyLayer):
sensorNode = doc.createElement('MapViewProxyLayer')
sensorNode.setAttribute('sensor_id', sensor.id())
style: QgsMapLayerStyle = lyr.mapLayerStyle()
styleNode = doc.createElement('LayerStyle')
style.writeXml(styleNode)
sensorNode.appendChild(styleNode)
nodeMapView.appendChild(sensorNode)
node.appendChild(nodeMapView)
def setName(self, name: str):
self.setTitle(name)
......@@ -1207,19 +1285,7 @@ class MapWidget(QFrame):
mwNode.appendChild(crsNode)
for mapView in self.mapViews():
mvNode = doc.createElement('MAP_VIEW')
mvNode.setAttribute('name', mapView.name())
for sensor in mapView.sensors():
lyr = mapView.sensorProxyLayer(sensor)
if isinstance(lyr, SensorProxyLayer):
sensorNode = doc.createElement('MAP_VIEW_PROXY_LAYER')
sensorNode.setAttribute('sensor_id', sensor.id())
style: QgsMapLayerStyle = lyr.mapLayerStyle()
styleNode = doc.createElement('STYLE')
style.writeXml(styleNode)
sensorNode.appendChild(styleNode)
mvNode.appendChild(sensorNode)
mwNode.appendChild(mvNode)
mapView.writeXml(mwNode, doc)
node.appendChild(mwNode)
return True
......@@ -1246,34 +1312,14 @@ class MapWidget(QFrame):
self.setCrs(extent.crs())
self.setSpatialExtent(extent)
mvNode = node.firstChildElement('MAP_VIEW').toElement()
while mvNode.nodeName() == 'MAP_VIEW':
mvName = mvNode.attribute('name')
mapView: MapView = None
# find existing map view with same name
for mv in self.mapViews():
if mv.name() == mvName:
mapView = mv
# no map view with same name, create a new
if not isinstance(mapView, MapView):
mapView = MapView()
mapView.setName(mvName)
self.addMapView(mapView)
mvNode = node.firstChildElement('MapView').toElement()
while mvNode.nodeName() == 'MapView':
mapView = MapView.readXml(mvNode)
if isinstance(mapView, MapView):
for s in mapView.sensors():
self.timeSeries().addSensor(s)
sensorNode = mvNode.firstChildElement('MAP_VIEW_PROXY_LAYER').toElement()
while not sensorNode.nodeName() == 'MAP_VIEW_PROXY_LAYER':
sid = sensorNode.attribute('sensor_id')
sensor = self.timeSeries().findMatchingSensor(sid)
if sensor:
lyr = mapView.sensorProxyLayer(sensor)
if isinstance(lyr, SensorProxyLayer):
styleNode = sensorNode.firstChildElement('STYLE')
if styleNode.nodeName() == 'STYLE':
style = QgsMapLayerStyle()
style.readXml(styleNode)
lyr.setMapLayerStyle(style)
sensorNode = sensorNode.nextSibling().toElement()
self.addMapView(mapView)
mvNode = mvNode.nextSibling().toElement()
def usedLayers(self) -> typing.List[QgsMapLayer]:
......
......@@ -2190,7 +2190,7 @@ class TimeSeries(QAbstractItemModel):
tssNode = tssNode.nextSibling()
if len(to_add) > 0:
self.addSources(to_add, runAsync=False)
self.addSources(to_add, runAsync=True)
def data(self, index, role):
"""
......
......@@ -83,6 +83,7 @@ class TestMain(EOTSVTestCase):
from eotimeseriesviewer.main import EOTimeSeriesViewer
TSV = EOTimeSeriesViewer()
TSV.createMapView('True Color')
TSV.createMapView('False Color')
TSV.loadExampleTimeSeries(loadAsync=True)
while QgsApplication.taskManager().countActiveTasks() > 0 or len(TSV.timeSeries().mTasks) > 0:
......@@ -96,6 +97,7 @@ class TestMain(EOTSVTestCase):
path = self.testOutputDirectory() / 'test.qgz'
QgsProject.instance().write(path.as_posix())
self.assertTrue(QgsProject.instance().read(path.as_posix()))
TSV.onReloadProject()
self.showGui([TSV.ui])
......@@ -109,21 +111,6 @@ class TestMain(EOTSVTestCase):
self.assertIsInstance(TSV, EOTimeSeriesViewer)
self.showGui(TSV.ui)
def test_TaskManagerStatusButton(self):
bar = QgsStatusBar()
w = TaskManagerStatusButton()
bar.addPermanentWidget(w, 10, QgsStatusBar.AnchorLeft)
bar.showMessage('my status')
w.mInfoLabel.setText('emoty')
self.showGui(bar)
def test_mapcanvasextent(self):
edit = QgsDateTimeEdit()
self.showGui(edit)
def test_TimeSeriesViewerInvalidSource(self):
......
......@@ -512,6 +512,15 @@ class TestTimeSeries(EOTSVTestCase):
lyr = sensor.proxyRasterLayer()
self.assertIsInstance(lyr, QgsRasterLayer)
doc = QDomDocument('eotsv')
node = doc.createElement('MySensor')
sensor.writeXml(node, doc)
sensor3 = SensorInstrument.readXml(node)
self.assertEqual(sensor, sensor3)
def test_datematching(self):
pass
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment