Implement start time editing.

This commit is contained in:
Faerbit 2020-02-24 17:15:34 +01:00
parent 233ca3fcee
commit 5b62e8684d
2 changed files with 25 additions and 4 deletions

View File

@ -179,14 +179,14 @@ class Report:
dsum += duration
dhours, rem = divmod(duration.seconds, 3600)
dmins, _ = divmod(rem, 60)
ret.append((task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}"))
ret.append([task, start_time.strftime("%H:%M"), f"{dhours:02d}:{dmins:02d}"])
else:
ret.append((task, start_time.strftime("%H:%M"), ""))
ret.append([task, start_time.strftime("%H:%M"), ""])
ret.append(("", "", ""))
ret.append(["", "", ""])
dhours, rem = divmod(dsum.seconds, 3600)
dmins, _ = divmod(rem, 60)
ret.append(("Sum", "", f"{dhours:02d}:{dmins:02d}"))
ret.append(["Sum", "", f"{dhours:02d}:{dmins:02d}"])
return ret
def save(self, report):

View File

@ -1,11 +1,14 @@
from PySide2 import QtCore, QtGui, QtWidgets
from datetime import datetime
class Report(QtWidgets.QDialog):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self._report = None
self._report_data = None
self._changing_items = False
self.setWindowTitle("Report")
@ -13,6 +16,7 @@ class Report(QtWidgets.QDialog):
self.tableWidget.verticalHeader().hide()
self.tableWidget.setColumnCount(3)
self.tableWidget.setHorizontalHeaderLabels(["Task", "Start time", "Duration"])
self.tableWidget.cellChanged.connect(self.cell_changed)
self.header = QtWidgets.QHeaderView(QtCore.Qt.Orientation.Horizontal)
self.tableWidget.setHorizontalHeader(self.header)
@ -56,6 +60,7 @@ class Report(QtWidgets.QDialog):
def refresh_table(self):
self.tableWidget.setRowCount(len(self._report_data))
self._changing_items = True
for row, _ in enumerate(self._report_data):
item0 = QtWidgets.QTableWidgetItem(self._report_data[row][0])
self.tableWidget.setItem(row, 0, item0)
@ -67,6 +72,7 @@ class Report(QtWidgets.QDialog):
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
if row > len(self._report_data) - 4:
item1.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
self._changing_items = False
self.tableWidget.resizeColumnsToContents()
@ -112,3 +118,18 @@ class Report(QtWidgets.QDialog):
self._report_data = self._report.report()
self.refresh_table()
self.update_prev_next()
@QtCore.Slot()
def cell_changed(self, row, column):
if self._changing_items:
return
item = self.tableWidget.item(row, column)
try:
new_time = datetime.strptime(item.text(), "%H:%M").time()
except ValueError:
item.setText(self._report_data[row][column])
return
self._report_data[row][column] = new_time.strftime("%H:%M")
self._report.save(self._report_data)
self._report_data = self._report.report()
self.refresh_table()