-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkItemTableModel.py
85 lines (74 loc) · 3.69 KB
/
WorkItemTableModel.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
82
83
84
85
from PyQt5.QtCore import QAbstractTableModel, QModelIndex, Qt, QVariant
from PyQt5.QtGui import QFont
from DataModel import DataModel
from Preferences import Preferences
from WorkItem import WorkItem
class WorkItemTableModel(QAbstractTableModel):
NUMBER_OF_COLUMNS = 4
HEADINGS: [str] = ("#", "Filter", "Bin", "Done")
FRAMES_ITEM_INDEX = 0
FILTER_ITEM_INDEX = 1
BINNING_ITEM_INDEX = 2
COMPLETED_ITEM_INDEX = 3
def __init__(self, data_model: DataModel, preferences: Preferences, work_items: [WorkItem]):
QAbstractTableModel.__init__(self)
self._work_items = work_items
self._data_model = data_model
self._preferences = preferences
# Methods required by the parent abstract data model
# noinspection PyMethodOverriding
def rowCount(self, parent_model_index: QModelIndex) -> int:
return len(self._work_items)
# noinspection PyMethodOverriding
def columnCount(self, parent_model_index: QModelIndex) -> int:
return WorkItemTableModel.NUMBER_OF_COLUMNS
# Get data element to display in a table cell
# noinspection PyMethodOverriding
def data(self, index: QModelIndex, role: Qt.DisplayRole):
row_index: int = index.row()
column_index: int = index.column()
if role == Qt.DisplayRole:
assert (row_index >= 0) and (row_index < len(self._work_items))
work_item: WorkItem = self._work_items[row_index]
if column_index == WorkItemTableModel.FRAMES_ITEM_INDEX:
return str(work_item.get_number_of_frames())
elif column_index == WorkItemTableModel.FILTER_ITEM_INDEX:
return work_item.hybrid_filter_name() if self._data_model.get_use_filter_wheel() else "No filter"
elif column_index == WorkItemTableModel.BINNING_ITEM_INDEX:
return f"{work_item.get_binning()} x {work_item.get_binning()}"
else:
assert column_index == WorkItemTableModel.COMPLETED_ITEM_INDEX
return str(work_item.get_num_completed())
elif role == Qt.FontRole:
# Font information for the headers above the top row
standard_font_size = self._preferences.get_standard_font_size()
font = QFont()
font.setPointSize(standard_font_size)
result = font
else:
result = QVariant()
return result
# noinspection PyMethodOverriding
def headerData(self, item_number, orientation, role):
result = QVariant()
if (role == Qt.DisplayRole) and (orientation == Qt.Horizontal):
assert (item_number >= 0) and (item_number < len(WorkItemTableModel.HEADINGS))
result = WorkItemTableModel.HEADINGS[item_number]
elif (role == Qt.FontRole) and (orientation == Qt.Horizontal):
# Font information for the headers above the top row
standard_font_size = self._preferences.get_standard_font_size()
font = QFont()
font.setPointSize(standard_font_size)
font.setBold(True)
result = font
return result
# self._work_items_table_model.set_frames_complete(row_index, frames_complete)
# A frame has been taken. Update the work item displayed in the given row index
# with the new # complete
def set_frames_complete(self, row_index: int, frames_complete: int):
work_item: WorkItem = self._work_items[row_index]
work_item.set_num_completed(frames_complete)
# Ask this cell to redraw
top_left: QModelIndex = self.index(row_index, self.COMPLETED_ITEM_INDEX)
bottom_right: QModelIndex = self.index(row_index, self.COMPLETED_ITEM_INDEX)
self.dataChanged.emit(top_left, bottom_right)