Newer
Older
self.sigSpatialExtentChanged.emit(extent)

benjamin.jakimow@geo.hu-berlin.de
committed
def setBackgroundColor(self, color:QColor):
"""
Sets the MapCanvas background color
:param color: QColor
"""
assert isinstance(color, QColor)
self.mColor = color
for mapCanvas in self.mMapCanvases:
assert isinstance(mapCanvas, MapCanvas)
mapCanvas.setCanvasColor(color)
def backgroundColor(self)->QColor:
"""
Returns the MapCanvas background color
:return: QColor
"""
return self.mColor

Benjamin Jakimow
committed
def mapCanvases(self, mapView=None)->list:
"""
Returns MapCanvases
:param mapView: a MapView to return MapCanvases from only, defaults to None
:return: [list-of-MapCanvas]
"""
if isinstance(mapView, MapView):
s = ""

Benjamin Jakimow
committed
def mapViews(self)->list:
"""
Returns a list of all mapviews
:return [list-of-MapViews]:
"""
return self.MVC[:]
def setCrs(self, crs):
assert isinstance(crs, QgsCoordinateReferenceSystem)
transform = QgsCoordinateTransform()
transform.setSourceCrs(self.mCRS)
transform.setDestinationCrs(crs)
if transform.isValid() and not transform.isShortCircuited():

Benjamin Jakimow
committed
for mapCanvas in self.mapCanvases():
# print(('STV set CRS {} {}', str(mapCanvas), self.mCRS.description()))
mapCanvas.setDestinationCrs(QgsCoordinateReferenceSystem(crs))
"""
from timeseriesviewer.utils import saveTransform
if saveTransform(self.mSpatialExtent, self.mCRS, crs):
self.mCRS = crs
else:
pass
"""
self.sigCRSChanged.emit(self.crs())
def crs(self)->QgsCoordinateReferenceSystem:
"""
Returns the QgsCoordinateReferenceSystem
:return: QgsCoordinateReferenceSystem
"""
def spatialExtent(self)->SpatialExtent:
"""
Returns the SpatialExtent
:return: SpatialExtent
"""

benjamin.jakimow@geo.hu-berlin.de
committed
return self.mSpatialExtent

benjamin.jakimow@geo.hu-berlin.de
committed
def navigateToTSD(self, TSD:TimeSeriesDatum):
"""
Changes the viewport of the scroll window to show the requested TimeSeriesDatum
:param TSD: TimeSeriesDatum
"""

benjamin.jakimow@geo.hu-berlin.de
committed
assert isinstance(TSD, TimeSeriesDatum)
#get widget related to TSD

benjamin.jakimow@geo.hu-berlin.de
committed
assert isinstance(self.scrollArea, QScrollArea)
self.scrollArea.ensureWidgetVisible(tsdv.ui)

benjamin.jakimow@geo.hu-berlin.de
committed
sigResizeRequired = pyqtSignal()
sigLoadingStarted = pyqtSignal(MapView, TimeSeriesDatum)
sigLoadingFinished = pyqtSignal(MapView, TimeSeriesDatum)

benjamin.jakimow@geo.hu-berlin.de
committed
sigShowProfiles = pyqtSignal(SpatialPoint)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)

benjamin.jakimow@geo.hu-berlin.de
committed
def __init__(self, STViz):
assert isinstance(STViz, SpatialTemporalVisualization)
super(DateViewCollection, self).__init__()

benjamin.jakimow@geo.hu-berlin.de
committed
#self.tsv = tsv
#self.timeSeries = tsv.TS
self.STV = STViz
self.ui = self.STV.targetLayout.parentWidget()

benjamin.jakimow@geo.hu-berlin.de
committed
self.scrollArea = self.ui.parentWidget().parentWidget()
#potentially there are many more dates than views.
#therefore we implement the addinng/removing of mapviews here
#we reduce the number of layout refresh calls by
#suspending signals, adding the new map view canvases, and sending sigResizeRequired
self.STV.MVC.sigMapViewAdded.connect(self.addMapView)
self.STV.MVC.sigMapViewRemoved.connect(self.removeMapView)

benjamin.jakimow@geo.hu-berlin.de
committed
self.setFocusView(None)

benjamin.jakimow@geo.hu-berlin.de
committed
def tsdFromMapCanvas(self, mapCanvas):
assert isinstance(mapCanvas, MapCanvas)
assert isinstance(view, DatumView)
if mapCanvas in view.mMapCanvases.values():
return view.TSD
return None

benjamin.jakimow@geo.hu-berlin.de
committed
def tsdView(self, tsd):
r = [v for v in self.mViews if v.TSD == tsd]

benjamin.jakimow@geo.hu-berlin.de
committed
if len(r) == 1:
return r[0]
else:
raise Exception('TSD not in list')
def addMapView(self, mapView):
assert isinstance(mapView, MapView)
w = self.ui
#w.setUpdatesEnabled(False)
#for tsdv in self.mViews:
# tsdv.ui.setUpdatesEnabled(False)

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
tsdv.insertMapView(mapView)
#for tsdv in self.mViews:
# tsdv.ui.setUpdatesEnabled(True)

benjamin.jakimow@geo.hu-berlin.de
committed
#mapView.sigSensorRendererChanged.connect(lambda *args : self.setRasterRenderer(mapView, *args))
mapView.sigMapViewVisibility.connect(lambda: self.sigResizeRequired.emit())
mapView.sigShowProfiles.connect(self.sigShowProfiles.emit)

benjamin.jakimow@geo.hu-berlin.de
committed
self.sigResizeRequired.emit()
def removeMapView(self, mapView):
assert isinstance(mapView, MapView)

benjamin.jakimow@geo.hu-berlin.de
committed
tsdv.removeMapView(mapView)
self.sigResizeRequired.emit()

benjamin.jakimow@geo.hu-berlin.de
committed
def highlightDate(self, tsd):
"""
Highlights a time series data for a specific time our
:param tsd:
:return:
"""
tsdView = self.tsdView(tsd)
if isinstance(tsdView, DatumView):
tsdView.setHighlight(True)

benjamin.jakimow@geo.hu-berlin.de
committed
def setFocusView(self, tsd):
self.focusView = tsd
def orderedViews(self):
#returns the
if self.focusView is not None:
assert isinstance(self.focusView, DatumView)
return sorted(self.mViews, key=lambda v: np.abs(v.TSD.date - self.focusView.TSD.date))

benjamin.jakimow@geo.hu-berlin.de
committed
else:

benjamin.jakimow@geo.hu-berlin.de
committed

benjamin.jakimow@geo.hu-berlin.de
committed
def setSubsetSize(self, size):
assert isinstance(size, QSize)
self.subsetSize = size
for tsdView in self.orderedViews():
tsdView.blockSignals(True)
for tsdView in self.orderedViews():
tsdView.setSubsetSize(size)
for tsdView in self.orderedViews():
tsdView.blockSignals(False)

benjamin.jakimow@geo.hu-berlin.de
committed
def addDates(self, tsdList):
"""
Create a new TSDView
:param tsdList:
:return:
"""
for tsd in tsdList:
assert isinstance(tsd, TimeSeriesDatum)
#tsdView.setSubsetSize(self.subsetSize)
DV.sigLoadingStarted.connect(self.sigLoadingStarted.emit)
DV.sigLoadingFinished.connect(self.sigLoadingFinished.emit)
DV.sigVisibilityChanged.connect(lambda: self.STV.adjustScrollArea())

benjamin.jakimow@geo.hu-berlin.de
committed
for i, mapView in enumerate(self.STV.MVC):
DV.insertMapView(mapView)

benjamin.jakimow@geo.hu-berlin.de
committed
bisect.insort(self.mViews, DV)
i = self.mViews.index(DV)

benjamin.jakimow@geo.hu-berlin.de
committed
DV.ui.setParent(self.STV.targetLayout.parentWidget())
self.STV.targetLayout.insertWidget(i, DV.ui)
DV.ui.show()

benjamin.jakimow@geo.hu-berlin.de
committed
if len(tsdList) > 0:
self.sigResizeRequired.emit()
def removeDates(self, tsdList):
toRemove = [v for v in self.mViews if v.TSD in tsdList]

benjamin.jakimow@geo.hu-berlin.de
committed
removedDates = []

benjamin.jakimow@geo.hu-berlin.de
committed
for mapCanvas in DV.mMapCanvases.values():

benjamin.jakimow@geo.hu-berlin.de
committed
toRemove = mapCanvas.layers()
mapCanvas.setLayers([])
toRemove = [l for l in toRemove if isinstance(l, QgsRasterLayer)]
if len(toRemove) > 0:
QgsProject.instance().removeMapLayers([l.id() for l in toRemove])

benjamin.jakimow@geo.hu-berlin.de
committed
DV.ui.parent().layout().removeWidget(DV.ui)
DV.ui.hide()
DV.ui.close()
removedDates.append(DV.TSD)
del DV

benjamin.jakimow@geo.hu-berlin.de
committed
if len(removedDates) > 0:
self.sigResizeRequired.emit()
def __len__(self):

benjamin.jakimow@geo.hu-berlin.de
committed
def __iter__(self):

benjamin.jakimow@geo.hu-berlin.de
committed
def __getitem__(self, slice):

benjamin.jakimow@geo.hu-berlin.de
committed
def __delitem__(self, slice):

benjamin.jakimow@geo.hu-berlin.de
committed
class MapViewListModel(QAbstractListModel):
"""
A model to keep a list of map views.
"""
sigMapViewsAdded = pyqtSignal(list)
sigMapViewsRemoved = pyqtSignal(list)
def __init__(self, parent=None):
super(MapViewListModel, self).__init__(parent)
self.mMapViewList = []
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
def addMapView(self, mapView):
i = len(self.mMapViewList)
self.insertMapView(i, mapView)
def insertMapView(self, i, mapView):
self.insertMapViews(i, [mapView])
def insertMapViews(self, i, mapViews):
assert isinstance(mapViews, list)
assert i >= 0 and i <= len(self.mMapViewList)
self.beginInsertRows(QModelIndex(), i, i + len(mapViews) - 1)
for j in range(len(mapViews)):
mapView = mapViews[j]
assert isinstance(mapView, MapView)
mapView.sigTitleChanged.connect(
lambda : self.doRefresh([mapView])
)
self.mMapViewList.insert(i + j, mapView)
self.endInsertRows()
self.sigMapViewsAdded.emit(mapViews)
def doRefresh(self, mapViews):
for mapView in mapViews:
idx = self.mapView2idx(mapView)
self.dataChanged.emit(idx, idx)
def removeMapView(self, mapView):
self.removeMapViews([mapView])
def removeMapViews(self, mapViews):
assert isinstance(mapViews, list)
for mv in mapViews:
assert mv in self.mMapViewList
idx = self.mapView2idx(mv)
self.beginRemoveRows(idx.parent(), idx.row(), idx.row())
self.mMapViewList.remove(mv)
self.endRemoveRows()
self.sigMapViewsRemoved.emit(mapViews)
def rowCount(self, parent=None, *args, **kwargs):
return len(self.mMapViewList)
def columnCount(self, QModelIndex_parent=None, *args, **kwargs):
return 1
def idx2MapView(self, index):
if isinstance(index, QModelIndex):
if index.isValid():
index = index.row()
else:
return None
assert index >= 0 and index < len(self.mMapViewList)
return self.mMapViewList[index]
def mapView2idx(self, mapView):
assert isinstance(mapView, MapView)
row = self.mMapViewList.index(mapView)
return self.createIndex(row, 0, mapView)
def __len__(self):
return len(self.mMapViewList)
def __iter__(self):
return iter(self.mMapViewList)
def __getitem__(self, slice):
return self.mMapViewList[slice]
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return None
if (index.row() >= len(self.mMapViewList)) or (index.row() < 0):
return None
mapView = self.idx2MapView(index)
assert isinstance(mapView, MapView)
value = None
if role == Qt.DisplayRole:
value = '{} {}'.format(index.row() +1 , mapView.title())
#if role == Qt.DecorationRole:
#value = classInfo.icon(QSize(20,20))
if role == Qt.UserRole:
value = mapView
return value

benjamin.jakimow@geo.hu-berlin.de
committed
class MapViewCollectionDock(QgsDockWidget, loadUI('mapviewdock.ui')):
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)

Benjamin Jakimow
committed
sigMapCanvasColorChanged = pyqtSignal(QColor)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigMapSizeChanged = pyqtSignal(QSize)
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
def setTimeSeries(self, timeSeries):
assert isinstance(timeSeries, TimeSeries)
self.TS = timeSeries
self.TS.sigSensorAdded.connect(self.addSensor)
self.TS.sigSensorRemoved.connect(self.removeSensor)
def __init__(self, parent=None):
super(MapViewCollectionDock, self).__init__(parent)
self.setupUi(self)
self.mMapViews = MapViewListModel()
self.baseTitle = self.windowTitle()
self.btnAddMapView.setDefaultAction(self.actionAddMapView)
self.btnRemoveMapView.setDefaultAction(self.actionRemoveMapView)
self.btnRefresh.setDefaultAction(self.actionApplyStyles)
self.btnHighlightMapView.setDefaultAction(self.actionHighlightMapView)
self.btnCrs.crsChanged.connect(self.sigCrsChanged)
self.btnMapCanvasColor.colorChanged.connect(self.sigMapCanvasColorChanged)
self.btnApplySizeChanges.clicked.connect(lambda : self.sigMapSizeChanged.emit(QSize(self.spinBoxMapSizeX.value(),self.spinBoxMapSizeY.value())))
self.actionAddMapView.triggered.connect(self.createMapView)
self.actionRemoveMapView.triggered.connect(lambda : self.removeMapView(self.currentMapView()) if self.currentMapView() else None)
self.actionHighlightMapView.triggered.connect(lambda : self.currentMapView().setHighlighted(True) if self.currentMapView() else None)
self.actionApplyStyles.triggered.connect(self.refreshCurrentMapView)
#self.actionApplyStyles.triggered.connect(self.dummySlot)
self.mMapViews.sigMapViewsRemoved.connect(self.onMapViewsRemoved)
self.mMapViews.sigMapViewsAdded.connect(self.onMapViewsAdded)
self.mMapViews.sigMapViewsAdded.connect(self.updateButtons)
self.mMapViews.sigMapViewsRemoved.connect(self.updateButtons)
self.cbMapView.setModel(self.mMapViews)
self.cbMapView.currentIndexChanged[int].connect(lambda i : None if i < 0 else self.setCurrentMapView(self.mMapViews.idx2MapView(i)) )
self.spinBoxMapSizeX.valueChanged.connect(lambda: self.onMapSizeChanged('X'))
self.spinBoxMapSizeY.valueChanged.connect(lambda: self.onMapSizeChanged('Y'))
self.mLastMapSize = self.mapSize()
#self.mapSize() #inits mLastMapSize
self.TS = None
def setCrs(self, crs):
if isinstance(crs, QgsCoordinateReferenceSystem):
old = self.btnCrs.crs()
if old != crs:
self.btnCrs.setCrs(crs)
self.btnCrs.setLayerCrs(crs)
def setMapSize(self, size):
assert isinstance(size, QSize)
ws = [self.spinBoxMapSizeX, self.spinBoxMapSizeY]
oldSize = self.mapSize()
b = oldSize != size
for w in ws:
w.blockSignals(True)
self.spinBoxMapSizeX.setValue(size.width()),
self.spinBoxMapSizeY.setValue(size.height())
self.mLastMapSize = QSize(size)
for w in ws:
w.blockSignals(False)
self.mLastMapSize = QSize(size)
if b:
self.sigMapSizeChanged.emit(size)
def onMapSizeChanged(self, dim):
newSize = self.mapSize()
#1. set size of other dimension accordingly
if dim is not None:
if self.checkBoxKeepSubsetAspectRatio.isChecked():
if dim == 'X':
vOld = self.mLastMapSize.width()
vNew = newSize.width()
targetSpinBox = self.spinBoxMapSizeY
elif dim == 'Y':
vOld = self.mLastMapSize.height()
vNew = newSize.height()
targetSpinBox = self.spinBoxMapSizeX
oldState = targetSpinBox.blockSignals(True)
targetSpinBox.setValue(int(round(float(vNew) / vOld * targetSpinBox.value())))
targetSpinBox.blockSignals(oldState)
newSize = self.mapSize()
if newSize != self.mLastMapSize:
self.btnApplySizeChanges.setEnabled(True)
else:
self.sigMapSizeChanged.emit(self.mapSize())
self.btnApplySizeChanges.setEnabled(False)
self.setMapSize(newSize)
def mapSize(self):
return QSize(self.spinBoxMapSizeX.value(),
self.spinBoxMapSizeY.value())
def refreshCurrentMapView(self, *args):
mv = self.currentMapView()
if isinstance(mv, MapView):
mv.refreshMapView()
else:
s =""
def dummySlot(self):
s =""
def onMapViewsRemoved(self, mapViews):
for mapView in mapViews:
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.removeWidget(mapView.ui)
mapView.ui.close()
else:
s = ""
self.actionRemoveMapView.setEnabled(len(self.mMapViews) > 0)
def onMapViewsAdded(self, mapViews):
nextShown = None
for mapView in mapViews:
mapView.sigTitleChanged.connect(self.updateTitle)
self.stackedWidget.addWidget(mapView.ui)
if nextShown is None:
nextShown = mapView
contents = mapView.ui.scrollAreaWidgetContents
size = contents.size()
hint = contents.sizeHint()
#mapView.ui.scrollArea.update()
s = ""
#setMinimumSize(mapView.ui.scrollAreaWidgetContents.sizeHint())
#hint = contents.sizeHint()
#contents.setMinimumSize(hint)
if isinstance(nextShown, MapView):
self.setCurrentMapView(nextShown)
for mapView in mapViews:
self.sigMapViewAdded.emit(mapView)
def updateButtons(self, *args):
b = len(self.mMapViews) > 0
self.actionRemoveMapView.setEnabled(b)
self.actionApplyStyles.setEnabled(b)
self.actionHighlightMapView.setEnabled(b)
def createMapView(self):
mapView = MapView(self)
n = len(self.mMapViews) + 1
title = 'Map View {}'.format(n)
while title in [m.title() for m in self.mMapViews]:
n += 1
title = 'Map View {}'.format(n)
mapView.setTitle(title)
mapView.sigShowProfiles.connect(self.sigShowProfiles)
self.mMapViews.addMapView(mapView)
#self.sigMapViewAdded.emit(mapView)
return mapView
def removeMapView(self, mapView):
if isinstance(mapView, MapView):
assert mapView in self.mMapViews
i = self.mMapViews.mapView2idx(mapView)
if not i == self.stackedWidget.indexOf(mapView.ui):
s = ""
self.mMapViews.removeMapView(mapView)
mapView.ui.close()
self.sigMapViewRemoved.emit(mapView)
def __len__(self):
return len(self.mMapViews)
def __iter__(self):
return iter(self.mMapViews)
def __getitem__(self, slice):
return self.mMapViews[slice]
def __contains__(self, mapView):
return mapView in self.mMapViews
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mMapViews.index(mapView)
def setVectorLayer(self, lyr):
for mapView in self.mMapViews:
assert isinstance(mapView, MapView)
mapView.setVectorLayer(lyr)
def addSensor(self, sensor):
for mapView in self.mMapViews:
mapView.addSensor(sensor)
def removeSensor(self, sensor):
for mapView in self.mMapViews:
mapView.removeSensor(sensor)
def applyStyles(self):
for mapView in self.mMapViews:
mapView.applyStyles()
def setCrosshairStyle(self, crosshairStyle):
for mapView in self.mMapViews:
mapView.setCrosshairStyle(crosshairStyle)
def setShowCrosshair(self, b):
for mapView in self.mMapViews:
mapView.setCrosshairVisibility(b)
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViewsDefinitions.index(mapView)
def setCurrentMapView(self, mapView):
assert isinstance(mapView, MapView) and mapView in self.mMapViews
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.setCurrentIndex(idx)
self.cbMapView.setCurrentIndex(self.mMapViews.mapView2idx(mapView).row())
self.updateTitle()
def updateTitle(self, *args):
# self.btnToggleMapViewVisibility.setChecked(mapView)
mapView = self.currentMapView()
if isinstance(mapView, MapView):
if mapView in self.mMapViews:
i = str(self.mMapViews.mapView2idx(mapView).row()+1)
else:
i = ''
#title = '{} | {} "{}"'.format(self.baseTitle, i, mapView.title())
title = '{} | {}'.format(self.baseTitle, i)
self.setWindowTitle(title)
def currentMapView(self):
if len(self.mMapViews) == 0:
return None
else:
i = self.cbMapView.currentIndex()
if i >= 0:
return self.mMapViews.idx2MapView(i)
else:
return None
class MapViewCollectionDockV2(QgsDockWidget, loadUI('mapviewdockV2.ui')):
sigMapViewAdded = pyqtSignal(MapView)
sigMapViewRemoved = pyqtSignal(MapView)
sigShowProfiles = pyqtSignal(SpatialPoint, MapCanvas, str)
sigMapCanvasColorChanged = pyqtSignal(QColor)
sigSpatialExtentChanged = pyqtSignal(SpatialExtent)
sigCrsChanged = pyqtSignal(QgsCoordinateReferenceSystem)
sigMapSizeChanged = pyqtSignal(QSize)

Benjamin Jakimow
committed
def setTimeSeries(self, timeSeries):
assert isinstance(timeSeries, TimeSeries)
self.TS = timeSeries
self.TS.sigSensorAdded.connect(self.addSensor)
self.TS.sigSensorRemoved.connect(self.removeSensor)
self.mMapViews = MapViewListModel()
self.btnAddMapView.setDefaultAction(self.actionAddMapView)
self.btnRemoveMapView.setDefaultAction(self.actionRemoveMapView)
self.btnRefresh.setDefaultAction(self.actionApplyStyles)

benjamin.jakimow@geo.hu-berlin.de
committed
self.btnHighlightMapView.setDefaultAction(self.actionHighlightMapView)

Benjamin Jakimow
committed
self.btnCrs.crsChanged.connect(self.sigCrsChanged)
self.btnMapCanvasColor.colorChanged.connect(self.sigMapCanvasColorChanged)
self.btnApplySizeChanges.clicked.connect(lambda : self.sigMapSizeChanged.emit(QSize(self.spinBoxMapSizeX.value(),self.spinBoxMapSizeY.value())))
self.actionAddMapView.triggered.connect(self.createMapView)
self.actionRemoveMapView.triggered.connect(lambda : self.removeMapView(self.currentMapView()) if self.currentMapView() else None)
self.actionHighlightMapView.triggered.connect(lambda : self.currentMapView().setHighlighted(True) if self.currentMapView() else None)
self.actionApplyStyles.triggered.connect(self.refreshCurrentMapView)
#self.actionApplyStyles.triggered.connect(self.dummySlot)
self.mMapViews.sigMapViewsRemoved.connect(self.onMapViewsRemoved)
self.mMapViews.sigMapViewsAdded.connect(self.onMapViewsAdded)
self.mMapViews.sigMapViewsAdded.connect(self.updateButtons)
self.mMapViews.sigMapViewsRemoved.connect(self.updateButtons)
self.cbMapView.currentIndexChanged[int].connect(lambda i : None if i < 0 else self.setCurrentMapView(self.mMapViews.idx2MapView(i)) )

Benjamin Jakimow
committed
self.spinBoxMapSizeX.valueChanged.connect(lambda: self.onMapSizeChanged('X'))
self.spinBoxMapSizeY.valueChanged.connect(lambda: self.onMapSizeChanged('Y'))
self.mLastMapSize = self.mapSize()
#self.mapSize() #inits mLastMapSize

Benjamin Jakimow
committed
def setCrs(self, crs):
if isinstance(crs, QgsCoordinateReferenceSystem):
old = self.btnCrs.crs()
if old != crs:
self.btnCrs.setCrs(crs)
self.btnCrs.setLayerCrs(crs)

Benjamin Jakimow
committed
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
def setMapSize(self, size):
assert isinstance(size, QSize)
ws = [self.spinBoxMapSizeX, self.spinBoxMapSizeY]
oldSize = self.mapSize()
b = oldSize != size
for w in ws:
w.blockSignals(True)
self.spinBoxMapSizeX.setValue(size.width()),
self.spinBoxMapSizeY.setValue(size.height())
self.mLastMapSize = QSize(size)
for w in ws:
w.blockSignals(False)
self.mLastMapSize = QSize(size)
if b:
self.sigMapSizeChanged.emit(size)
def onMapSizeChanged(self, dim):
newSize = self.mapSize()
#1. set size of other dimension accordingly
if dim is not None:
if self.checkBoxKeepSubsetAspectRatio.isChecked():
if dim == 'X':
vOld = self.mLastMapSize.width()
vNew = newSize.width()
targetSpinBox = self.spinBoxMapSizeY
elif dim == 'Y':
vOld = self.mLastMapSize.height()
vNew = newSize.height()
targetSpinBox = self.spinBoxMapSizeX
oldState = targetSpinBox.blockSignals(True)
targetSpinBox.setValue(int(round(float(vNew) / vOld * targetSpinBox.value())))
targetSpinBox.blockSignals(oldState)
newSize = self.mapSize()
if newSize != self.mLastMapSize:
self.btnApplySizeChanges.setEnabled(True)
else:
self.sigMapSizeChanged.emit(self.mapSize())
self.btnApplySizeChanges.setEnabled(False)
self.setMapSize(newSize)
def mapSize(self):
return QSize(self.spinBoxMapSizeX.value(),
self.spinBoxMapSizeY.value())
def refreshCurrentMapView(self, *args):
mv = self.currentMapView()
if isinstance(mv, MapView):
mv.refreshMapView()
else:
s =""
def dummySlot(self):
s =""
for mapView in mapViews:
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.removeWidget(mapView.ui)
mapView.ui.close()
else:
s = ""
self.actionRemoveMapView.setEnabled(len(self.mMapViews) > 0)
def onMapViewsAdded(self, mapViews):
nextShown = None
for mapView in mapViews:
mapView.sigTitleChanged.connect(self.updateTitle)
self.stackedWidget.addWidget(mapView.ui)
if nextShown is None:
nextShown = mapView
contents = mapView.ui.scrollAreaWidgetContents
size = contents.size()
hint = contents.sizeHint()
#mapView.ui.scrollArea.update()
s = ""
#setMinimumSize(mapView.ui.scrollAreaWidgetContents.sizeHint())
#hint = contents.sizeHint()
#contents.setMinimumSize(hint)
if isinstance(nextShown, MapView):
self.setCurrentMapView(nextShown)

Benjamin Jakimow
committed
for mapView in mapViews:
self.sigMapViewAdded.emit(mapView)
def updateButtons(self, *args):
b = len(self.mMapViews) > 0
self.actionRemoveMapView.setEnabled(b)
self.actionApplyStyles.setEnabled(b)
self.actionHighlightMapView.setEnabled(b)
n = len(self.mMapViews) + 1
title = 'Map View {}'.format(n)
while title in [m.title() for m in self.mMapViews]:
n += 1
title = 'Map View {}'.format(n)
mapView.setTitle(title)
mapView.sigShowProfiles.connect(self.sigShowProfiles)

Benjamin Jakimow
committed
#self.sigMapViewAdded.emit(mapView)
if isinstance(mapView, MapView):
assert mapView in self.mMapViews
i = self.mMapViews.mapView2idx(mapView)
if not i == self.stackedWidget.indexOf(mapView.ui):
s = ""
self.mMapViews.removeMapView(mapView)
self.sigMapViewRemoved.emit(mapView)
def __getitem__(self, slice):
return self.mMapViews[slice]
def __contains__(self, mapView):
return mapView in self.mMapViews
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mMapViews.index(mapView)
def setVectorLayer(self, lyr):
for mapView in self.mMapViews:
assert isinstance(mapView, MapView)
mapView.setVectorLayer(lyr)
def addSensor(self, sensor):
for mapView in self.mMapViews:
mapView.addSensor(sensor)
def removeSensor(self, sensor):
for mapView in self.mMapViews:
mapView.removeSensor(sensor)
def applyStyles(self):
for mapView in self.mMapViews:
mapView.applyStyles()
def setCrosshairStyle(self, crosshairStyle):
for mapView in self.mMapViews:
mapView.setCrosshairStyle(crosshairStyle)
def setShowCrosshair(self, b):
for mapView in self.mMapViews:

Benjamin Jakimow
committed
mapView.setCrosshairVisibility(b)
def index(self, mapView):
assert isinstance(mapView, MapView)
return self.mapViewsDefinitions.index(mapView)
def setCurrentMapView(self, mapView):
assert isinstance(mapView, MapView) and mapView in self.mMapViews
idx = self.stackedWidget.indexOf(mapView.ui)
if idx >= 0:
self.stackedWidget.setCurrentIndex(idx)
self.cbMapView.setCurrentIndex(self.mMapViews.mapView2idx(mapView).row())
self.updateTitle()
def updateTitle(self, *args):
# self.btnToggleMapViewVisibility.setChecked(mapView)
mapView = self.currentMapView()
if isinstance(mapView, MapView):
if mapView in self.mMapViews:
i = str(self.mMapViews.mapView2idx(mapView).row()+1)
else:
i = ''
#title = '{} | {} "{}"'.format(self.baseTitle, i, mapView.title())
title = '{} | {}'.format(self.baseTitle, i)
self.setWindowTitle(title)
if len(self.mMapViews) == 0:
return None
else:
i = self.cbMapView.currentIndex()
if i >= 0:
return self.mMapViews.idx2MapView(i)
else:
return None