Commit 92cf9cb7 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

MapView + MapViewDock simplifications, toolbox (many changes)


Signed-off-by: Benjamin Jakimow's avatarbenjamin.jakimow <benjamin.jakimow@geo.hu-berlin.de>
parent fa24d506
This diff is collapsed.
......@@ -639,7 +639,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
def onTimeSeriesChanged(self, *args):
if not self.mSpatialMapExtentInitialized:
if len(self.mTimeSeries.mTSDs) > 0:
if len(self.mTimeSeries) > 0:
if len(self.spatialTemporalVis.MVC) == 0:
# add an empty MapView by default
self.spatialTemporalVis.createMapView()
......@@ -653,7 +653,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
if len(self.mTimeSeries.mTSDs) == 0:
if len(self.mTimeSeries) == 0:
self.mSpatialMapExtentInitialized = False
......
......@@ -32,12 +32,13 @@ from PyQt5.QtWidgets import *
from PyQt5.QtXml import QDomDocument
from .utils import *
from .timeseries import TimeSeriesDatum, SensorProxyLayer, SensorInstrument
from .externals.qps.crosshair.crosshair import CrosshairDialog, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.maptools import *
from .labeling import LabelAttributeTableModel, labelShortcutLayers, layerClassSchemes, applyShortcutsToRegisteredLayers
from .externals.qps.classification.classificationscheme import ClassificationScheme, ClassInfo
from .externals.qps.utils import *
import eotimeseriesviewer.settings
......@@ -765,7 +766,7 @@ class MapCanvas(QgsMapCanvas):
if newRenderer is not None:
self.mMapView.sensorProxyLayer(l.sensor()).setRenderer(newRenderer)
#self.sigChangeSVRequest.emit(self, )
# self.sigChangeSVRequest.emit(self, )
self.addToRefreshPipeLine(MapCanvas.Command.RefreshRenderer)
return
s = ""
......@@ -791,7 +792,7 @@ class MapCanvas(QgsMapCanvas):
self.saveAsImage(path, None, fileType)
eotimeseriesviewer.settings.setValue(eotimeseriesviewer.settings.Keys.ScreenShotDirectory, os.path.dirname(path))
def setSpatialExtent(self, spatialExtent:SpatialExtent):
def setSpatialExtent(self, spatialExtent: SpatialExtent):
"""
Sets the SpatialExtent to be shown.
:param spatialExtent: SpatialExtent
......@@ -801,7 +802,7 @@ class MapCanvas(QgsMapCanvas):
spatialExtent = spatialExtent.toCrs(self.crs())
self.setExtent(spatialExtent)
def setSpatialCenter(self, spatialPoint:SpatialPoint):
def setSpatialCenter(self, spatialPoint: SpatialPoint):
"""
Sets the map center
:param spatialPoint: SpatialPoint
......
This diff is collapsed.
......@@ -440,14 +440,13 @@ class TimeSeriesSource(object):
class TimeSeriesDatum(QObject):
"""
A containe to store all image source related to a single observation date and sensor.
"""
sigVisibilityChanged = pyqtSignal(bool)
sigRemoveMe = pyqtSignal()
sigSourcesChanged = pyqtSignal()
def __init__(self, timeSeries, date:np.datetime64, sensor:SensorInstrument):
"""
Constructor
......@@ -466,9 +465,6 @@ class TimeSeriesDatum(QObject):
self.mVisibility = True
self.mTimeSeries = timeSeries
def addSource(self, source):
"""
Adds an time series source to this TimeSeriesDatum
......@@ -489,8 +485,6 @@ class TimeSeriesDatum(QObject):
else:
return None
def setVisibility(self, b:bool):
"""
Sets the visibility of the TimeSeriesDatum, i.e. whether linked MapCanvases will be shown to the user
......@@ -605,6 +599,19 @@ class TimeSeriesDatum(QObject):
return False
return self.id() == other.id() and self.mSources == other.mSources
def __contains__(self, item):
return item in self.mSources
def __getitem__(self, slice):
return self.mSources[slice]
def __iter__(self):
"""
Iterator over all sources
"""
return iter(self.mSources)
def __len__(self)->int:
"""
Returns the number of source images.
......@@ -835,7 +842,7 @@ class TimeSeries(QObject):
def __init__(self, imageFiles=None, maskFiles=None):
QObject.__init__(self)
super(TimeSeries, self).__init__()
self.mTSDs = list()
self.mSensors = []
self.mShape = None
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Frame</class>
<widget class="QFrame" name="Frame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>348</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/mapview.svg</normaloff>:/timeseriesviewer/icons/mapview.svg</iconset>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QToolButton" name="btnToggleMapViewVisibility">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Toggle map view visibility</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/mapviewHidden.svg</normaloff>:/timeseriesviewer/icons/mapviewHidden.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="popupMode">
<enum>QToolButton::DelayedPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnToggleCrosshair">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Show/hide crosshair</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/crosshair.svg</normaloff>:/timeseriesviewer/icons/crosshair.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="popupMode">
<enum>QToolButton::MenuButtonPopup</enum>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="tbName">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>Map View Title</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnHighlightMapView">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>?</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QgsLayerTreeView" name="mLayerTreeView"/>
</item>
</layout>
<action name="actionToggleMapViewHidden">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="enabled">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/mapviewHidden.svg</normaloff>:/timeseriesviewer/icons/mapviewHidden.svg</iconset>
</property>
<property name="text">
<string>Hide Map View</string>
</property>
<property name="toolTip">
<string>Hide this map view</string>
</property>
</action>
<action name="actionToggleCrosshairVisibility">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/crosshair.svg</normaloff>:/timeseriesviewer/icons/crosshair.svg</iconset>
</property>
<property name="text">
<string>Show/hide Crosshair</string>
</property>
<property name="toolTip">
<string>Show/hide a crosshair</string>
</property>
</action>
<action name="actionSetCrosshairStyle">
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/symbology.svg</normaloff>:/timeseriesviewer/icons/symbology.svg</iconset>
</property>
<property name="text">
<string>Set crosshair style</string>
</property>
</action>
<action name="actionHighlightMapView">
<property name="text">
<string>?</string>
</property>
<property name="toolTip">
<string>Click to highlight this map view</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>QgsLayerTreeView</class>
<extends>QTreeView</extends>
<header>qgis.gui</header>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>
......@@ -17,7 +17,7 @@
</size>
</property>
<property name="windowTitle">
<string>Maps &amp;&amp; Map Views</string>
<string>Mapping</string>
</property>
<widget class="QWidget" name="dockWidgetContents">
<layout class="QVBoxLayout" name="verticalLayout">
......@@ -43,6 +43,9 @@
</property>
<item>
<widget class="QToolButton" name="btnRemoveMapView">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
......@@ -97,26 +100,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="btnHighlightMapView">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources.qrc">
<normaloff>:/timeseriesviewer/icons/mActionAddMapView.svg</normaloff>:/timeseriesviewer/icons/mActionAddMapView.svg</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
......@@ -151,9 +134,13 @@ QToolBox::tab:selected { /* italicize selected tabs */
<x>0</x>
<y>0</y>
<width>452</width>
<height>389</height>
<height>386</height>
</rect>
</property>
<attribute name="icon">
<iconset resource="../../../../QGIS/images/images.qrc">
<normaloff>:/images/themes/default/mLayoutItemMap.svg</normaloff>:/images/themes/default/mLayoutItemMap.svg</iconset>
</attribute>
<attribute name="label">
<string>Map Properties</string>
</attribute>
......@@ -453,14 +440,6 @@ QToolBox::tab:selected { /* italicize selected tabs */
<string>Create a new map view</string>
</property>
</action>
<action name="actionHighlightMapView">
<property name="text">
<string>?</string>
</property>
<property name="toolTip">
<string>Click to highlight this map view</string>
</property>
</action>
<action name="actionSetSubsetSize">
<property name="text">
<string>setSubsetSize</string>
......@@ -483,6 +462,7 @@ QToolBox::tab:selected { /* italicize selected tabs */
</customwidgets>
<resources>
<include location="resources.qrc"/>
<include location="../../../../QGIS/images/images.qrc"/>
</resources>
<connections>
<connection>
......
......@@ -23,6 +23,7 @@ from PyQt5.QtGui import *
from PyQt5.QtCore import *
import unittest
from eotimeseriesviewer.utils import *
from eotimeseriesviewer.timeseries import TimeSeries, TimeSeriesDatum, TimeSeriesSource
from eotimeseriesviewer.mapcanvas import *
from eotimeseriesviewer.mapvisualization import *
from example.Images import Img_2014_05_07_LC82270652014127LGN00_BOA
......@@ -85,15 +86,17 @@ class testclassMapVisualization(unittest.TestCase):
"""Runs after each test."""
pass
def test_mapview(self):
TS = TestObjects.createTimeSeries()
lyr = TestObjects.createVectorLayer()
lyr.setName('Layer1 Name')
lyr.setTitle('Layer1 title')
lyr2 = TestObjects.createVectorLayer()
lyr2.setName('Layer2 name')
mapview = MapView()
mapview.show()
self.assertEqual([], mapview.sensors())
......@@ -104,7 +107,6 @@ class testclassMapVisualization(unittest.TestCase):
mapview.addLayer(lyr2)
self.assertEqual(TS.sensors(), mapview.sensors())
from eotimeseriesviewer.mapcanvas import MapCanvas
canvas = MapCanvas()
tsd = TS[0]
......@@ -121,6 +123,11 @@ class testclassMapVisualization(unittest.TestCase):
canvas.setExtent(l.extent())
if SHOW_GUI:
w = QWidget()
w.setLayout(QHBoxLayout())
w.layout().addWidget(mapview)
w.layout().addWidget(canvas)
w.show()
timer = QTimer()
timer.timeout.connect(canvas.timedRefresh)
......@@ -128,6 +135,35 @@ class testclassMapVisualization(unittest.TestCase):
timer.start()
QGIS_APP.exec_()
def test_mapViewDock(self):
TS = TestObjects.createTimeSeries()
dock = MapViewDock()
self.assertIsInstance(dock, MapViewDock)
dock.setTimeSeries(TS)
mapView = dock.createMapView()
self.assertIsInstance(mapView, MapView)
mapView.setTimeSeries(TS)
canvas = MapCanvas()
canvas.setTSD(TS[0])
mapView.registerMapCanvas(canvas)
tss = TS[0][0]
self.assertIsInstance(tss, TimeSeriesSource)
canvas.setCrs(tss.crs())
canvas.setSpatialExtent(tss.spatialExtent())
if SHOW_GUI:
dock.show()
canvas.show()
timer = QTimer()
timer.timeout.connect(canvas.timedRefresh)
timer.setInterval(500)
timer.start()
QGIS_APP.exec_()
......@@ -288,26 +324,38 @@ class testclassMapVisualization(unittest.TestCase):
TSV = TimeSeriesViewer()
TSV.loadExampleTimeSeries()
TSV.show()
SV = TSV.spatialTemporalVis
self.assertIsInstance(SV, SpatialTemporalVisualization)
QApplication.processEvents()
# TSV.createMapView()
import time
time.sleep(5)
SV.timedCanvasRefresh()
visibleCanvases = []
withLayers = []
empty = []
extent = None
for mc in SV.mapCanvases():
self.assertIsInstance(mc, MapCanvas)
self.assertIsInstance(mc.spatialExtent(), SpatialExtent)
for mapCanvas in SV.mapCanvases():
self.assertIsInstance(mapCanvas, MapCanvas)
self.assertIsInstance(mapCanvas.spatialExtent(), SpatialExtent)
if extent is None:
extent = mc.spatialExtent()
extent = mapCanvas.spatialExtent()
else:
self.assertTrue(mc.spatialExtent() == extent)
self.assertTrue(mapCanvas.spatialExtent() == extent)
if len(mc.layers()) == 0:
empty.append(mc)
if len(mapCanvas.layers()) == 0:
empty.append(mapCanvas)
else:
withLayers.append(mc)
withLayers.append(mapCanvas)
if True:
QGIS_APP.exec_()
self.assertTrue(len(withLayers) > 0)
self.assertTrue(len(empty) > 0)
......@@ -316,10 +364,10 @@ class testclassMapVisualization(unittest.TestCase):
extent2 = extent.setCenter(SpatialPoint(extent.crs(), extent.center().x()-100, extent.center().y()))
SV.setSpatialExtent(extent2)
SV.timedCanvasRefresh()
for mc in SV.mapCanvases():
self.assertIsInstance(mc, MapCanvas)
if mc.isVisibleToViewport():
self.assertTrue(mc.spatialExtent() == extent2)
for mapCanvas in SV.mapCanvases():
self.assertIsInstance(mapCanvas, MapCanvas)
if mapCanvas.isVisibleToViewport():
self.assertTrue(mapCanvas.spatialExtent() == extent2)
# shift spatial extent of single map canvas
......@@ -328,9 +376,9 @@ class testclassMapVisualization(unittest.TestCase):
self.assertIsInstance(canvas, MapCanvas)
canvas.setSpatialExtent(extent3)
SV.timedCanvasRefresh()
for mc in SV.mapCanvases():
if mc.isVisibleToViewport():
self.assertTrue(mc.spatialExtent() == extent3)
for mapCanvas in SV.mapCanvases():
if mapCanvas.isVisibleToViewport():
self.assertTrue(mapCanvas.spatialExtent() == extent3)
# test map render changes
for canvas in SV.mapCanvases():
......
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