-
Notifications
You must be signed in to change notification settings - Fork 0
/
pinModel.py
81 lines (60 loc) · 2.13 KB
/
pinModel.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
71
72
73
74
75
76
77
78
79
80
81
import sys
import re
import untangle
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtQml import *
from PyQt5.QtQuickWidgets import *
from PyQt5.QtPositioning import *
from PyQt5.QtGui import *
class MarkerItem():
def __init__(self, position, title):
self._position = position
self._title = title
def position(self):
return self._position
def setPosition(self, value):
self._position = value
def title(self):
return self._title
def setTitle(self, value):
self._title = value
class MarkerModel(QAbstractListModel):
PositionRole = Qt.UserRole
TitleRole = Qt.UserRole + 1
_roles = {PositionRole: QByteArray(
b"markerPosition"), TitleRole: QByteArray(b"markerTitle")}
def __init__(self, parent=None):
QAbstractListModel.__init__(self, parent)
self._markers = []
def rowCount(self, index=QModelIndex()):
return len(self._markers)
def roleNames(self):
return self._roles
def data(self, index, role=Qt.DisplayRole):
if index.row() >= self.rowCount():
return QVariant()
marker = self._markers[index.row()]
if role == MarkerModel.PositionRole:
return marker.position()
elif role == MarkerModel.TitleRole:
return marker.title()
return QVariant()
def setData(self, index, value, role=Qt.EditRole):
if index.isValid():
marker = self._markers[index.row()]
if role == MarkerModel.PositionRole:
marker.setPosition(value)
if role == MarkerModel.TitleRole:
marker.setTitle(value)
self.dataChanged.emit(index, index)
return True
return QAbstractListModel.setData(self, index, value, role)
def addMarker(self, marker):
self.beginInsertRows(QModelIndex(), self.rowCount(), self.rowCount())
self._markers.append(marker)
self.endInsertRows()
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
return QAbstractListModel.flags(index) | Qt.ItemIsEditable