Skip to content
Snippets Groups Projects
Commit 02610731 authored by benjamin.jakimow@geo.hu-berlin.de's avatar benjamin.jakimow@geo.hu-berlin.de
Browse files

TsvDockWidgetBase for panel docks

NavigationDockUI logic
parent 3901a79c
No related branches found
No related tags found
No related merge requests found
......@@ -11,36 +11,199 @@ import sys, re, os, six
from timeseriesviewer import jp, SETTINGS
from timeseriesviewer.ui import loadUIFormClass, DIR_UI
from timeseriesviewer.main import SpatialExtent
load = lambda p : loadUIFormClass(jp(DIR_UI,p))
class ProfileViewDockUI(QgsDockWidget, load('profileviewdock.ui')):
class TsvDockWidgetBase(QgsDockWidget):
def _blockSignals(self, widgets, block=True):
states = dict()
if isinstance(widgets, dict):
for w, block in widgets.items():
states[w] = w.blockSignals(block)
else:
for w in widgets:
states[w] = w.blockSignals(block)
return states
class ProfileViewDockUI(TsvDockWidgetBase, load('profileviewdock.ui')):
def __init__(self, parent=None):
super(ProfileViewDockUI, self).__init__(parent)
self.setupUi(self)
class SensorDockUI(QgsDockWidget, load('sensordock.ui')):
class SensorDockUI(TsvDockWidgetBase, load('sensordock.ui')):
def __init__(self, parent=None):
super(SensorDockUI, self).__init__(parent)
self.setupUi(self)
class RenderingDockUI(QgsDockWidget, load('renderingdock.ui')):
class RenderingDockUI(TsvDockWidgetBase, load('renderingdock.ui')):
def __init__(self, parent=None):
super(RenderingDockUI, self).__init__(parent)
self.setupUi(self)
class NavigationDockUI(QgsDockWidget, load('navigationdock.ui')):
def subsetSize(self):
return QSize(self.spinBoxSubsetSizeX.value(),
self.spinBoxSubsetSizeY.value())
class NavigationDockUI(TsvDockWidgetBase, load('navigationdock.ui')):
from timeseriesviewer.timeseries import TimeSeriesDatum
sigNavToDOI = pyqtSignal(TimeSeriesDatum)
def __init__(self, parent=None):
super(NavigationDockUI, self).__init__(parent)
self.setupUi(self)
self.mCrs = None
self.btnNavToFirstTSD.setDefaultAction(parent.actionFirstTSD)
self.btnNavToLastTSD.setDefaultAction(parent.actionLastTSD)
self.btnNavToPreviousTSD.setDefaultAction(parent.actionPreviousTSD)
self.btnNavToNextTSD.setDefaultAction(parent.actionNextTSD)
#default: disable QgsSync box
self.gbSyncQgs.setEnabled(False)
self.cbSyncQgsMapExtent.clicked.connect(self.qgsSyncStateChanged)
self.cbSyncQgsMapCenter.clicked.connect(self.qgsSyncStateChanged)
self.cbSyncQgsCRS.clicked.connect(self.qgsSyncStateChanged)
self.spatialExtentWidgets = [self.spinBoxExtentCenterX, self.spinBoxExtentCenterY,
self.spinBoxExtentWidth, self.spinBoxExtentHeight]
self.sliderDOI.valueChanged.connect(self.onSliderDOIChanged)
self.connectTimeSeries(None)
def connectTimeSeries(self, TS):
self.TS = TS
self.timeSeriesInitialized = False
if TS is not None:
TS.sigTimeSeriesDatesAdded.connect(self.updateFromTimeSeries)
self.updateFromTimeSeries()
def updateFromTimeSeries(self):
self.sliderDOI.setMinimum(1)
if self.TS is None or len(self.TS) == 0:
#reset
self.timeSeriesInitialized = False
self.labelDOIValue.setText('Time series is empty')
self.sliderDOI.setMaximum(1)
else:
l = len(self.TS)
self.sliderDOI.setMaximum(l)
# get meaningfull tick intervall
for tickInterval in [1, 5, 10, 25, 50, 100, 200]:
if (self.sliderDOI.size().width() / float(l) * tickInterval) > 5:
break
self.sliderDOI.setTickInterval(tickInterval)
if not self.timeSeriesInitialized:
self.setSpatialExtent(self.TS.getMaxSpatialExtent(self.crs()))
self.timeSeriesInitialized = True
def setDOISliderValue(self, key):
ui = self.ui
v = ui.sliderDOI.value()
if key == 'first':
v = ui.sliderDOI.minimum()
elif key == 'last':
v = ui.sliderDOI.maximum()
elif key == 'next':
v = min([v + 1, ui.sliderDOI.maximum()])
elif key == 'previous':
v = max([v - 1, ui.sliderDOI.minimum()])
ui.sliderDOI.setValue(v)
def onSliderDOIChanged(self, i):
if self.TS is None or len(self.TS) == 0:
self.labelDOIValue.setText('<empty timeseries>')
else:
assert i <= len(self.TS)
TSD = self.TS.data[i - 1]
self.labelDOIValue.setText(str(TSD.date))
self.sigNavToDOI.emit(TSD)
def qgsSyncStateChanged(self, *args):
s = ""
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
old = self.mCrs
self.mCrs = crs
self.textBoxCRSInfo.setPlainText(crs.toWkt())
if self.mCrs != old:
self.sigCrsChanged.emit(crs)
def crs(self):
return self.mCrs
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
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 = QgsPoint(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()
from timeseriesviewer.main import 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.sigSpatialExtentChanged.emit(extent)
def _blockSignals(self, widgets, block=True):
states = dict()
if isinstance(widgets, dict):
for w, block in widgets.items():
states[w] = w.blockSignals(block)
else:
for w in widgets:
states[w] = w.blockSignals(block)
return states
class TimeSeriesDockUI(QgsDockWidget, load('timeseriesdock.ui')):
class TimeSeriesDockUI(TsvDockWidgetBase, load('timeseriesdock.ui')):
def __init__(self, parent=None):
super(TimeSeriesDockUI, self).__init__(parent)
self.setupUi(self)
class MapViewDockUI(QgsDockWidget, load('mapviewdock.ui')):
class MapViewDockUI(TsvDockWidgetBase, load('mapviewdock.ui')):
def __init__(self, parent=None):
super(MapViewDockUI, self).__init__(parent)
self.setupUi(self)
......@@ -86,11 +249,12 @@ class MapViewDockUI(QgsDockWidget, load('mapviewdock.ui')):
#self.toogleLayout(self.scrollAreaMapsViewDockContent)
self.toogleLayout(self.BVButtonList)
class LabelingDockUI(QgsDockWidget, load('labelingdock.ui')):
class LabelingDockUI(TsvDockWidgetBase, load('labelingdock.ui')):
def __init__(self, parent=None):
super(LabelingDockUI, self).__init__(parent)
self.setupUi(self)
self.btnClearLabelList.clicked.connect(self.tbCollectedLabels.clear)
if __name__ == '__main__':
import site, sys
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment