-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathroll_offset.py
50 lines (37 loc) · 1.67 KB
/
roll_offset.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
"""
This module provides the Roll Offset class
"""
from qgis.PyQt.QtCore import QPointF, QRectF
from qgis.PyQt.QtXml import QDomDocument, QDomNode
from .functions import toFloat
class RollOffset:
def __init__(self) -> None: # assign default values
self.rctOffsets = QRectF()
self.radOffsets = QPointF()
def writeXml(self, parent: QDomNode, doc: QDomDocument):
offsetElem = doc.createElement('offset')
offsetElem.setAttribute('xmin', str(self.rctOffsets.left()))
offsetElem.setAttribute('xmax', str(self.rctOffsets.right()))
offsetElem.setAttribute('ymin', str(self.rctOffsets.top()))
offsetElem.setAttribute('ymax', str(self.rctOffsets.bottom()))
offsetElem.setAttribute('rmin', str(self.radOffsets.x()))
offsetElem.setAttribute('rmax', str(self.radOffsets.y()))
parent.appendChild(offsetElem)
return offsetElem
def readXml(self, parent: QDomNode):
offsetElem = parent.namedItem('offset').toElement()
if offsetElem.isNull():
return False
xmin = toFloat(offsetElem.attribute('xmin'))
xmax = toFloat(offsetElem.attribute('xmax'))
self.rctOffsets.setLeft(min(xmin, xmax))
self.rctOffsets.setRight(max(xmin, xmax))
ymin = toFloat(offsetElem.attribute('ymin'))
ymax = toFloat(offsetElem.attribute('ymax'))
self.rctOffsets.setTop(min(ymin, ymax))
self.rctOffsets.setBottom(max(ymin, ymax))
rmin = toFloat(offsetElem.attribute('rmin'))
rmax = toFloat(offsetElem.attribute('rmax'))
self.radOffsets.setX(min(rmin, rmax))
self.radOffsets.setY(max(rmin, rmax))
return True