From f99960a96c681cebde3e5d2396ca05efe33f0eac Mon Sep 17 00:00:00 2001 From: Faerbit Date: Tue, 3 Mar 2020 23:20:36 +0100 Subject: [PATCH] Fix "New item" button in report dialog. --- data.py | 13 ++++++------- report.py | 12 ++++++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/data.py b/data.py index 3edc58a..503bcf5 100644 --- a/data.py +++ b/data.py @@ -159,7 +159,7 @@ class Report: def __init__(self, data, pdate): self._data = data self._date = pdate - self._actual_data_len = 0 + self._sum_len = 0 self._prev = None self._next = None self._update_prev_next() @@ -204,14 +204,13 @@ class Report: dhours, rem = divmod(total_sum.seconds, 3600) dmins, _ = divmod(rem, 60) ret.append(["Total sum", "", f"{dhours:02d}:{dmins:02d}"]) - edit_len = len(ret) - (4 + len(tasks_sums)) - self._actual_data_len = edit_len - if self._date != date.today(): - self._actual_data_len += 1 - return ret, edit_len + self._sum_len = 3 + len(tasks_sums) + if self._date == date.today(): + self._sum_len += 1 + return ret, len(ret) - (4 + len(tasks_sums)) def save(self, report): - report = report[:self._actual_data_len] + report = report[:-self._sum_len] if not report: return save_list = [] diff --git a/report.py b/report.py index d6aabfe..42a8517 100644 --- a/report.py +++ b/report.py @@ -11,6 +11,7 @@ class Report(QtWidgets.QDialog): self._changing_items = False self._new_log_task = "" self._new_log_pos = -1 + self._edit_len = -1 self.setWindowTitle("Report") @@ -72,7 +73,7 @@ class Report(QtWidgets.QDialog): self.setWindowTitle(f"Report {self._report.date()}") 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._changing_items = True @@ -84,9 +85,9 @@ class Report(QtWidgets.QDialog): item2 = QtWidgets.QTableWidgetItem(self._report_data[row][2]) self.tableWidget.setItem(row, 2, item2) item2.setFlags(item2.flags() & QtCore.Qt.ItemIsEnabled) - if row >= edit_len: + if row >= self._edit_len: item0.setFlags(item1.flags() & QtCore.Qt.ItemIsEnabled) - if row > edit_len: + if row > self._edit_len: item1.setFlags(item0.flags() & QtCore.Qt.ItemIsEnabled) self._changing_items = False @@ -122,12 +123,14 @@ class Report(QtWidgets.QDialog): @QtCore.Slot() 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.tableWidget.insertRow(after) self.tableWidget.setCurrentCell(after, 0) item = QtWidgets.QTableWidgetItem() + self._changing_items = True self.tableWidget.setItem(after, 0, item) + self._changing_items = False self.tableWidget.editItem(item) @QtCore.Slot() @@ -162,6 +165,7 @@ class Report(QtWidgets.QDialog): if column == 0: if self._new_log_pos == row: self._new_log_task = self.tableWidget.item(row, column).text() or "Unnamed" + return else: self._report_data[row][column] = item.text() or "Unnamed" if column == 1: