-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmapItem.py
70 lines (62 loc) · 1.93 KB
/
mapItem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
# @Author : llc
# @Time : 2020/3/10 14:59
from qgis.PyQt.QtCore import QRectF, Qt, QLineF
from qgis.PyQt.QtGui import QPen, QColor
from qgis.gui import QgsMapCanvasItem
class SwipeMapItem(QgsMapCanvasItem):
def __init__(self, mapCanvas):
super(SwipeMapItem, self).__init__(mapCanvas)
self.image = None
self.line = None
self.startPaint = False
self.direction = -1
self.x = 0
self.y = 0
self.w = 0
self.h = 0
def updateImageRect(self, x, y):
w = self.boundingRect().width()
h = self.boundingRect().height()
if self.direction == -1: # all
self.x = 0
self.y = 0
self.w = w
self.h = h
elif self.direction == 0: # 0:'⬇'
self.x = 0
self.y = 0
self.w = w
self.h = y
self.line = QLineF(0, y, w, y)
elif self.direction == 1: # 1:'⬆'
self.x = 0
self.y = y
self.w = w
self.h = h - y
self.line = QLineF(0, y, w, y)
elif self.direction == 2: # 2:'➡'
self.x = 0
self.y = 0
self.w = x
self.h = h
self.line = QLineF(x, 0, x, h)
else: # 3:'⬅'
self.x = x
self.y = 0
self.w = w - x
self.h = h
self.line = QLineF(x, 0, x, h)
self.startPaint = True
self.update()
def paint(self, painter, *args):
if self.startPaint is False:
return
pen = QPen(Qt.DashDotDotLine)
pen.setColor(QColor(18, 150, 219))
pen.setWidth(4)
painter.setPen(pen)
if self.line:
painter.drawLine(self.line)
image = self.image.copy(int(self.x), int(self.y), int(self.w), int(self.h))
painter.drawImage(QRectF(self.x, self.y, self.w, self.h), image)