|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a class to store task data. |
|
8 """ |
|
9 |
|
10 import os |
|
11 import time |
|
12 |
|
13 from PyQt4.QtCore import Qt |
|
14 from PyQt4.QtGui import QTreeWidgetItem |
|
15 |
|
16 import UI.PixmapCache |
|
17 import Preferences |
|
18 |
|
19 |
|
20 class Task(QTreeWidgetItem): |
|
21 """ |
|
22 Class implementing the task data structure. |
|
23 """ |
|
24 TypeNone = -1 |
|
25 TypeFixme = 0 |
|
26 TypeTodo = 1 |
|
27 TypeWarning = 2 |
|
28 TypeNote = 3 |
|
29 |
|
30 def __init__(self, description, priority=1, filename="", lineno=0, |
|
31 completed=False, _time=0, isProjectTask=False, |
|
32 taskType=TypeTodo, project=None, longtext=""): |
|
33 """ |
|
34 Constructor |
|
35 |
|
36 @param parent parent widget of the task (QWidget) |
|
37 @param description descriptive text of the task (string) |
|
38 @param priority priority of the task (0=high, 1=normal, 2=low) |
|
39 @param filename filename containing the task (string) |
|
40 @param lineno line number containing the task (integer) |
|
41 @param completed flag indicating completion status (boolean) |
|
42 @param _time creation time of the task (float, if 0 use current time) |
|
43 @param isProjectTask flag indicating a task related to the current project |
|
44 (boolean) |
|
45 @param taskType type of the task (one of TypeFixme, TypeTodo, |
|
46 TypeWarning, TypeNote) |
|
47 @param project reference to the project object (Project) |
|
48 @param longtext explanatory text of the task (string) |
|
49 """ |
|
50 super().__init__() |
|
51 |
|
52 self.description = description |
|
53 self.longtext = longtext |
|
54 if priority in [0, 1, 2]: |
|
55 self.priority = priority |
|
56 else: |
|
57 self.priority = 1 |
|
58 self.filename = filename |
|
59 self.lineno = lineno |
|
60 self.completed = completed |
|
61 self.created = _time and _time or time.time() |
|
62 self._isProjectTask = isProjectTask |
|
63 self.taskType = taskType |
|
64 self.project = project |
|
65 |
|
66 if isProjectTask: |
|
67 self.filename = self.project.getRelativePath(self.filename) |
|
68 |
|
69 self.setData(0, Qt.DisplayRole, "") |
|
70 self.setData(1, Qt.DisplayRole, "") |
|
71 self.setData(2, Qt.DisplayRole, self.description) |
|
72 self.setData(3, Qt.DisplayRole, self.filename) |
|
73 self.setData(4, Qt.DisplayRole, self.lineno or "") |
|
74 |
|
75 if self.completed: |
|
76 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted.png")) |
|
77 strikeOut = True |
|
78 else: |
|
79 self.setIcon(0, UI.PixmapCache.getIcon("empty.png")) |
|
80 strikeOut = False |
|
81 for column in range(2, 5): |
|
82 f = self.font(column) |
|
83 f.setStrikeOut(strikeOut) |
|
84 self.setFont(column, f) |
|
85 |
|
86 if self.priority == 1: |
|
87 self.setIcon(1, UI.PixmapCache.getIcon("empty.png")) |
|
88 elif self.priority == 0: |
|
89 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh.png")) |
|
90 elif self.priority == 2: |
|
91 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow.png")) |
|
92 else: |
|
93 self.setIcon(1, UI.PixmapCache.getIcon("empty.png")) |
|
94 |
|
95 if self.taskType == Task.TypeFixme: |
|
96 self.setIcon(2, UI.PixmapCache.getIcon("taskFixme.png")) |
|
97 elif self.taskType == Task.TypeWarning: |
|
98 self.setIcon(2, UI.PixmapCache.getIcon("taskWarning.png")) |
|
99 elif self.taskType == Task.TypeTodo: |
|
100 self.setIcon(2, UI.PixmapCache.getIcon("taskTodo.png")) |
|
101 else: |
|
102 self.setIcon(2, UI.PixmapCache.getIcon("taskNote.png")) |
|
103 |
|
104 self.colorizeTask() |
|
105 self.setTextAlignment(4, Qt.AlignRight) |
|
106 |
|
107 def colorizeTask(self): |
|
108 """ |
|
109 Public slot to set the colors of the task item. |
|
110 """ |
|
111 boldFont = self.font(0) |
|
112 boldFont.setBold(True) |
|
113 for col in range(5): |
|
114 if self.taskType == Task.TypeFixme: |
|
115 self.setBackgroundColor(col, Preferences.getTasks("TasksFixmeColor")) |
|
116 elif self.taskType == Task.TypeWarning: |
|
117 self.setBackgroundColor(col, Preferences.getTasks("TasksWarningColor")) |
|
118 elif self.taskType == Task.TypeTodo: |
|
119 self.setBackgroundColor(col, Preferences.getTasks("TasksTodoColor")) |
|
120 else: |
|
121 self.setBackgroundColor(col, Preferences.getTasks("TasksNoteColor")) |
|
122 if self._isProjectTask: |
|
123 self.setFont(col, boldFont) |
|
124 |
|
125 def setDescription(self, description): |
|
126 """ |
|
127 Public slot to update the description. |
|
128 |
|
129 @param longtext explanatory text of the task (string) |
|
130 """ |
|
131 self.description = description |
|
132 self.setText(2, self.description) |
|
133 |
|
134 def setLongText(self, longtext): |
|
135 """ |
|
136 Public slot to update the longtext field. |
|
137 |
|
138 @param longtext descriptive text of the task (string) |
|
139 """ |
|
140 self.longtext = longtext |
|
141 |
|
142 def setPriority(self, priority): |
|
143 """ |
|
144 Public slot to update the priority. |
|
145 |
|
146 @param priority priority of the task (0=high, 1=normal, 2=low) |
|
147 """ |
|
148 if priority in [0, 1, 2]: |
|
149 self.priority = priority |
|
150 else: |
|
151 self.priority = 1 |
|
152 |
|
153 if self.priority == 1: |
|
154 self.setIcon(1, UI.PixmapCache.getIcon("empty.png")) |
|
155 elif self.priority == 0: |
|
156 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioHigh.png")) |
|
157 elif self.priority == 2: |
|
158 self.setIcon(1, UI.PixmapCache.getIcon("taskPrioLow.png")) |
|
159 else: |
|
160 self.setIcon(1, UI.PixmapCache.getIcon("empty.png")) |
|
161 |
|
162 def setCompleted(self, completed): |
|
163 """ |
|
164 Public slot to update the completed flag. |
|
165 |
|
166 @param completed flag indicating completion status (boolean) |
|
167 """ |
|
168 self.completed = completed |
|
169 if self.completed: |
|
170 self.setIcon(0, UI.PixmapCache.getIcon("taskCompleted.png")) |
|
171 strikeOut = True |
|
172 else: |
|
173 self.setIcon(0, UI.PixmapCache.getIcon("empty.png")) |
|
174 strikeOut = False |
|
175 for column in range(2, 5): |
|
176 f = self.font(column) |
|
177 f.setStrikeOut(strikeOut) |
|
178 self.setFont(column, f) |
|
179 |
|
180 def isCompleted(self): |
|
181 """ |
|
182 Public slot to return the completion status. |
|
183 |
|
184 @return flag indicating the completion status (boolean) |
|
185 """ |
|
186 return self.completed |
|
187 |
|
188 def getFilename(self): |
|
189 """ |
|
190 Public method to retrieve the tasks filename. |
|
191 |
|
192 @return filename (string) |
|
193 """ |
|
194 if self._isProjectTask and self.filename: |
|
195 return os.path.join(self.project.getProjectPath(), self.filename) |
|
196 else: |
|
197 return self.filename |
|
198 |
|
199 def getLineno(self): |
|
200 """ |
|
201 Public method to retrieve the tasks linenumber. |
|
202 |
|
203 @return linenumber (integer) |
|
204 """ |
|
205 return self.lineno |
|
206 |
|
207 def setProjectTask(self, pt): |
|
208 """ |
|
209 Public method to set the project relation flag. |
|
210 |
|
211 @param pt flag indicating a project task (boolean) |
|
212 """ |
|
213 self._isProjectTask = pt |
|
214 self.colorizeTask() |
|
215 |
|
216 def isProjectTask(self): |
|
217 """ |
|
218 Public slot to return the project relation status. |
|
219 |
|
220 @return flag indicating the project relation status (boolean) |
|
221 """ |
|
222 return self._isProjectTask |