Refactor TaskEdit dialog

This commit is contained in:
Fabian 2022-09-29 19:45:49 +02:00
parent 832e768a4e
commit 74e974b7ab
2 changed files with 7 additions and 12 deletions

View File

@ -49,7 +49,7 @@ class App:
self.import_task = ImportTask(config, None)
self.import_task.accepted.connect(self.new_task_imported)
self.taskEdit = TaskEdit(None)
self.taskEdit = TaskEdit(self.tasks, None)
self.taskEdit.accepted.connect(self.tasks_edited)
self.reportDialog = ReportDialog(self.tasks, Report(lcd), None)
@ -122,7 +122,7 @@ class App:
menu_items.append((1, None))
menu_items.append(("Import Jira task", self.import_task.show))
menu_items.append(("Edit tasks", self.edit_tasks))
menu_items.append(("Edit tasks", self.taskEdit.show))
menu_items.append(("Report", self.reportDialog.show))
menu_items.append(("Worklog", self.worklogDialog.show))
@ -161,11 +161,6 @@ class App:
else:
self.app.exec_()
@QtCore.Slot()
def edit_tasks(self):
self.taskEdit.tasks = self.tasks.tasks
self.taskEdit.show()
def init_logging():
log_dir_path = Path(QtCore.QStandardPaths.writableLocation(QtCore.QStandardPaths.AppDataLocation)) / "logs"

View File

@ -3,12 +3,15 @@ try:
except ImportError:
from PySide2 import QtCore, QtGui, QtWidgets
from fime.data import Tasks
from fime.util import get_icon, EditStartedDetector
class TaskEdit(QtWidgets.QDialog):
def __init__(self, parent, *args, **kwargs):
def __init__(self, tasks: Tasks, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self._task_data = tasks
self.setWindowTitle("Edit Tasks")
self.list = QtCore.QStringListModel()
@ -82,10 +85,7 @@ class TaskEdit(QtWidgets.QDialog):
ret = self.list.stringList()
return list(filter(None, ret)) # filter empty strings
@tasks.setter
def tasks(self, tasks):
self.list.setStringList(tasks)
def showEvent(self, _):
self.list.setStringList(self._task_data.tasks)
self.raise_()
self.activateWindow()