Newer
Older
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
from qgis.gui import *
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
from timeseriesviewer.utils import *
class MapViewGridLayout(QGridLayout):
def __init__(self):
pass
class GridWidgetModel(QAbstractTableModel):
def __init__(self):
super(GridWidgetModel, self).__init__()
def columnNames(self)->list:
"""
Returns the column names
:return: [list-of-str]
"""
return [self.mColLabel, self.mColName, self.mColColor]
def rowCount(self, parent:QModelIndex=None):
"""
Returns the number of row / ClassInfos
:param parent: QModelIndex
:return: int
"""
return len(self.mClasses)
def columnCount(self, parent: QModelIndex=None):
return len(self.columnNames())
def index2ClassInfo(self, index)->ClassInfo:
if isinstance(index, QModelIndex):
index = index.row()
return self.mClasses[index]
def classInfo2index(self, classInfo:ClassInfo)->QModelIndex:
row = self.mClasses.index(classInfo)
return self.createIndex(row, 0)
def data(self, index: QModelIndex, role: int = Qt.DisplayRole):
if not index.isValid():
return None
value = None
col = index.column()
row = index.row()
classInfo = self.index2ClassInfo(row)
if role == Qt.DisplayRole:
if col == 0:
return classInfo.label()
if col == 1:
return classInfo.name()
if col == 2:
return classInfo.color().name()
if role == Qt.ForegroundRole:
if col == self.mColColor:
return QBrush(getTextColorWithContrast(classInfo.color()))
if role == Qt.BackgroundColorRole:
if col == 2:
return QBrush(classInfo.color())
if role == Qt.AccessibleTextRole:
if col == 0:
return str(classInfo.label())
if col == 1:
return classInfo.name()
if col == 2:
return classInfo.color().name()
if role == Qt.ToolTipRole:
if col == 0:
return 'Class label "{}"'.format(classInfo.label())
if col == 1:
return 'Class name "{}"'.format(classInfo.name())
if col == 2:
return 'Class color "{}"'.format(classInfo.color().name())
if role == Qt.EditRole:
if col == 1:
return classInfo.name()
if col == 2:
return classInfo.color()
if role == Qt.UserRole:
return classInfo
return None
if __name__ == '__main__':
app = initQgisApplication()
view = QTableView()
view.resize(QSize(300,200))
view.show()
app.exec_()