5 |
5 |
6 """ |
6 """ |
7 Module implementing the time tracker edit dialog. |
7 Module implementing the time tracker edit dialog. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt5.QtCore import pyqtSlot, QDateTime, QDate |
10 from PyQt6.QtCore import pyqtSlot, QDateTime, QDate |
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
12 |
12 |
13 from .Ui_TimeTrackerEntryDialog import Ui_TimeTrackerEntryDialog |
13 from .Ui_TimeTrackerEntryDialog import Ui_TimeTrackerEntryDialog |
14 |
14 |
15 |
15 |
16 class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog): |
16 class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog): |
19 """ |
19 """ |
20 def __init__(self, tracker, entry, taskItems, commentItems, parent=None): |
20 def __init__(self, tracker, entry, taskItems, commentItems, parent=None): |
21 """ |
21 """ |
22 Constructor |
22 Constructor |
23 |
23 |
24 @param tracker reference to the time tracker (TimeTracker) |
24 @param tracker reference to the time tracker |
25 @param entry reference to the time tracker entry (TimeTrackEntry) |
25 @type TimeTracker |
|
26 @param entry reference to the time tracker entry |
|
27 @type TimeTrackEntry |
26 @param taskItems list of task item entries for the |
28 @param taskItems list of task item entries for the |
27 task combo box (list of strings) |
29 task combo box |
|
30 @type list of str |
28 @param commentItems list of comment item entries for the |
31 @param commentItems list of comment item entries for the |
29 comment combo box (list of strings) |
32 comment combo box |
30 @param parent reference to the parent widget (QWidget) |
33 @type list of str |
|
34 @param parent reference to the parent widget |
|
35 @type QWidget |
31 """ |
36 """ |
32 super().__init__(parent) |
37 super().__init__(parent) |
33 self.setupUi(self) |
38 self.setupUi(self) |
34 |
39 |
35 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
40 self.buttonBox.button( |
|
41 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
36 |
42 |
37 self.taskCombo.addItems(taskItems) |
43 self.taskCombo.addItems(taskItems) |
38 self.commentCombo.addItems(commentItems) |
44 self.commentCombo.addItems(commentItems) |
39 |
45 |
40 # The allowed end time (i.e. start date and time plus duration must be |
46 # The allowed end time (i.e. start date and time plus duration must be |
49 self.setWindowTitle(self.tr("Add Tracker Entry")) |
55 self.setWindowTitle(self.tr("Add Tracker Entry")) |
50 self.startDateTimeEdit.setDate(QDate.currentDate()) |
56 self.startDateTimeEdit.setDate(QDate.currentDate()) |
51 else: |
57 else: |
52 self.startDateTimeEdit.setDateTime(entry.getStartDateTime()) |
58 self.startDateTimeEdit.setDateTime(entry.getStartDateTime()) |
53 self.durationSpinBox.setValue(entry.getDuration()) |
59 self.durationSpinBox.setValue(entry.getDuration()) |
|
60 self.durationSpinBox.setMaximum( |
|
61 entry.getStartDateTime().secsTo(self.__endDateTime) // 60) |
54 self.taskCombo.setEditText(entry.getTask()) |
62 self.taskCombo.setEditText(entry.getTask()) |
55 self.commentCombo.setEditText(entry.getComment()) |
63 self.commentCombo.setEditText(entry.getComment()) |
56 |
64 |
57 msh = self.minimumSizeHint() |
65 msh = self.minimumSizeHint() |
58 self.resize(max(self.width(), msh.width()), msh.height()) |
66 self.resize(max(self.width(), msh.width()), msh.height()) |
60 def __checkOk(self): |
68 def __checkOk(self): |
61 """ |
69 """ |
62 Private slot to set the enabled state of the OK button. |
70 Private slot to set the enabled state of the OK button. |
63 """ |
71 """ |
64 dt = self.startDateTimeEdit.dateTime() |
72 dt = self.startDateTimeEdit.dateTime() |
65 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
73 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
66 dt.addSecs(self.durationSpinBox.value() * 60) <= |
74 dt.addSecs(self.durationSpinBox.value() * 60) <= |
67 self.__endDateTime) |
75 self.__endDateTime) |
68 |
76 |
69 @pyqtSlot(QDateTime) |
77 @pyqtSlot(QDateTime) |
70 def on_startDateTimeEdit_dateTimeChanged(self, date): |
78 def on_startDateTimeEdit_dateTimeChanged(self, date): |
71 """ |
79 """ |
72 Private slot handling a change of the start date and time. |
80 Private slot handling a change of the start date and time. |
73 |
81 |
74 @param date start date and time (QDateTime) |
82 @param date start date and time |
|
83 @type QDateTime |
75 """ |
84 """ |
76 self.__checkOk() |
85 self.__checkOk() |
77 |
86 |
78 @pyqtSlot(int) |
87 @pyqtSlot(int) |
79 def on_durationSpinBox_valueChanged(self, value): |
88 def on_durationSpinBox_valueChanged(self, value): |
80 """ |
89 """ |
81 Private slot handling a change of the duration. |
90 Private slot handling a change of the duration. |
82 |
91 |
83 @param value value of the duration spin box (integer) |
92 @param value value of the duration spin box |
|
93 @type int |
84 """ |
94 """ |
85 self.__checkOk() |
95 self.__checkOk() |
86 |
96 |
87 def getData(self): |
97 def getData(self): |
88 """ |
98 """ |
89 Public method to get the data. |
99 Public method to get the data. |
90 |
100 |
91 @return tuple with start date and time, duration, task description |
101 @return tuple with start date and time, duration, task description |
92 and comment (QDateTime, integer, string, string) |
102 and comment |
|
103 @rtype tuple of (QDateTime, int, str, str) |
93 """ |
104 """ |
94 return ( |
105 return ( |
95 self.startDateTimeEdit.dateTime(), |
106 self.startDateTimeEdit.dateTime(), |
96 self.durationSpinBox.value(), |
107 self.durationSpinBox.value(), |
97 self.taskCombo.currentText(), |
108 self.taskCombo.currentText(), |