Commit 9aeb1242 authored by Benjamin Jakimow's avatar Benjamin Jakimow
Browse files

fixed current profiles signaling


fixed scaling bug in profileviewdock.ui
removed qtcharts.py
Signed-off-by: Benjamin Jakimow's avatarBenjamin Jakimow benjamin.jakimow@geo.hu-berlin.de <benjamin.jakimow@geo.hu-berlin.de>
parent 789f4b81
Pipeline #12992 failed
......@@ -59,7 +59,7 @@ from eotimeseriesviewer.temporalprofiles import TemporalProfileLayer
from eotimeseriesviewer.mapvisualization import MapView, MapWidget
import eotimeseriesviewer.settings as eotsvSettings
from .externals.qps.speclib.core import SpectralProfile, SpectralLibrary
from .externals.qps.speclib.gui import SpectralLibraryPanel
from .externals.qps.speclib.gui import SpectralLibraryPanel, SpectralLibraryWidget
from .externals.qps.maptools import MapTools, CursorLocationMapTool, QgsMapToolSelect, QgsMapToolSelectionHandler
from .externals.qps.cursorlocationvalue import CursorLocationInfoModel, CursorLocationInfoDock
from .externals.qps.vectorlayertools import VectorLayerTools
......@@ -522,7 +522,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
mw.sigSpatialExtentChanged.connect(self.timeSeries().setCurrentSpatialExtent)
mw.sigVisibleDatesChanged.connect(self.timeSeries().setVisibleDates)
mw.sigMapViewAdded.connect(self.onMapViewAdded)
mw.sigCurrentLocationChanged.connect(
mw.sigCurrentLocationChanged[QgsCoordinateReferenceSystem, QgsPointXY].connect(
lambda crs, pt, canvas=mw: self.setCurrentLocation(SpatialPoint(crs, pt),
mapCanvas=mw.currentMapCanvas()))
mw.sigCurrentLayerChanged.connect(self.updateCurrentLayerActions)
......@@ -893,6 +893,11 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
"""
return self.profileDock.temporalProfileLayer()
def spectralLibraryWidgets(self) -> typing.List[SpectralLibraryWidget]:
w = []
w.append(self.ui.dockSpectralLibrary.SLW)
return w
def spectralLibrary(self) -> SpectralLibrary:
"""
Returns the SpectraLibrary of the SpectralLibrary dock
......@@ -1264,9 +1269,10 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
for lyr in sensorLayers:
assert isinstance(lyr, SensorProxyLayer)
p = SpectralProfile.fromRasterLayer(lyr, spatialPoint)
basename = os.path.basename(lyr.source())
if isinstance(p, SpectralProfile):
p2 = p.copyFieldSubset(sl.fields())
p2.setName('{} {}'.format(p.name(), tsd.date()))
p2.setName(f'{basename}')
p2.setAttribute('date', '{}'.format(tsd.date()))
p2.setAttribute('doy', int(tsd.doy()))
p2.setAttribute('sensor', tsd.sensor().name())
......@@ -1274,7 +1280,17 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
if self.mCurrentMapSpectraLoading == 'TOP':
break
self.ui.dockSpectralLibrary.SLW.setCurrentSpectra(currentSpectra)
if len(currentSpectra) > 0:
self.setCurrentSpectralProfiles(currentSpectra)
def setCurrentSpectralProfiles(self, spectra: typing.List[SpectralProfile]):
if not isinstance(spectra, list):
spectra = [spectra]
for s in spectra:
assert isinstance(s, SpectralProfile)
for w in self.spectralLibraryWidgets():
w.setCurrentProfiles(spectra)
@pyqtSlot(SpatialPoint)
def loadCurrentTemporalProfile(self, spatialPoint: SpatialPoint):
......@@ -1313,7 +1329,7 @@ class EOTimeSeriesViewer(QgisInterface, QObject):
p2.setAttribute('doy', int(tsd.mDOY))
p2.setAttribute('sensor', tsd.mSensor.name())
profiles2.append(p2)
self.ui.dockSpectralLibrary.SLW.setCurrentSpectra(profiles2)
self.ui.dockSpectralLibrary.SLW.setCurrentSpectralProfiles(profiles2)
elif mapToolKey == MapTools.CursorLocation:
......
......@@ -31,7 +31,7 @@ import traceback
import typing
import numpy as np
import time
import qgis.utils
from qgis.PyQt.QtCore import \
Qt, QSize, pyqtSignal, QModelIndex, QTimer, QAbstractListModel
......@@ -1033,8 +1033,8 @@ class MapWidget(QFrame):
self.tbSliderDate: QLabel
self.mCurrentMapView: MapView = None
self.mCurrentMapCanvas: MapCanvas = None
#self.mCurrentMapView: MapView = None
#self.mCurrentMapCanvas: MapCanvas = None
self.mMapViews: typing.List[MapView] = []
self.mCanvases: typing.Dict[MapView, typing.List[MapCanvas]] = dict()
......@@ -1245,29 +1245,43 @@ class MapWidget(QFrame):
Returns the active map canvas, i.e. the MapCanvas that was clicked last.
:return: MapCanvas
"""
return self.mCurrentMapCanvas
canvases = sorted(self.mapCanvases(), key=lambda c: c.property(KEY_LAST_CLICKED), reverse=True)
if len(canvases) > 0:
return canvases[0]
else:
return None
def setCurrentMapCanvas(self, mapCanvas: MapCanvas):
assert isinstance(mapCanvas, MapCanvas)
if mapCanvas != self.mCurrentMapCanvas:
assert mapCanvas in self.mapCanvases()
self.sigCurrentCanvasChanged.emit(mapCanvas)
if isinstance(mapCanvas.mapView(), MapView):
self.setCurrentMapView(mapCanvas.mapView())
canvases = self.mapCanvases()
assert mapCanvas in canvases
mapCanvas.setProperty(KEY_LAST_CLICKED, time.time())
def currentMapView(self) -> MapView:
"""
Returns the last used map view, i.e. the last map view a canvas was clicked on or a layer was selected in
:return:
"""
return self.mCurrentMapView
return self.currentMapCanvas().mapView()
def setCurrentMapView(self, mapView: MapView):
if mapView != self.mCurrentMapView:
assert isinstance(mapView, MapView)
assert isinstance(mapView, MapView)
lastCurrentMapCanvas = self.currentMapCanvas()
lastCurrentMapView = lastCurrentMapCanvas.mapView()
if mapView != lastCurrentMapView:
assert mapView in self.mapViews()
self.mCurrentMapView = mapView
self.sigCurrentMapViewChanged.emit(mapView)
position = 0
for i, c in enumerate(lastCurrentMapView):
if c == lastCurrentMapCanvas:
position = i
break
canvases = mapView.mapCanvases()
if len(canvases) > 0:
position = min(position, len(canvases) - 1)
self.currentMapCanvas(canvases[position])
def writeXml(self, node: QDomElement, doc: QDomDocument) -> bool:
"""
......@@ -1492,11 +1506,11 @@ class MapWidget(QFrame):
def mapViewCanvases(self, mapView: MapView) -> typing.List[MapCanvas]:
"""
Returns the MapCanvases related to a MapView
Returns the MapCanvases related to a MapView, sorted
:param mapView: MapView
:return: [list-of-MapCanvases]
"""
return self.mCanvases[mapView]
return sorted(self.mCanvases[mapView], key=lambda c: c.tsd())
def moveToNextTSD(self):
......@@ -1608,10 +1622,8 @@ class MapWidget(QFrame):
self.sigMapViewsChanged.emit()
self.sigMapViewAdded.emit(mapView)
s = ""
if not isinstance(self.mCurrentMapView, MapView):
self.mCurrentMapView = mapView
if len(self.mapViews()) == 1:
self.setCurrentMapView(mapView)
return mapView
......
......@@ -1372,6 +1372,9 @@ class DateTimeAxis(pg.AxisItem):
return d
def tickFont(self):
return self.style.get('tickFont', None)
def drawPicture(self, p, axisSpec, tickSpecs, textSpecs):
p.setRenderHint(p.Antialiasing, False)
......@@ -1389,8 +1392,8 @@ class DateTimeAxis(pg.AxisItem):
p.drawLine(p1, p2)
## Draw all text
if self.tickFont is not None:
p.setFont(self.tickFont)
if self.tickFont() is not None:
p.setFont(self.tickFont())
p.setPen(self.pen())
# for rect, flags, text in textSpecs:
......
# -*- coding: utf-8 -*-
#
# Licensed under the terms of the MIT License
# Copyright (c) 2015 Pierre Raybaut
"""
Simple example illustrating Qt Charts capabilities to plot curves with
a high number of points, using OpenGL accelerated series
"""
import PyQt5.QtChart
from qgis.PyQt.QtGui import QPolygonF, QPainter
from qgis.PyQt.QtWidgets import QMainWindow
import numpy as np
def series_to_polyline(xdata, ydata):
"""Convert series data to QPolygon(F) polyline
This code is derived from PythonQwt's function named
`qwt.plot_curve.series_to_polyline`"""
size = len(xdata)
polyline = QPolygonF(size)
pointer = polyline.data()
dtype, tinfo = np.float, np.finfo # integers: = np.int, np.iinfo
pointer.setsize(2 * polyline.size() * tinfo(dtype).dtype.itemsize)
memory = np.frombuffer(pointer, dtype)
memory[:(size - 1) * 2 + 1:2] = xdata
memory[1:(size - 1) * 2 + 2:2] = ydata
return polyline
class TestWindow(QMainWindow):
def __init__(self, parent=None):
super(TestWindow, self).__init__(parent=parent)
self.ncurves = 0
self.chart = QChart()
self.chart.legend().hide()
self.view = QChartView(self.chart)
self.view.setRenderHint(QPainter.Antialiasing)
self.setCentralWidget(self.view)
def set_title(self, title):
self.chart.setTitle(title)
def add_data(self, xdata, ydata, color=None):
curve = QLineSeries()
pen = curve.pen()
if color is not None:
pen.setColor(color)
pen.setWidthF(.1)
curve.setPen(pen)
curve.setUseOpenGL(True)
curve.append(series_to_polyline(xdata, ydata))
self.chart.addSeries(curve)
self.chart.createDefaultAxes()
self.ncurves += 1
if __name__ == '__main__':
import sys
from qgis.PyQt.QtWidgets import QApplication
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtChart import *
app = QApplication(sys.argv)
window = TestWindow()
npoints = 1000000
xdata = np.linspace(0., 10., npoints)
window.add_data(xdata, np.sin(xdata), color=Qt.red)
window.add_data(xdata, np.cos(xdata), color=Qt.blue)
window.set_title("Simple example with %d curves of %d points " \
"(OpenGL Accelerated Series)" \
% (window.ncurves, npoints))
window.setWindowTitle("Simple performance example")
window.show()
window.resize(500, 400)
sys.exit(app.exec_())
\ No newline at end of file
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1116</width>
<height>393</height>
<height>331</height>
</rect>
</property>
<property name="minimumSize">
......@@ -140,7 +140,7 @@
<string>Temporal profile coordinates</string>
</property>
<property name="icon">
<iconset resource="../../../QGIS/images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionOpenTable.svg</normaloff>:/images/themes/default/mActionOpenTable.svg</iconset>
</property>
</item>
......@@ -283,7 +283,7 @@
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="orientation">
......@@ -465,7 +465,7 @@
</widget>
<action name="actionRefresh2D">
<property name="icon">
<iconset resource="../../../QGIS/images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionReload.svg</normaloff>:/images/themes/default/mActionReload.svg</iconset>
</property>
<property name="text">
......@@ -477,7 +477,7 @@
</action>
<action name="actionAddStyle2D">
<property name="icon">
<iconset resource="../../../QGIS/images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionAdd.svg</normaloff>:/images/themes/default/mActionAdd.svg</iconset>
</property>
<property name="text">
......@@ -489,7 +489,7 @@
</action>
<action name="actionRemoveStyle2D">
<property name="icon">
<iconset resource="../../../QGIS/images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionRemove.svg</normaloff>:/images/themes/default/mActionRemove.svg</iconset>
</property>
<property name="text">
......@@ -537,7 +537,7 @@
</action>
<action name="actionSaveTemporalProfiles">
<property name="icon">
<iconset resource="../../../QGIS/images/images.qrc">
<iconset>
<normaloff>:/images/themes/default/mActionFileSaveAs.svg</normaloff>:/images/themes/default/mActionFileSaveAs.svg</iconset>
</property>
<property name="text">
......
Supports Markdown
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