1 | from typing import List
|
---|
2 |
|
---|
3 | from PyQt5.QtCore import QAbstractTableModel, QModelIndex, QVariant
|
---|
4 | from PyQt5.QtCore import Qt
|
---|
5 |
|
---|
6 | from geniusweb.protocol.session.TeamInfo import TeamInfo
|
---|
7 | from geniusweb.references.PartyWithProfile import PartyWithProfile
|
---|
8 |
|
---|
9 |
|
---|
10 | class SelectionModel(QAbstractTableModel):
|
---|
11 | '''
|
---|
12 | The selected parties, profiles etc
|
---|
13 | '''
|
---|
14 |
|
---|
15 | colnames = ["Party", "Parameters", "Profile"]
|
---|
16 |
|
---|
17 | def __init__(self):
|
---|
18 | super().__init__()
|
---|
19 | self._teams:List[TeamInfo] = []
|
---|
20 | # pyqt does not use listeners
|
---|
21 |
|
---|
22 | def getTeams(self) -> List[TeamInfo]:
|
---|
23 | return self._teams
|
---|
24 |
|
---|
25 | def addTeam(self, team:TeamInfo):
|
---|
26 | self._teams.append(team)
|
---|
27 | self.beginResetModel()
|
---|
28 | self.endResetModel()
|
---|
29 |
|
---|
30 | # Override
|
---|
31 | def rowCount(self, parent=QModelIndex()):
|
---|
32 | return len(self._teams)
|
---|
33 |
|
---|
34 | # Override
|
---|
35 | def columnCount(self, parent=QModelIndex()):
|
---|
36 | return 3
|
---|
37 |
|
---|
38 | def data(self, index, role=None):
|
---|
39 | if role == Qt.ItemDataRole.DisplayRole:
|
---|
40 | party:PartyWithProfile = self._teams[index.row()].getParties()[0]
|
---|
41 | if index.column() == 0:
|
---|
42 | return str(party.getParty().getPartyRef().getURI())
|
---|
43 | if index.column() == 1:
|
---|
44 | return str(party.getParty().getParameters())
|
---|
45 | if index.column() == 2:
|
---|
46 | return str(party.getProfile().getURI())
|
---|
47 | return "???"
|
---|
48 | return None # without this you get checkboxes everywhere in table...
|
---|
49 |
|
---|
50 | def headerData(self, column:int, orientation, role=Qt.ItemDataRole.DisplayRole):
|
---|
51 | if role != Qt.ItemDataRole.DisplayRole:
|
---|
52 | return QVariant()
|
---|
53 | if orientation == Qt.Orientation.Horizontal:
|
---|
54 | return QVariant(self.colnames[column])
|
---|