Commit 21135a6a authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

better screenshot updates

refactoring MapView dock
parent dcfbf1f7
# #
from qgis.core import *
from qgis.gui import *
from qgis.PyQt.QtWidgets import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from timeseriesviewer.utils import * from timeseriesviewer.utils import *
from timeseriesviewer.main import TimeSeriesViewer from timeseriesviewer.main import TimeSeriesViewer
from timeseriesviewer.mapvisualization import *
from timeseriesviewer.profilevisualization import *
from timeseriesviewer.timeseries import *
from timeseriesviewer import DIR_REPO, DIR_QGIS_RESOURCES from timeseriesviewer import DIR_REPO, DIR_QGIS_RESOURCES
DIR_SCREENSHOTS = jp(DIR_REPO, 'screenshots') DIR_SCREENSHOTS = jp(DIR_REPO, 'screenshots')
os.makedirs(DIR_SCREENSHOTS, exist_ok=True) os.makedirs(DIR_SCREENSHOTS, exist_ok=True)
...@@ -12,12 +19,125 @@ app = initQgisApplication(qgisResourceDir=DIR_QGIS_RESOURCES) ...@@ -12,12 +19,125 @@ app = initQgisApplication(qgisResourceDir=DIR_QGIS_RESOURCES)
TS = TimeSeriesViewer(None) TS = TimeSeriesViewer(None)
TS.show() TS.show()
TS.loadExampleTimeSeries()
#set up example settings
from example.Images import Img_2014_04_21_LC82270652014111LGN00_BOA, re_2014_06_25
#TS.loadExampleTimeSeries()
TS.loadImageFiles([Img_2014_04_21_LC82270652014111LGN00_BOA, re_2014_06_25])
sensorLS = None
sensorRE = None
for sensor in TS.TS.sensors():
assert isinstance(sensor, SensorInstrument)
if sensor.id() == '6b30.0m0.49;0.56;0.66;0.84;1.65;2.2um':
sensor.setName('Landsat')
sensorLS = sensor
if sensor.id() == '5b5.0m':
sensor.setName('RapidEye')
sensorRE = sensor
assert isinstance(sensorLS, SensorInstrument)
assert isinstance(sensorRE, SensorInstrument)
#add second MapView
TS.createMapView()
mv1 = TS.mapViews()[0]
mv2 = TS.mapViews()[1]
assert isinstance(mv1, MapView)
assert isinstance(mv2, MapView)
mv1.setTitle('True Color')
mv2.setTitle('Short-Wave IR')
#set True Color Bands
for sensor in [sensorLS, sensorRE]:
rendering = mv1.sensorWidget(sensor)
assert isinstance(rendering, MapViewRenderSettings)
renderer = rendering.rasterRenderer()
assert isinstance(renderer, QgsMultiBandColorRenderer)
renderer.setRedBand(3)
renderer.setGreenBand(2)
renderer.setBlueBand(1)
rendering.setRasterRenderer(renderer)
#set swIR-nIR-R Bands
rendering = mv2.sensorWidget(sensorLS)
assert isinstance(rendering, MapViewRenderSettings)
renderer = rendering.rasterRenderer()
assert isinstance(renderer, QgsMultiBandColorRenderer)
renderer.setRedBand(4)
renderer.setGreenBand(5)
renderer.setBlueBand(3)
rendering.setRasterRenderer(renderer)
rendering = mv2.sensorWidget(sensorRE)
assert isinstance(rendering, MapViewRenderSettings)
renderer = rendering.rasterRenderer()
assert isinstance(renderer, QgsMultiBandColorRenderer)
renderer.setRedBand(5)
renderer.setGreenBand(4)
renderer.setBlueBand(3)
rendering.setRasterRenderer(renderer)
app.exec_()
def widgetScreenshot(widget, path):
assert isinstance(widget, QWidget)
rect = widget.rect()
pixmap = QPixmap(rect.size())
widget.render(pixmap, QPoint(), QRegion(rect))
pixmap.save(path, quality=100)
def makePNG(widget, name):
path = jp(DIR_SCREENSHOTS, name+'.png')
widgetScreenshot(widget, path)
# makePNG(TS.ui, 'mainGUI')
for dockWidget in TS.ui.findChildren(QDockWidget):
assert isinstance(dockWidget, QDockWidget)
#dockWidget.setFloating(True)
name = dockWidget.objectName()
dSize = dockWidget.size()
#change sizes
if name == 'cursorLocationInfoPanel':
center = TS.TS.getMaxSpatialExtent().spatialCenter()
from timeseriesviewer.mapcanvas import MapTools
TS.onShowProfile(center, mv1.mapCanvases()[0], MapTools.CursorLocation)
dockWidget.reloadCursorLocation()
dockWidget.resize(QSize(300, 150))
dockWidget.update()
if name == 'mapViewPanel':
dockWidget.setCurrentMapView(mv1)
dockWidget.gbMapProperties.setCollapsed(True)
dockWidget.gbMapProperties.update()
mv1.ui.gbVectorRendering.setCollapsed(True)
mv1.ui.gbVectorRendering.setChecked(False)
mv1.ui.update()
dockWidget.resize(QSize(300, 600))
dockWidget.update()
if name == 'sensorPanel':
#dockWidget.setFixedHeight(200)
dockWidget.setFixedSize(QSize(550, 100))
if name == 'systemInfoPanel':
dockWidget.setFixedHeight(400)
if name == 'spectralLibraryPanel':
dockWidget.setFixedSize(QSize(800, 250))
if name == 'temporalProfilePanel':
dockWidget.setFixedSize(QSize(800, 250))
if name == 'timeseriesPanel':
dockWidget.setFixedSize(QSize(800, 250))
makePNG(dockWidget, name)
#dockWidget.setFloating(False)
app.exec_()
#print('Done')
...@@ -6,7 +6,7 @@ from qgis.PyQt.QtGui import * ...@@ -6,7 +6,7 @@ from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import * from qgis.PyQt.QtWidgets import *
from osgeo import gdal from osgeo import gdal
from timeseriesviewer.ui.docks import TsvDockWidgetBase, loadUI from timeseriesviewer.ui.docks import loadUI
from timeseriesviewer.classificationscheme import ClassificationSchemeWidget, ClassificationScheme, ClassInfo, getTextColorWithContrast from timeseriesviewer.classificationscheme import ClassificationSchemeWidget, ClassificationScheme, ClassInfo, getTextColorWithContrast
class LabelShortcutButton(QPushButton): class LabelShortcutButton(QPushButton):
......
...@@ -565,7 +565,7 @@ class TimeSeriesViewer(QgisInterface, QObject): ...@@ -565,7 +565,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
extentWMC = extent.toCrs(crsWMC) extentWMC = extent.toCrs(crsWMC)
pxSize = max(self.TS.getPixelSizes(), key= lambda s :s.width()) pxSize = max(self.TS.getPixelSizes(), key= lambda s :s.width())
canvasSize = self.spatialTemporalVis.subsetSize() canvasSize = self.spatialTemporalVis.mapSize()
f = 0.05 f = 0.05
width = f * canvasSize.width() * pxSize.width() # width in map units width = f * canvasSize.width() * pxSize.width() # width in map units
height = f * canvasSize.height() * pxSize.height() height = f * canvasSize.height() * pxSize.height()
......
...@@ -1260,7 +1260,7 @@ class MapView(QObject): ...@@ -1260,7 +1260,7 @@ class MapView(QObject):
mapCanvas.setRenderer(renderer) mapCanvas.setRenderer(renderer)
#mapCanvas.refresh() #mapCanvas.refresh()
""" """
def getSensorWidget(self, sensor): def sensorWidget(self, sensor):
assert type(sensor) is SensorInstrument assert type(sensor) is SensorInstrument
return self.mSensorViews[sensor] return self.mSensorViews[sensor]
...@@ -1675,7 +1675,7 @@ class DatumView(QObject): ...@@ -1675,7 +1675,7 @@ class DatumView(QObject):
self.setColumnInfo() self.setColumnInfo()
self.MVC = stv.MVC self.MVC = stv.MVC
self.DVC = stv.DVC self.DVC = stv.DVC
self.mapCanvases = dict() self.mMapCanvases = dict()
self.mRenderState = dict() self.mRenderState = dict()
def setColumnInfo(self): def setColumnInfo(self):
...@@ -1704,7 +1704,7 @@ class DatumView(QObject): ...@@ -1704,7 +1704,7 @@ class DatumView(QObject):
self.ui.setStyleSheet(styleOff) self.ui.setStyleSheet(styleOff)
def removeMapView(self, mapView): def removeMapView(self, mapView):
canvas = self.mapCanvases.pop(mapView) canvas = self.mMapCanvases.pop(mapView)
self.ui.layout().removeWidget(canvas) self.ui.layout().removeWidget(canvas)
canvas.close() canvas.close()
#self.adjustBaseMinSize() #self.adjustBaseMinSize()
...@@ -1712,7 +1712,7 @@ class DatumView(QObject): ...@@ -1712,7 +1712,7 @@ class DatumView(QObject):
def refresh(self): def refresh(self):
if self.ui.isVisible(): if self.ui.isVisible():
for c in self.mapCanvases.values(): for c in self.mMapCanvases.values():
if c.isVisible(): if c.isVisible():
c.refresh() c.refresh()
...@@ -1756,8 +1756,8 @@ class DatumView(QObject): ...@@ -1756,8 +1756,8 @@ class DatumView(QObject):
self.showLoading(any(self.mRenderState.values())) self.showLoading(any(self.mRenderState.values()))
def onRendering(self, *args): def onRendering(self, *args):
renderFlags = [m.renderFlag() for m in self.mapCanvases.values()] renderFlags = [m.renderFlag() for m in self.mMapCanvases.values()]
drawFlags = [m.isDrawing() for m in self.mapCanvases.values()] drawFlags = [m.isDrawing() for m in self.mMapCanvases.values()]
# print((renderFlags, drawFlags)) # print((renderFlags, drawFlags))
isLoading = any(renderFlags) isLoading = any(renderFlags)
...@@ -1770,14 +1770,15 @@ class DatumView(QObject): ...@@ -1770,14 +1770,15 @@ class DatumView(QObject):
from timeseriesviewer.mapcanvas import MapCanvas from timeseriesviewer.mapcanvas import MapCanvas
assert isinstance(mapCanvas, MapCanvas) assert isinstance(mapCanvas, MapCanvas)
assert isinstance(mapView, MapView) assert isinstance(mapView, MapView)
self.mapCanvases[mapView] = mapCanvas self.mMapCanvases[mapView] = mapCanvas
#mapView.sigTitleChanged.connect(lambda title : mapCanvas.setSaveFileName('{}_{}'.format(self.TSD.date, title))) #mapView.sigTitleChanged.connect(lambda title : mapCanvas.setSaveFileName('{}_{}'.format(self.TSD.date, title)))
mapCanvas.layerModel().setRasterLayerSources([self.TSD.pathImg]) mapCanvas.layerModel().setRasterLayerSources([self.TSD.pathImg])
self.ui.layout().insertWidget(self.wOffset + len(self.mapCanvases), mapCanvas) #self.ui.layout().insertWidget(self.wOffset + len(self.mapCanvases), mapCanvas)
self.ui.layout().insertWidget(self.ui.layout().count() - 1, mapCanvas)
self.ui.update() self.ui.update()
#register signals handled on (this) DV level #register signals handled on (this) DV level
...@@ -1862,7 +1863,7 @@ class SpatialTemporalVisualization(QObject): ...@@ -1862,7 +1863,7 @@ class SpatialTemporalVisualization(QObject):
self.MVC = self.ui.dockMapViews self.MVC = self.ui.dockMapViews
assert isinstance(self.MVC, MapViewCollectionDock) assert isinstance(self.MVC, MapViewCollectionDock)
self.MVC.sigShowProfiles.connect(self.sigShowProfiles.emit) self.MVC.sigShowProfiles.connect(self.sigShowProfiles.emit)
self.MVC.sigMapViewAdded.connect(self.onMapViewAdded)
self.vectorOverlay = None self.vectorOverlay = None
self.DVC = DateViewCollection(self) self.DVC = DateViewCollection(self)
...@@ -1878,6 +1879,9 @@ class SpatialTemporalVisualization(QObject): ...@@ -1878,6 +1879,9 @@ class SpatialTemporalVisualization(QObject):
self.setSpatialExtent(self.TS.getMaxSpatialExtent()) self.setSpatialExtent(self.TS.getMaxSpatialExtent())
#self.setSubsetSize(QSize(100,50)) #self.setSubsetSize(QSize(100,50))
def onMapViewAdded(self, *args):
self.adjustScrollArea()
s = ""
def createMapView(self): def createMapView(self):
self.MVC.createMapView() self.MVC.createMapView()
...@@ -1925,7 +1929,7 @@ class SpatialTemporalVisualization(QObject): ...@@ -1925,7 +1929,7 @@ class SpatialTemporalVisualization(QObject):
self.sigMapSizeChanged.emit(self.mSize) self.sigMapSizeChanged.emit(self.mSize)
self.adjustScrollArea() self.adjustScrollArea()
def subsetSize(self): def mapSize(self):
return QSize(self.mSize) return QSize(self.mSize)
...@@ -1986,7 +1990,7 @@ class SpatialTemporalVisualization(QObject): ...@@ -1986,7 +1990,7 @@ class SpatialTemporalVisualization(QObject):
canvas.setMapTool(mt) canvas.setMapTool(mt)
self.mMapTools.append(mt) self.mMapTools.append(mt)
#if required, link map-tool with specific EnMAP-Box slots #if required, link map-tool with specificslots
if isinstance(mt, CursorLocationMapTool): if isinstance(mt, CursorLocationMapTool):
mt.sigLocationRequest[SpatialPoint, QgsMapCanvas].connect(lambda c, m : self.sigShowProfiles.emit(c,m, mapToolKey)) mt.sigLocationRequest[SpatialPoint, QgsMapCanvas].connect(lambda c, m : self.sigShowProfiles.emit(c,m, mapToolKey))
...@@ -2128,7 +2132,7 @@ class DateViewCollection(QObject): ...@@ -2128,7 +2132,7 @@ class DateViewCollection(QObject):
#self.tsv = tsv #self.tsv = tsv
#self.timeSeries = tsv.TS #self.timeSeries = tsv.TS
self.views = list() self.mViews = list()
self.STV = STViz self.STV = STViz
self.ui = self.STV.targetLayout.parentWidget() self.ui = self.STV.targetLayout.parentWidget()
self.scrollArea = self.ui.parentWidget().parentWidget() self.scrollArea = self.ui.parentWidget().parentWidget()
...@@ -2145,14 +2149,14 @@ class DateViewCollection(QObject): ...@@ -2145,14 +2149,14 @@ class DateViewCollection(QObject):
def tsdFromMapCanvas(self, mapCanvas): def tsdFromMapCanvas(self, mapCanvas):
assert isinstance(mapCanvas, MapCanvas) assert isinstance(mapCanvas, MapCanvas)
for view in self.views: for view in self.mViews:
assert isinstance(view, DatumView) assert isinstance(view, DatumView)
if mapCanvas in view.mapCanvases.values(): if mapCanvas in view.mMapCanvases.values():
return view.TSD return view.TSD
return None return None
def tsdView(self, tsd): def tsdView(self, tsd):
r = [v for v in self.views if v.TSD == tsd] r = [v for v in self.mViews if v.TSD == tsd]
if len(r) == 1: if len(r) == 1:
return r[0] return r[0]
else: else:
...@@ -2161,26 +2165,26 @@ class DateViewCollection(QObject): ...@@ -2161,26 +2165,26 @@ class DateViewCollection(QObject):
def addMapView(self, mapView): def addMapView(self, mapView):
assert isinstance(mapView, MapView) assert isinstance(mapView, MapView)
w = self.ui w = self.ui
w.setUpdatesEnabled(False) #w.setUpdatesEnabled(False)
for tsdv in self.views: #for tsdv in self.mViews:
tsdv.ui.setUpdatesEnabled(False) # tsdv.ui.setUpdatesEnabled(False)
for tsdv in self.views: for tsdv in self.mViews:
tsdv.insertMapView(mapView) tsdv.insertMapView(mapView)
for tsdv in self.views: #for tsdv in self.mViews:
tsdv.ui.setUpdatesEnabled(True) # tsdv.ui.setUpdatesEnabled(True)
#mapView.sigSensorRendererChanged.connect(lambda *args : self.setRasterRenderer(mapView, *args)) #mapView.sigSensorRendererChanged.connect(lambda *args : self.setRasterRenderer(mapView, *args))
mapView.sigMapViewVisibility.connect(lambda: self.sigResizeRequired.emit()) mapView.sigMapViewVisibility.connect(lambda: self.sigResizeRequired.emit())
mapView.sigShowProfiles.connect(self.sigShowProfiles.emit) mapView.sigShowProfiles.connect(self.sigShowProfiles.emit)
w.setUpdatesEnabled(True) #w.setUpdatesEnabled(True)
self.sigResizeRequired.emit() self.sigResizeRequired.emit()
def removeMapView(self, mapView): def removeMapView(self, mapView):
assert isinstance(mapView, MapView) assert isinstance(mapView, MapView)
for tsdv in self.views: for tsdv in self.mViews:
tsdv.removeMapView(mapView) tsdv.removeMapView(mapView)
self.sigResizeRequired.emit() self.sigResizeRequired.emit()
...@@ -2202,9 +2206,9 @@ class DateViewCollection(QObject): ...@@ -2202,9 +2206,9 @@ class DateViewCollection(QObject):
#returns the #returns the
if self.focusView is not None: if self.focusView is not None:
assert isinstance(self.focusView, DatumView) assert isinstance(self.focusView, DatumView)
return sorted(self.views,key=lambda v: np.abs(v.TSD.date - self.focusView.TSD.date)) return sorted(self.mViews, key=lambda v: np.abs(v.TSD.date - self.focusView.TSD.date))
else: else:
return self.views return self.mViews
""" """
def setSubsetSize(self, size): def setSubsetSize(self, size):
...@@ -2240,8 +2244,8 @@ class DateViewCollection(QObject): ...@@ -2240,8 +2244,8 @@ class DateViewCollection(QObject):
for i, mapView in enumerate(self.STV.MVC): for i, mapView in enumerate(self.STV.MVC):
DV.insertMapView(mapView) DV.insertMapView(mapView)
bisect.insort(self.views, DV) bisect.insort(self.mViews, DV)
i = self.views.index(DV) i = self.mViews.index(DV)
DV.ui.setParent(self.STV.targetLayout.parentWidget()) DV.ui.setParent(self.STV.targetLayout.parentWidget())
self.STV.targetLayout.insertWidget(i, DV.ui) self.STV.targetLayout.insertWidget(i, DV.ui)
...@@ -2251,10 +2255,10 @@ class DateViewCollection(QObject): ...@@ -2251,10 +2255,10 @@ class DateViewCollection(QObject):
self.sigResizeRequired.emit() self.sigResizeRequired.emit()
def removeDates(self, tsdList): def removeDates(self, tsdList):
toRemove = [v for v in self.views if v.TSD in tsdList] toRemove = [v for v in self.mViews if v.TSD in tsdList]
removedDates = [] removedDates = []
for DV in toRemove: for DV in toRemove:
self.views.remove(DV) self.mViews.remove(DV)
for mapCanvas in DV.mapCanvases.values(): for mapCanvas in DV.mapCanvases.values():
toRemove = mapCanvas.layers() toRemove = mapCanvas.layers()
...@@ -2273,16 +2277,16 @@ class DateViewCollection(QObject): ...@@ -2273,16 +2277,16 @@ class DateViewCollection(QObject):
self.sigResizeRequired.emit() self.sigResizeRequired.emit()
def __len__(self): def __len__(self):
return len(self.views) return len(self.mViews)
def __iter__(self): def __iter__(self):
return iter(self.views) return iter(self.mViews)
def __getitem__(self, slice): def __getitem__(self, slice):
return self.views[slice] return self.mViews[slice]
def __delitem__(self, slice): def __delitem__(self, slice):
self.removeDates(self.views[slice]) self.removeDates(self.mViews[slice])
class MapViewListModel(QAbstractListModel): class MapViewListModel(QAbstractListModel):
......
...@@ -30,8 +30,7 @@ from qgis.PyQt.QtGui import * ...@@ -30,8 +30,7 @@ from qgis.PyQt.QtGui import *
from timeseriesviewer import jp, SETTINGS from timeseriesviewer import jp, SETTINGS
from timeseriesviewer.timeseries import * from timeseriesviewer.timeseries import *
from timeseriesviewer.utils import SpatialExtent, SpatialPoint, px2geo from timeseriesviewer.utils import SpatialExtent, SpatialPoint, px2geo, loadUI
from timeseriesviewer.ui.docks import TsvDockWidgetBase, loadUI
from timeseriesviewer.plotstyling import PlotStyle, PlotStyleButton from timeseriesviewer.plotstyling import PlotStyle, PlotStyleButton
from timeseriesviewer.pixelloader import PixelLoader, PixelLoaderTask from timeseriesviewer.pixelloader import PixelLoader, PixelLoaderTask
from timeseriesviewer.sensorvisualization import SensorListModel from timeseriesviewer.sensorvisualization import SensorListModel
......
...@@ -28,8 +28,8 @@ from qgis.PyQt.QtGui import * ...@@ -28,8 +28,8 @@ from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import * from qgis.PyQt.QtWidgets import *
from timeseriesviewer.timeseries import TimeSeries, TimeSeriesDatum, SensorInstrument from timeseriesviewer.timeseries import TimeSeries, SensorInstrument
from timeseriesviewer.ui.docks import loadUI, TsvDockWidgetBase from timeseriesviewer.utils import loadUI
class SensorDockUI(QgsDockWidget, loadUI('sensordock.ui')): class SensorDockUI(QgsDockWidget, loadUI('sensordock.ui')):
def __init__(self, parent=None): def __init__(self, parent=None):
......
...@@ -966,6 +966,7 @@ class SpectralLibraryPanel(QgsDockWidget): ...@@ -966,6 +966,7 @@ class SpectralLibraryPanel(QgsDockWidget):
sigLoadFromMapRequest = None sigLoadFromMapRequest = None
def __init__(self, parent=None): def __init__(self, parent=None):
super(SpectralLibraryPanel, self).__init__(parent) super(SpectralLibraryPanel, self).__init__(parent)
self.setObjectName('spectralLibraryPanel')
self.setWindowTitle('Spectral Library') self.setWindowTitle('Spectral Library')
self.SLW = SpectralLibraryWidget(self) self.SLW = SpectralLibraryWidget(self)
self.setWidget(self.SLW) self.setWidget(self.SLW)
......
...@@ -34,7 +34,7 @@ from qgis.PyQt.QtCore import * ...@@ -34,7 +34,7 @@ from qgis.PyQt.QtCore import *
from osgeo import gdal from osgeo import gdal
from timeseriesviewer.utils import SpatialExtent from timeseriesviewer.utils import SpatialExtent, loadUI
gdal.SetConfigOption('VRT_SHARED_SOURCE', '0') #!important. really. do not change this. gdal.SetConfigOption('VRT_SHARED_SOURCE', '0') #!important. really. do not change this.
...@@ -394,8 +394,7 @@ class TimeSeriesTableView(QTableView): ...@@ -394,8 +394,7 @@ class TimeSeriesTableView(QTableView):
assert isinstance(b, bool) assert isinstance(b, bool)
from timeseriesviewer.ui.docks import TsvDockWidgetBase
from timeseriesviewer.utils import loadUI
class TimeSeriesDockUI(QgsDockWidget, loadUI('timeseriesdock.ui')): class TimeSeriesDockUI(QgsDockWidget, loadUI('timeseriesdock.ui')):
def __init__(self, parent=None): def __init__(self, parent=None):
super(TimeSeriesDockUI, self).__init__(parent) super(TimeSeriesDockUI, self).__init__(parent)
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>DockWidget</class> <class>cursorLocationInfoPanel</class>
<widget class="QDockWidget" name="DockWidget"> <widget class="QDockWidget" name="cursorLocationInfoPanel">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
...@@ -22,7 +22,16 @@ ...@@ -22,7 +22,16 @@
<property name="spacing"> <property name="spacing">
<number>2</number> <number>2</number>
</property> </property>
<property name="margin"> <property name="leftMargin">