Newer
Older
# -*- coding: utf-8 -*-
"""
/***************************************************************************

Benjamin Jakimow
committed
EO Time Series Viewer
-------------------
begin : 2015-08-20
git sha : $Format:%H$
copyright : (C) 2017 by HU-Berlin
email : benjamin.jakimow@geo.hu-berlin.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
# noinspection PyPep8Naming
from eotimeseriesviewer import CursorLocationMapTool
from qgis.core import *
from qgis.gui import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtXml import QDomDocument
from .timeseries import TimeSeriesDate, SensorProxyLayer, SensorInstrument
from .externals.qps.crosshair.crosshair import CrosshairDialog, CrosshairStyle, CrosshairMapCanvasItem
from .externals.qps.maptools import *
from .labeling import quickLabelLayers, labelShortcutLayerClassificationSchemes, setQuickTSDLabelsForRegisteredLayers
from .externals.qps.classification.classificationscheme import ClassificationScheme, ClassInfo
from .externals.qps.utils import *
from .externals.qps.layerproperties import showLayerPropertiesDialog
import eotimeseriesviewer.settings
PROGRESS_TIMER = QTimer()
PROGRESS_TIMER.start(100)
def toQgsMimeDataUtilsUri(mapLayer:QgsMapLayer):
uri = QgsMimeDataUtils.Uri()
uri.name = mapLayer.name()
uri.providerKey = mapLayer.dataProvider().name()
uri.uri = mapLayer.source()
if isinstance(mapLayer, QgsRasterLayer):
uri.layerType = 'raster'
elif isinstance(mapLayer, QgsVectorLayer):
uri.layerType = 'vector'
else:
raise NotImplementedError()
return uri
class MapLoadingInfoItem(QgsMapCanvasItem):
def __init__(self, mapCanvas):
assert isinstance(mapCanvas, QgsMapCanvas)
super(MapLoadingInfoItem, self).__init__(mapCanvas)
self.mCanvas = mapCanvas
self.mProgressConnection = None
self.mCanvas.renderStarting.connect(lambda: self.showLoadingProgress(True))
#self.mCanvas.renderComplete.connect(lambda: self.showLoadingProgress(False))
PROGRESS_TIMER.timeout.connect(self.onProgressTimeOut)
self.mShowProgress = False
self.mIsVisible = True
def showLoadingProgress(self, showProgress: bool):
self.mShowProgress = showProgress
self.update()
def onProgressTimeOut(self):
if self.mShowProgress:
self.mCanvas.update()
def paint(self, painter, QStyleOptionGraphicsItem=None, QWidget_widget=None):
"""
Paints the crosshair
:param painter:
:param QStyleOptionGraphicsItem:
:param QWidget_widget:
:return:
"""
if True:
options = QStyleOptionProgressBar()
options.rect = QRect(0, 0, painter.window().width(), 25)
options.textAlignment = Qt.AlignCenter
options.progress = 0
options.maximum = 0
options.minimum = 0
QApplication.style().drawControl(QStyle.CE_ProgressBar, options, painter)
class MapCanvasInfoItem(QgsMapCanvasItem):

Benjamin Jakimow
committed
"""
A QgsMapCanvasItem to show text
"""
def __init__(self, mapCanvas):
assert isinstance(mapCanvas, QgsMapCanvas)
super(MapCanvasInfoItem, self).__init__(mapCanvas)
self.mCanvas = mapCanvas

Benjamin Jakimow
committed
self.mText = dict()
self.mWrapChar = '\n'
self.mTextFormat = QgsTextFormat()
self.mTextFormat.setSizeUnit(QgsUnitTypes.RenderPixels)
self.mTextFormat.setFont(QFont('Helvetica', pointSize=10))
self.mTextFormat.setColor(QColor('yellow'))
def setWrapChar(self, c:str)->str:
"""
Sets a Wrap Character
:param c:
:return:
"""
self.mWrapChar = c
return self.wrapChar()

Benjamin Jakimow
committed
def wrapChar(self)->str:
return self.mWrapChar

Benjamin Jakimow
committed
def setText(self, text:str, alignment:Qt.Alignment=Qt.AlignTop | Qt.AlignHCenter):

Benjamin Jakimow
committed
self.mText[alignment] = text
def setTextFormat(self, format:QgsTextFormat):
assert isinstance(format, QgsTextFormat)
self.mTextFormat = format
self.updateCanvas()
def textFormat(self)->QgsTextFormat:
"""
Returns the text format.
:return: QgsTextFormat
"""
return self.mTextFormat
def font(self)->QFont:
"""
Returns the font used to write text on the map canvas.
:return: QFont
"""
return self.mTextFormat.font()
def setFont(self, font:QFont):
self.mTextFormat.setFont(font)
"""
Sets the map info color
:param color: QColor
"""

Benjamin Jakimow
committed
self.mTextFormat.setColor(color)
"""
Returns the info text color
:return: QColor
"""

Benjamin Jakimow
committed
return self.mTextFormat.color()

Benjamin Jakimow
committed
def paintText(self, painter, text:str, flags, rotation=0):
padding = 5
text = text.replace('\\n', '\n')
text = text.split(self.wrapChar())

Benjamin Jakimow
committed
nl = len(text)
#text = text.split('\\n')
r = QgsTextRenderer()

Benjamin Jakimow
committed
painter.setBrush(Qt.NoBrush)
painter.setPen(Qt.NoPen)
painter.setRenderHint(QPainter.Antialiasing)

Benjamin Jakimow
committed
context = QgsRenderContext()

Benjamin Jakimow
committed
# taken from QGIS Repo src/core/qgspallabeling.cpp
m2p = QgsMapToPixel(1, 0, 0, 0, 0, 0)
context.setMapToPixel(m2p)
context.setScaleFactor(QgsApplication.desktop().logicalDpiX() / 25.4)
context.setUseAdvancedEffects(True)
context.setPainter(painter)
#context.setExtent(self.mCanvas.extent())
#context.setExpressionContext(self.mCanvas.mapSettings().expressionContext())

Benjamin Jakimow
committed
vp = QRectF(painter.viewport())
#rect = self.mCanvas.extent().toRectF()
Loading
Loading full blame...