Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Jakimow
EO Time Series Viewer
Commits
e2dc8231
Commit
e2dc8231
authored
Nov 06, 2020
by
Benjamin Jakimow
Browse files
fixed quikc labeling for QGIS 3.16+
Signed-off-by:
Benjamin Jakimow
<
benjamin.jakimow@geo.hu-berlin.de
>
parent
d497b327
Pipeline
#13822
failed
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
eotimeseriesviewer/labeling.py
View file @
e2dc8231
import
typing
import
enum
import
numpy
as
np
import
math
from
qgis.core
import
QgsMapLayer
,
QgsRasterLayer
,
QgsVectorLayer
,
QgsField
,
QgsFields
,
\
QgsEditorWidgetSetup
,
QgsFeature
,
QgsVectorLayerTools
,
QgsFieldModel
,
\
QgsRendererCategory
,
QgsCategorizedSymbolRenderer
,
QgsProject
,
QgsMapLayerStore
,
QgsSymbol
...
...
@@ -313,6 +314,8 @@ def setQuickTSDLabels(vectorLayer: QgsVectorLayer,
value
=
QDate
(
year
,
1
,
1
)
elif
fieldType
==
QVariant
.
DateTime
:
value
=
QDateTime
(
2000
,
1
,
1
,
0
,
0
)
elif
fieldType
==
QVariant
.
Int
:
value
=
year
elif
labelType
==
LabelShortcutType
.
DecimalYear
:
value
=
tsd
.
decimalYear
()
...
...
@@ -901,6 +904,10 @@ class LabelShortcutEditorWidgetWrapper(QgsEditorWidgetWrapper):
elif
typeCode
==
QVariant
.
String
:
return
str
(
editor
.
dateTime
())
elif
isinstance
(
editor
,
(
QgsSpinBox
,
QgsDoubleSpinBox
)):
return
editor
.
value
()
else
:
s
=
""
return
self
.
defaultValue
()
def
setEnabled
(
self
,
enabled
:
bool
):
...
...
@@ -938,6 +945,10 @@ class LabelShortcutEditorWidgetWrapper(QgsEditorWidgetWrapper):
elif
isinstance
(
w
,
QgsDateTimeEdit
):
w
.
setDateTime
(
QDateTime
(
value
))
elif
isinstance
(
w
,
(
QgsSpinBox
,
QgsDoubleSpinBox
)):
if
w
.
maximum
()
<=
value
:
e
=
int
(
math
.
log10
(
value
))
+
1
w
.
setMaximum
(
int
(
10
**
e
))
w
.
setClearValue
(
value
)
w
.
setValue
(
value
)
elif
isinstance
(
w
,
QLineEdit
):
w
.
setText
(
str
(
value
))
...
...
eotimeseriesviewer/mapcanvas.py
View file @
e2dc8231
...
...
@@ -498,25 +498,6 @@ class MapCanvas(QgsMapCanvas):
"""
return
self
.
mRenderingFinished
def
mousePressEvent
(
self
,
event
:
QMouseEvent
):
self
.
setProperty
(
KEY_LAST_CLICKED
,
time
.
time
())
b
=
event
.
button
()
==
Qt
.
LeftButton
if
b
and
isinstance
(
self
.
mapTool
(),
QgsMapTool
):
b
=
isinstance
(
self
.
mapTool
(),
(
QgsMapToolIdentify
,
CursorLocationMapTool
,
SpectralProfileMapTool
,
TemporalProfileMapTool
))
super
(
MapCanvas
,
self
).
mousePressEvent
(
event
)
if
b
:
ms
=
self
.
mapSettings
()
pointXY
=
ms
.
mapToPixel
().
toMapCoordinates
(
event
.
x
(),
event
.
y
())
spatialPoint
=
SpatialPoint
(
ms
.
destinationCrs
(),
pointXY
)
self
.
setCrosshairPosition
(
spatialPoint
)
self
.
sigCanvasClicked
.
emit
(
event
)
def
setMapView
(
self
,
mapView
):
"""
Sets the map canvas MapView
...
...
@@ -1255,12 +1236,25 @@ class MapCanvas(QgsMapCanvas):
proxyLayer
.
setRenderer
(
r
)
def
mousePressEvent
(
self
,
event
:
QMouseEvent
):
self
.
setProperty
(
KEY_LAST_CLICKED
,
time
.
time
())
bLeft
:
bool
=
event
.
button
()
==
Qt
.
LeftButton
bRight
:
bool
=
event
.
button
()
==
Qt
.
RightButton
modifiers
=
QApplication
.
keyboardModifiers
()
mt
:
QgsMapTool
=
self
.
mapTool
()
if
Qgis
.
QGIS_VERSION
>=
'3.16'
:
super
(
MapCanvas
,
self
).
mousePressEvent
(
event
)
if
bRight
and
\
isinstance
(
mt
,
(
QgsMapToolAddFeature
,
))
\
and
not
bool
(
mt
.
flags
()
&
QgsMapTool
.
ShowContextMenu
)
\
and
bool
(
modifiers
&
Qt
.
ControlModifier
):
menu
=
QMenu
()
# mt.populateContextMenu(menu)
self
.
populateContextMenu
(
menu
,
event
.
pos
())
menu
.
exec_
(
event
.
globalPos
())
else
:
if
event
.
button
()
==
Qt
.
RightButton
:
mt
:
QgsMapTool
=
self
.
mapTool
()
if
isinstance
(
mt
,
QgsMapTool
):
if
bool
(
mt
.
flags
()
&
QgsMapTool
.
ShowContextMenu
):
...
...
@@ -1271,6 +1265,13 @@ class MapCanvas(QgsMapCanvas):
return
super
().
mousePressEvent
(
event
)
if
bLeft
and
not
isinstance
(
mt
,
(
QgsMapToolAddFeature
,
)):
ms
=
self
.
mapSettings
()
pointXY
=
ms
.
mapToPixel
().
toMapCoordinates
(
event
.
x
(),
event
.
y
())
spatialPoint
=
SpatialPoint
(
ms
.
destinationCrs
(),
pointXY
)
self
.
setCrosshairPosition
(
spatialPoint
)
self
.
sigCanvasClicked
.
emit
(
event
)
def
addLayers2QGIS
(
self
,
mapLayers
):
import
qgis.utils
iface
=
qgis
.
utils
.
iface
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment