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.main import TimeSeriesViewer
from timeseriesviewer.mapvisualization import *
from timeseriesviewer.profilevisualization import *
from timeseriesviewer.timeseries import *
from timeseriesviewer import DIR_REPO, DIR_QGIS_RESOURCES
DIR_SCREENSHOTS = jp(DIR_REPO, 'screenshots')
os.makedirs(DIR_SCREENSHOTS, exist_ok=True)
......@@ -12,12 +19,125 @@ app = initQgisApplication(qgisResourceDir=DIR_QGIS_RESOURCES)
TS = TimeSeriesViewer(None)
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 *
from qgis.PyQt.QtWidgets import *
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
class LabelShortcutButton(QPushButton):
......
......@@ -565,7 +565,7 @@ class TimeSeriesViewer(QgisInterface, QObject):
extentWMC = extent.toCrs(crsWMC)
pxSize = max(self.TS.getPixelSizes(), key= lambda s :s.width())
canvasSize = self.spatialTemporalVis.subsetSize()
canvasSize = self.spatialTemporalVis.mapSize()
f = 0.05
width = f * canvasSize.width() * pxSize.width() # width in map units
height = f * canvasSize.height() * pxSize.height()
......
......@@ -1260,7 +1260,7 @@ class MapView(QObject):
mapCanvas.setRenderer(renderer)
#mapCanvas.refresh()
"""
def getSensorWidget(self, sensor):
def sensorWidget(self, sensor):
assert type(sensor) is SensorInstrument
return self.mSensorViews[sensor]
......@@ -1675,7 +1675,7 @@ class DatumView(QObject):
self.setColumnInfo()
self.MVC = stv.MVC
self.DVC = stv.DVC
self.mapCanvases = dict()
self.mMapCanvases = dict()
self.mRenderState = dict()
def setColumnInfo(self):
......@@ -1704,7 +1704,7 @@ class DatumView(QObject):
self.ui.setStyleSheet(styleOff)
def removeMapView(self, mapView):
canvas = self.mapCanvases.pop(mapView)
canvas = self.mMapCanvases.pop(mapView)
self.ui.layout().removeWidget(canvas)
canvas.close()
#self.adjustBaseMinSize()
......@@ -1712,7 +1712,7 @@ class DatumView(QObject):
def refresh(self):
if self.ui.isVisible():
for c in self.mapCanvases.values():
for c in self.mMapCanvases.values():
if c.isVisible():
c.refresh()
......@@ -1756,8 +1756,8 @@ class DatumView(QObject):
self.showLoading(any(self.mRenderState.values()))
def onRendering(self, *args):
renderFlags = [m.renderFlag() for m in self.mapCanvases.values()]
drawFlags = [m.isDrawing() for m in self.mapCanvases.values()]
renderFlags = [m.renderFlag() for m in self.mMapCanvases.values()]
drawFlags = [m.isDrawing() for m in self.mMapCanvases.values()]
# print((renderFlags, drawFlags))
isLoading = any(renderFlags)
......@@ -1770,14 +1770,15 @@ class DatumView(QObject):
from timeseriesviewer.mapcanvas import MapCanvas
assert isinstance(mapCanvas, MapCanvas)
assert isinstance(mapView, MapView)
self.mapCanvases[mapView] = mapCanvas
self.mMapCanvases[mapView] = mapCanvas
#mapView.sigTitleChanged.connect(lambda title : mapCanvas.setSaveFileName('{}_{}'.format(self.TSD.date, title)))
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()
#register signals handled on (this) DV level
......@@ -1862,7 +1863,7 @@ class SpatialTemporalVisualization(QObject):
self.MVC = self.ui.dockMapViews
assert isinstance(self.MVC, MapViewCollectionDock)
self.MVC.sigShowProfiles.connect(self.sigShowProfiles.emit)
self.MVC.sigMapViewAdded.connect(self.onMapViewAdded)
self.vectorOverlay = None
self.DVC = DateViewCollection(self)
......@@ -1878,6 +1879,9 @@ class SpatialTemporalVisualization(QObject):
self.setSpatialExtent(self.TS.getMaxSpatialExtent())
#self.setSubsetSize(QSize(100,50))
def onMapViewAdded(self, *args):
self.adjustScrollArea()
s = ""
def createMapView(self):
self.MVC.createMapView()
......@@ -1925,7 +1929,7 @@ class SpatialTemporalVisualization(QObject):
self.sigMapSizeChanged.emit(self.mSize)
self.adjustScrollArea()
def subsetSize(self):
def mapSize(self):
return QSize(self.mSize)
......@@ -1986,7 +1990,7 @@ class SpatialTemporalVisualization(QObject):
canvas.setMapTool(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):
mt.sigLocationRequest[SpatialPoint, QgsMapCanvas].connect(lambda c, m : self.sigShowProfiles.emit(c,m, mapToolKey))
......@@ -2128,7 +2132,7 @@ class DateViewCollection(QObject):
#self.tsv = tsv
#self.timeSeries = tsv.TS
self.views = list()
self.mViews = list()
self.STV = STViz
self.ui = self.STV.targetLayout.parentWidget()
self.scrollArea = self.ui.parentWidget().parentWidget()
......@@ -2145,14 +2149,14 @@ class DateViewCollection(QObject):
def tsdFromMapCanvas(self, mapCanvas):
assert isinstance(mapCanvas, MapCanvas)
for view in self.views:
for view in self.mViews:
assert isinstance(view, DatumView)
if mapCanvas in view.mapCanvases.values():
if mapCanvas in view.mMapCanvases.values():
return view.TSD
return None
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:
return r[0]
else:
......@@ -2161,26 +2165,26 @@ class DateViewCollection(QObject):
def addMapView(self, mapView):
assert isinstance(mapView, MapView)
w = self.ui
w.setUpdatesEnabled(False)
for tsdv in self.views:
tsdv.ui.setUpdatesEnabled(False)
#w.setUpdatesEnabled(False)
#for tsdv in self.mViews:
# tsdv.ui.setUpdatesEnabled(False)
for tsdv in self.views:
for tsdv in self.mViews:
tsdv.insertMapView(mapView)
for tsdv in self.views:
tsdv.ui.setUpdatesEnabled(True)
#for tsdv in self.mViews:
# tsdv.ui.setUpdatesEnabled(True)
#mapView.sigSensorRendererChanged.connect(lambda *args : self.setRasterRenderer(mapView, *args))
mapView.sigMapViewVisibility.connect(lambda: self.sigResizeRequired.emit())
mapView.sigShowProfiles.connect(self.sigShowProfiles.emit)
w.setUpdatesEnabled(True)
#w.setUpdatesEnabled(True)
self.sigResizeRequired.emit()
def removeMapView(self, mapView):
assert isinstance(mapView, MapView)
for tsdv in self.views:
for tsdv in self.mViews:
tsdv.removeMapView(mapView)
self.sigResizeRequired.emit()
......@@ -2202,9 +2206,9 @@ class DateViewCollection(QObject):
#returns the
if self.focusView is not None:
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:
return self.views
return self.mViews
"""
def setSubsetSize(self, size):
......@@ -2240,8 +2244,8 @@ class DateViewCollection(QObject):
for i, mapView in enumerate(self.STV.MVC):
DV.insertMapView(mapView)
bisect.insort(self.views, DV)
i = self.views.index(DV)
bisect.insort(self.mViews, DV)
i = self.mViews.index(DV)
DV.ui.setParent(self.STV.targetLayout.parentWidget())
self.STV.targetLayout.insertWidget(i, DV.ui)
......@@ -2251,10 +2255,10 @@ class DateViewCollection(QObject):
self.sigResizeRequired.emit()
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 = []
for DV in toRemove:
self.views.remove(DV)
self.mViews.remove(DV)
for mapCanvas in DV.mapCanvases.values():
toRemove = mapCanvas.layers()
......@@ -2273,16 +2277,16 @@ class DateViewCollection(QObject):
self.sigResizeRequired.emit()
def __len__(self):
return len(self.views)
return len(self.mViews)
def __iter__(self):
return iter(self.views)
return iter(self.mViews)
def __getitem__(self, slice):
return self.views[slice]
return self.mViews[slice]
def __delitem__(self, slice):
self.removeDates(self.views[slice])
self.removeDates(self.mViews[slice])
class MapViewListModel(QAbstractListModel):
......
......@@ -30,8 +30,7 @@ from qgis.PyQt.QtGui import *
from timeseriesviewer import jp, SETTINGS
from timeseriesviewer.timeseries import *
from timeseriesviewer.utils import SpatialExtent, SpatialPoint, px2geo
from timeseriesviewer.ui.docks import TsvDockWidgetBase, loadUI
from timeseriesviewer.utils import SpatialExtent, SpatialPoint, px2geo, loadUI
from timeseriesviewer.plotstyling import PlotStyle, PlotStyleButton
from timeseriesviewer.pixelloader import PixelLoader, PixelLoaderTask
from timeseriesviewer.sensorvisualization import SensorListModel
......
......@@ -28,8 +28,8 @@ from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
from timeseriesviewer.timeseries import TimeSeries, TimeSeriesDatum, SensorInstrument
from timeseriesviewer.ui.docks import loadUI, TsvDockWidgetBase
from timeseriesviewer.timeseries import TimeSeries, SensorInstrument
from timeseriesviewer.utils import loadUI
class SensorDockUI(QgsDockWidget, loadUI('sensordock.ui')):
def __init__(self, parent=None):
......
......@@ -966,6 +966,7 @@ class SpectralLibraryPanel(QgsDockWidget):
sigLoadFromMapRequest = None
def __init__(self, parent=None):
super(SpectralLibraryPanel, self).__init__(parent)
self.setObjectName('spectralLibraryPanel')
self.setWindowTitle('Spectral Library')
self.SLW = SpectralLibraryWidget(self)
self.setWidget(self.SLW)
......
......@@ -34,7 +34,7 @@ from qgis.PyQt.QtCore import *
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.
......@@ -394,8 +394,7 @@ class TimeSeriesTableView(QTableView):
assert isinstance(b, bool)
from timeseriesviewer.ui.docks import TsvDockWidgetBase
from timeseriesviewer.utils import loadUI
class TimeSeriesDockUI(QgsDockWidget, loadUI('timeseriesdock.ui')):
def __init__(self, parent=None):
super(TimeSeriesDockUI, self).__init__(parent)
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DockWidget</class>
<widget class="QDockWidget" name="DockWidget">
<class>cursorLocationInfoPanel</class>
<widget class="QDockWidget" name="cursorLocationInfoPanel">
<property name="geometry">
<rect>
<x>0</x>
......@@ -22,7 +22,16 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
......@@ -115,7 +124,16 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
......@@ -173,7 +191,16 @@
<property name="spacing">
<number>2</number>
</property>
<property name="margin">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
......@@ -254,6 +281,7 @@
<class>QgsProjectionSelectionWidget</class>
<extends>QWidget</extends>
<header>qgsprojectionselectionwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
......
......@@ -46,176 +46,6 @@ class TsvDockWidgetBase(QgsDockWidget):
class DEPR_RenderingDockUI(QgsDockWidget, loadUI('renderingdock.ui')):
from timeseriesviewer.crosshair import CrosshairStyle
sigMapCanvasColorChanged = pyqtSignal(QColor)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigMapSizeChanged = pyqtSignal(QSize)
sigQgisInteractionRequest = pyqtSignal(str)
def __init__(self, parent=None):
super(RenderingDockUI, self).__init__(parent)
self.setupUi(self)
self.progress = dict()
self.spinBoxMapSizeX.valueChanged.connect(lambda : self.onMapSizeChanged('X'))
self.spinBoxMapSizeY.valueChanged.connect(lambda : self.onMapSizeChanged('Y'))
self.mLastMapSize = self.mapSize()
self.mSubsetRatio = None
self.mResizeStop = False
self.btnApplySizeChanges.setEnabled(False)
self.btnApplySizeChanges.clicked.connect(lambda: self.onMapSizeChanged(None))
self.btnMapCanvasColor.colorChanged.connect(self.sigMapCanvasColorChanged)
self.btnCrs.crsChanged.connect(self.sigCrsChanged)
self.progressBar.setVisible(False)
self.enableQgisInteraction(False)
self.btnSetQGISCenter.clicked.connect(lambda : self.sigQgisInteractionRequest.emit('tsvCenter2qgsCenter'))
self.btnSetQGISExtent.clicked.connect(lambda: self.sigQgisInteractionRequest.emit('tsvExtent2qgsExtent'))
self.btnGetQGISCenter.clicked.connect(lambda: self.sigQgisInteractionRequest.emit('qgisCenter2tsvCenter'))
self.btnGetQGISExtent.clicked.connect(lambda: self.sigQgisInteractionRequest.emit('qgisExtent2tsvExtent'))
sigShowVectorOverlay = pyqtSignal(QgsVectorLayer)
sigRemoveVectorOverlay = pyqtSignal()
def onVectorOverlayerChanged(self, *args):
b = self.gbQgsVectorLayer.isChecked()
lyr = self.cbQgsVectorLayer.currentLayer()
if b and isinstance(lyr, QgsVectorLayer):
self.sigShowVectorOverlay.emit(lyr)
else:
self.sigRemoveVectorOverlay.emit()
s = ""
def enableQgisInteraction(self, b):
self.gbSyncQgs.setEnabled(b)
if b:
self.gbSyncQgs.setTitle('QGIS')
else:
self.gbSyncQgs.setTitle('QGIS (not available)')
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
self.btnCrs.setCrs(crs)
self.btnCrs.setLayerCrs(crs)
#self.sigCrsChanged.emit(self.crs())
def crs(self):
return self.btnCrs.crs()
def spatialExtent(self):
crs = self.crs()
if not crs:
return None
width = QgsVector(self.spinBoxExtentWidth.value(), 0.0)
height = QgsVector(0.0, self.spinBoxExtentHeight.value())
Center = QgsPointXY(self.spinBoxExtentCenterX.value(), self.spinBoxExtentCenterY.value())
UL = Center - (width * 0.5) + (height * 0.5)
LR = Center + (width * 0.5) - (height * 0.5)
from timeseriesviewer.main import SpatialExtent
return SpatialExtent(self.crs(), UL, LR)
def setSpatialExtent(self, extent):
old = self.spatialExtent()
assert isinstance(extent, SpatialExtent)
center = extent.center()
states = self._blockSignals(self.spatialExtentWidgets, True)
self.spinBoxExtentCenterX.setValue(center.x())
self.spinBoxExtentCenterY.setValue(center.y())
self.spinBoxExtentWidth.setValue(extent.width())
self.spinBoxExtentHeight.setValue(extent.height())
self.setCrs(extent.crs())
self._blockSignals(states)
if extent != old:
self.sigSetSpatialExtent.emit(extent