15 |
15 |
16 class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog): |
16 class TimeTrackerEntryDialog(QDialog, Ui_TimeTrackerEntryDialog): |
17 """ |
17 """ |
18 Class implementing the time tracker edit dialog. |
18 Class implementing the time tracker edit dialog. |
19 """ |
19 """ |
|
20 |
20 def __init__(self, tracker, entry, taskItems, commentItems, parent=None): |
21 def __init__(self, tracker, entry, taskItems, commentItems, parent=None): |
21 """ |
22 """ |
22 Constructor |
23 Constructor |
23 |
24 |
24 @param tracker reference to the time tracker |
25 @param tracker reference to the time tracker |
25 @type TimeTracker |
26 @type TimeTracker |
26 @param entry reference to the time tracker entry |
27 @param entry reference to the time tracker entry |
27 @type TimeTrackEntry |
28 @type TimeTrackEntry |
28 @param taskItems list of task item entries for the |
29 @param taskItems list of task item entries for the |
34 @param parent reference to the parent widget |
35 @param parent reference to the parent widget |
35 @type QWidget |
36 @type QWidget |
36 """ |
37 """ |
37 super().__init__(parent) |
38 super().__init__(parent) |
38 self.setupUi(self) |
39 self.setupUi(self) |
39 |
40 |
40 self.buttonBox.button( |
41 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
41 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
42 |
42 |
|
43 self.taskCombo.addItems(taskItems) |
43 self.taskCombo.addItems(taskItems) |
44 self.commentCombo.addItems(commentItems) |
44 self.commentCombo.addItems(commentItems) |
45 |
45 |
46 # 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 |
47 # earlier or equal to the start date and time of the current entry. |
47 # earlier or equal to the start date and time of the current entry. |
48 self.__endDateTime = QDateTime( |
48 self.__endDateTime = QDateTime(tracker.getCurrentEntry().getStartDateTime()) |
49 tracker.getCurrentEntry().getStartDateTime()) |
49 |
50 |
50 self.durationSpinBox.setMinimum(tracker.getPreferences("MinimumDuration")) |
51 self.durationSpinBox.setMinimum( |
51 |
52 tracker.getPreferences("MinimumDuration")) |
|
53 |
|
54 if entry is None: |
52 if entry is None: |
55 self.setWindowTitle(self.tr("Add Tracker Entry")) |
53 self.setWindowTitle(self.tr("Add Tracker Entry")) |
56 self.startDateTimeEdit.setDate(QDate.currentDate()) |
54 self.startDateTimeEdit.setDate(QDate.currentDate()) |
57 else: |
55 else: |
58 self.startDateTimeEdit.setDateTime(entry.getStartDateTime()) |
56 self.startDateTimeEdit.setDateTime(entry.getStartDateTime()) |
59 self.durationSpinBox.setValue(entry.getDuration()) |
57 self.durationSpinBox.setValue(entry.getDuration()) |
60 self.durationSpinBox.setMaximum( |
58 self.durationSpinBox.setMaximum( |
61 entry.getStartDateTime().secsTo(self.__endDateTime) // 60) |
59 entry.getStartDateTime().secsTo(self.__endDateTime) // 60 |
|
60 ) |
62 self.taskCombo.setEditText(entry.getTask()) |
61 self.taskCombo.setEditText(entry.getTask()) |
63 self.commentCombo.setEditText(entry.getComment()) |
62 self.commentCombo.setEditText(entry.getComment()) |
64 |
63 |
65 msh = self.minimumSizeHint() |
64 msh = self.minimumSizeHint() |
66 self.resize(max(self.width(), msh.width()), msh.height()) |
65 self.resize(max(self.width(), msh.width()), msh.height()) |
67 |
66 |
68 def __checkOk(self): |
67 def __checkOk(self): |
69 """ |
68 """ |
70 Private slot to set the enabled state of the OK button. |
69 Private slot to set the enabled state of the OK button. |
71 """ |
70 """ |
72 dt = self.startDateTimeEdit.dateTime() |
71 dt = self.startDateTimeEdit.dateTime() |
73 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
72 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
74 dt.addSecs(self.durationSpinBox.value() * 60) <= |
73 dt.addSecs(self.durationSpinBox.value() * 60) <= self.__endDateTime |
75 self.__endDateTime) |
74 ) |
76 |
75 |
77 @pyqtSlot(QDateTime) |
76 @pyqtSlot(QDateTime) |
78 def on_startDateTimeEdit_dateTimeChanged(self, date): |
77 def on_startDateTimeEdit_dateTimeChanged(self, date): |
79 """ |
78 """ |
80 Private slot handling a change of the start date and time. |
79 Private slot handling a change of the start date and time. |
81 |
80 |
82 @param date start date and time |
81 @param date start date and time |
83 @type QDateTime |
82 @type QDateTime |
84 """ |
83 """ |
85 self.__checkOk() |
84 self.__checkOk() |
86 |
85 |
87 @pyqtSlot(int) |
86 @pyqtSlot(int) |
88 def on_durationSpinBox_valueChanged(self, value): |
87 def on_durationSpinBox_valueChanged(self, value): |
89 """ |
88 """ |
90 Private slot handling a change of the duration. |
89 Private slot handling a change of the duration. |
91 |
90 |
92 @param value value of the duration spin box |
91 @param value value of the duration spin box |
93 @type int |
92 @type int |
94 """ |
93 """ |
95 self.__checkOk() |
94 self.__checkOk() |
96 |
95 |
97 def getData(self): |
96 def getData(self): |
98 """ |
97 """ |
99 Public method to get the data. |
98 Public method to get the data. |
100 |
99 |
101 @return tuple with start date and time, duration, task description |
100 @return tuple with start date and time, duration, task description |
102 and comment |
101 and comment |
103 @rtype tuple of (QDateTime, int, str, str) |
102 @rtype tuple of (QDateTime, int, str, str) |
104 """ |
103 """ |
105 return ( |
104 return ( |