|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the task properties dialog. |
|
8 """ |
|
9 |
|
10 import time |
|
11 |
|
12 from PyQt5.QtWidgets import QDialog |
|
13 |
|
14 from E5Gui.E5Completers import E5FileCompleter |
|
15 |
|
16 from .Ui_TaskPropertiesDialog import Ui_TaskPropertiesDialog |
|
17 |
|
18 from .Task import TaskType, TaskPriority |
|
19 |
|
20 |
|
21 class TaskPropertiesDialog(QDialog, Ui_TaskPropertiesDialog): |
|
22 """ |
|
23 Class implementing the task properties dialog. |
|
24 """ |
|
25 def __init__(self, task=None, parent=None, projectOpen=False): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param task the task object to be shown |
|
30 @type Task |
|
31 @param parent the parent widget |
|
32 @type QWidget |
|
33 @param projectOpen flag indicating status of the project |
|
34 @type bool |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.filenameCompleter = E5FileCompleter(self.filenameEdit) |
|
40 |
|
41 self.typeCombo.addItem(self.tr("Bugfix"), TaskType.FIXME) |
|
42 self.typeCombo.addItem(self.tr("Warning"), TaskType.WARNING) |
|
43 self.typeCombo.addItem(self.tr("ToDo"), TaskType.TODO) |
|
44 self.typeCombo.addItem(self.tr("Note"), TaskType.NOTE) |
|
45 self.typeCombo.addItem(self.tr("Test"), TaskType.TEST) |
|
46 self.typeCombo.addItem(self.tr("Documentation"), TaskType.DOCU) |
|
47 |
|
48 if task is not None: |
|
49 self.summaryEdit.setText(task.summary) |
|
50 self.descriptionEdit.setText(task.description) |
|
51 self.creationLabel.setText( |
|
52 time.strftime("%Y-%m-%d, %H:%M:%S", |
|
53 time.localtime(task.created))) |
|
54 self.priorityCombo.setCurrentIndex(task.priority.value) |
|
55 self.projectCheckBox.setChecked(task._isProjectTask) |
|
56 self.completedCheckBox.setChecked(task.completed) |
|
57 self.filenameEdit.setText(task.filename) |
|
58 if task.lineno: |
|
59 self.linenoEdit.setText(str(task.lineno)) |
|
60 index = self.typeCombo.findData(task.taskType) |
|
61 self.typeCombo.setCurrentIndex(index) |
|
62 self.__setMode(bool(task.filename), projectOpen) |
|
63 else: |
|
64 self.projectCheckBox.setChecked(projectOpen) |
|
65 self.typeCombo.setCurrentIndex(2) # TaskType.TODO |
|
66 self.__setMode(False, projectOpen) |
|
67 |
|
68 def __setMode(self, isFileTask, projectOpen): |
|
69 """ |
|
70 Private method to show or hide dialog elements depending on the task |
|
71 kind. |
|
72 |
|
73 @param isFileTask flag indicating a file task (i.e. extracted task) |
|
74 @type bool |
|
75 @param projectOpen flag indicating status of the project |
|
76 @type bool |
|
77 """ |
|
78 self.__isFileTaskMode = isFileTask |
|
79 if self.__isFileTaskMode: |
|
80 self.descriptionEdit.hide() |
|
81 self.descriptionLabel.hide() |
|
82 self.manualTaskFrame.hide() |
|
83 |
|
84 msh = self.minimumSizeHint() |
|
85 self.resize(max(self.width(), msh.width()), msh.height()) |
|
86 else: |
|
87 self.fileTaskFrame.hide() |
|
88 |
|
89 self.summaryEdit.setReadOnly(isFileTask) |
|
90 self.projectCheckBox.setEnabled(projectOpen and not isFileTask) |
|
91 |
|
92 def isManualTaskMode(self): |
|
93 """ |
|
94 Public method to check, if the dialog is in manual task mode. |
|
95 |
|
96 @return flag indicating manual task mode |
|
97 @rtype bool |
|
98 """ |
|
99 return not self.__isFileTaskMode |
|
100 |
|
101 def setSubTaskMode(self, projectTask): |
|
102 """ |
|
103 Public slot to set the sub-task mode. |
|
104 |
|
105 @param projectTask flag indicating a project related task (boolean) |
|
106 """ |
|
107 self.projectCheckBox.setChecked(projectTask) |
|
108 self.projectCheckBox.setEnabled(False) |
|
109 |
|
110 def getData(self): |
|
111 """ |
|
112 Public method to retrieve the dialogs data. |
|
113 |
|
114 @return tuple of description, priority, type, completion flag, |
|
115 project flag and long text |
|
116 @rtype tuple of (str, TaskPriority, TaskType, bool, bool, str) |
|
117 """ |
|
118 return (self.summaryEdit.text(), |
|
119 TaskPriority(self.priorityCombo.currentIndex()), |
|
120 TaskType(self.typeCombo.currentData()), |
|
121 self.completedCheckBox.isChecked(), |
|
122 self.projectCheckBox.isChecked(), |
|
123 self.descriptionEdit.toPlainText()) |