Fix "New item" button in report dialog.
This commit is contained in:
parent
702917ab07
commit
f99960a96c
13
data.py
13
data.py
@ -159,7 +159,7 @@ class Report:
|
|||||||
def __init__(self, data, pdate):
|
def __init__(self, data, pdate):
|
||||||
self._data = data
|
self._data = data
|
||||||
self._date = pdate
|
self._date = pdate
|
||||||
self._actual_data_len = 0
|
self._sum_len = 0
|
||||||
self._prev = None
|
self._prev = None
|
||||||
self._next = None
|
self._next = None
|
||||||
self._update_prev_next()
|
self._update_prev_next()
|
||||||
@ -204,14 +204,13 @@ class Report:
|
|||||||
dhours, rem = divmod(total_sum.seconds, 3600)
|
dhours, rem = divmod(total_sum.seconds, 3600)
|
||||||
dmins, _ = divmod(rem, 60)
|
dmins, _ = divmod(rem, 60)
|
||||||
ret.append(["Total sum", "", f"{dhours:02d}:{dmins:02d}"])
|
ret.append(["Total sum", "", f"{dhours:02d}:{dmins:02d}"])
|
||||||
edit_len = len(ret) - (4 + len(tasks_sums))
|
self._sum_len = 3 + len(tasks_sums)
|
||||||
self._actual_data_len = edit_len
|
if self._date == date.today():
|
||||||
if self._date != date.today():
|
self._sum_len += 1
|
||||||
self._actual_data_len += 1
|
return ret, len(ret) - (4 + len(tasks_sums))
|
||||||
return ret, edit_len
|
|
||||||
|
|
||||||
def save(self, report):
|
def save(self, report):
|
||||||
report = report[:self._actual_data_len]
|
report = report[:-self._sum_len]
|
||||||
if not report:
|
if not report:
|
||||||
return
|
return
|
||||||
save_list = []
|
save_list = []
|
||||||
|
12
report.py
12
report.py
@ -11,6 +11,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
self._changing_items = False
|
self._changing_items = False
|
||||||
self._new_log_task = ""
|
self._new_log_task = ""
|
||||||
self._new_log_pos = -1
|
self._new_log_pos = -1
|
||||||
|
self._edit_len = -1
|
||||||
|
|
||||||
self.setWindowTitle("Report")
|
self.setWindowTitle("Report")
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
self.setWindowTitle(f"Report {self._report.date()}")
|
self.setWindowTitle(f"Report {self._report.date()}")
|
||||||
|
|
||||||
def refresh_table(self):
|
def refresh_table(self):
|
||||||
self._report_data, edit_len = self._report.report()
|
self._report_data, self._edit_len = self._report.report()
|
||||||
self.tableWidget.setRowCount(len(self._report_data))
|
self.tableWidget.setRowCount(len(self._report_data))
|
||||||
|
|
||||||
self._changing_items = True
|
self._changing_items = True
|
||||||
@ -84,9 +85,9 @@ class Report(QtWidgets.QDialog):
|
|||||||
item2 = QtWidgets.QTableWidgetItem(self._report_data[row][2])
|
item2 = QtWidgets.QTableWidgetItem(self._report_data[row][2])
|
||||||
self.tableWidget.setItem(row, 2, item2)
|
self.tableWidget.setItem(row, 2, item2)
|
||||||
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
if row >= edit_len:
|
if row >= self._edit_len:
|
||||||
item0.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
item0.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
if row > edit_len:
|
if row > self._edit_len:
|
||||||
item1.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
item1.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled)
|
||||||
self._changing_items = False
|
self._changing_items = False
|
||||||
|
|
||||||
@ -122,12 +123,14 @@ class Report(QtWidgets.QDialog):
|
|||||||
|
|
||||||
@QtCore.Slot()
|
@QtCore.Slot()
|
||||||
def new_log(self):
|
def new_log(self):
|
||||||
after = min(self.tableWidget.currentItem().row(), len(self._report_data) - 4) + 1
|
after = min(self.tableWidget.currentItem().row(), self._edit_len-1) + 1
|
||||||
self._new_log_pos = after
|
self._new_log_pos = after
|
||||||
self.tableWidget.insertRow(after)
|
self.tableWidget.insertRow(after)
|
||||||
self.tableWidget.setCurrentCell(after, 0)
|
self.tableWidget.setCurrentCell(after, 0)
|
||||||
item = QtWidgets.QTableWidgetItem()
|
item = QtWidgets.QTableWidgetItem()
|
||||||
|
self._changing_items = True
|
||||||
self.tableWidget.setItem(after, 0, item)
|
self.tableWidget.setItem(after, 0, item)
|
||||||
|
self._changing_items = False
|
||||||
self.tableWidget.editItem(item)
|
self.tableWidget.editItem(item)
|
||||||
|
|
||||||
@QtCore.Slot()
|
@QtCore.Slot()
|
||||||
@ -162,6 +165,7 @@ class Report(QtWidgets.QDialog):
|
|||||||
if column == 0:
|
if column == 0:
|
||||||
if self._new_log_pos == row:
|
if self._new_log_pos == row:
|
||||||
self._new_log_task = self.tableWidget.item(row, column).text() or "Unnamed"
|
self._new_log_task = self.tableWidget.item(row, column).text() or "Unnamed"
|
||||||
|
return
|
||||||
else:
|
else:
|
||||||
self._report_data[row][column] = item.text() or "Unnamed"
|
self._report_data[row][column] = item.text() or "Unnamed"
|
||||||
if column == 1:
|
if column == 1:
|
||||||
|
Loading…
Reference in New Issue
Block a user