1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtOrganizer module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include "qorganizertodo.h"
35
36#include "qorganizertodotime.h"
37
38QT_BEGIN_NAMESPACE_ORGANIZER
39
40/*!
41 \class QOrganizerTodo
42 \brief The QOrganizerTodo class provides a task which should be completed.
43 \inmodule QtOrganizer
44 \ingroup organizer-items
45
46 A todo is an item which contains information about a task which has to
47 be completed. It might be associated with a particular point in time
48 (for example, water the garden tomorrow evening) or it might have no
49 specific temporal association (for example, climb Mount Everest someday).
50
51 A todo can reoccur (for example, water the garden every evening) or it
52 can occur only once.
53
54 Todos can be used to schedule agenda items or tasks in a meaningful manner.
55 */
56
57/*!
58 Sets the date time at which the task should be started to \a startDateTime (for recurring tasks,
59 this applies to the first instance). For all-day tasks, the time part can be set to any valid
60 value.
61 */
62void QOrganizerTodo::setStartDateTime(const QDateTime &startDateTime)
63{
64 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
65 ttr.setStartDateTime(startDateTime);
66 saveDetail(detail: &ttr);
67}
68
69/*!
70 Returns the date time at which the task should be started (for recurring tasks, this applies to
71 the first instance). For all-day tasks, the time part is meaningless.
72 */
73QDateTime QOrganizerTodo::startDateTime() const
74{
75 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
76 return ttr.startDateTime();
77}
78
79/*!
80 Sets the date time by which the task should be completed to \a dueDateTime (for recurring tasks,
81 this applies to the first instance). For all-day tasks, the time part can be set to any valid
82 value.
83 */
84void QOrganizerTodo::setDueDateTime(const QDateTime &dueDateTime)
85{
86 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
87 ttr.setDueDateTime(dueDateTime);
88 saveDetail(detail: &ttr);
89}
90
91/*!
92 Returns the date time by which the task should be completed (for recurring tasks, this applies to
93 the first instance). For all-day tasks, the time part is meaningless.
94 */
95QDateTime QOrganizerTodo::dueDateTime() const
96{
97 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
98 return ttr.dueDateTime();
99}
100
101/*!
102 Sets whether the time-of-day component of the todo's start date-time or end date-time is
103 insignificant (e.g. this is generally set to true for a birthday). If \a isAllDay is true,
104 the time-of-day component is considered insignificant, and the todo will be an all-day
105 item.
106 */
107void QOrganizerTodo::setAllDay(bool isAllDay)
108{
109 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
110 ttr.setAllDay(isAllDay);
111 saveDetail(detail: &ttr);
112}
113
114/*!
115 Returns true if and only if the time component of the start date/time or end date/time are
116 insignificant.
117*/
118bool QOrganizerTodo::isAllDay() const
119{
120 QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime);
121 return ttr.isAllDay();
122}
123
124/*!
125 Sets the dates on which the todo reoccurs to \a rdates.
126 */
127void QOrganizerTodo::setRecurrenceDates(const QSet<QDate> &rdates)
128{
129 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
130 rec.setRecurrenceDates(rdates);
131 saveDetail(detail: &rec);
132}
133
134/*!
135 Returns the dates on which the todo reoccurs, which have been explicitly set
136 by calling \l setRecurrenceDates().
137 */
138QSet<QDate> QOrganizerTodo::recurrenceDates() const
139{
140 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
141 return rec.recurrenceDates();
142}
143
144/*!
145 Clears the set of recurrence rules which define when the todo occurs, and replaces
146 it will the single recurrence rule \a rrule.
147 */
148void QOrganizerTodo::setRecurrenceRule(const QOrganizerRecurrenceRule &rrule)
149{
150 setRecurrenceRules(QSet<QOrganizerRecurrenceRule>() << rrule);
151}
152
153/*!
154 Sets the recurrence rules which define when the todo occurs to \a rrules.
155 */
156void QOrganizerTodo::setRecurrenceRules(const QSet<QOrganizerRecurrenceRule> &rrules)
157{
158 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
159 rec.setRecurrenceRules(rrules);
160 saveDetail(detail: &rec);
161}
162
163/*!
164 Returns a recurrence rule which defines when the todo occurs.
165 If more than one recurrence rule has been set in the todo,
166 one will be returned at random.
167 */
168QOrganizerRecurrenceRule QOrganizerTodo::recurrenceRule() const
169{
170 QSet<QOrganizerRecurrenceRule> rrules = recurrenceRules();
171 if (!rrules.isEmpty())
172 return *rrules.begin();
173 return QOrganizerRecurrenceRule();
174}
175
176/*!
177 Returns the list of recurrence rules which define when the todo occurs.
178 */
179QSet<QOrganizerRecurrenceRule> QOrganizerTodo::recurrenceRules() const
180{
181 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
182 return rec.recurrenceRules();
183}
184
185/*!
186 Sets the dates on which the todo does not occur despite the date
187 fulfilling the recurrence rules of the todo, to \a exdates
188 */
189void QOrganizerTodo::setExceptionDates(const QSet<QDate> &exdates)
190{
191 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
192 rec.setExceptionDates(exdates);
193 saveDetail(detail: &rec);
194}
195
196/*!
197 Returns the dates on which the todo does not occur, where it otherwise
198 would occur as described by the recurrence rules.
199 */
200QSet<QDate> QOrganizerTodo::exceptionDates() const
201{
202 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
203 return rec.exceptionDates();
204}
205
206/*!
207 Clears the set of recurrence rules which describe the dates on which the todo does
208 not occur, where it otherwise would occur as described by the recurrence rules, and
209 inserts into the cleared list the single exception rule \a exrule.
210 */
211void QOrganizerTodo::setExceptionRule(const QOrganizerRecurrenceRule &exrule)
212{
213 setExceptionRules(QSet<QOrganizerRecurrenceRule>() << exrule);
214}
215
216/*!
217 Sets the recurrence rules which describe the dates on which the todo does
218 not occur, where it otherwise would occur as described by the recurrence rules
219 set with \l setRecurrenceRules(), to \a exrules.
220 */
221void QOrganizerTodo::setExceptionRules(const QSet<QOrganizerRecurrenceRule> &exrules)
222{
223 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
224 rec.setExceptionRules(exrules);
225 saveDetail(detail: &rec);
226}
227
228/*!
229 Returns a recurrence rule which describe the dates on which the todo does not occur, where
230 it otherwise would occur as described by the recurrence rules. If more than one exception
231 rule was set for the todo item, one of those exception rules will be returned at random.
232 */
233QOrganizerRecurrenceRule QOrganizerTodo::exceptionRule() const
234{
235 QSet<QOrganizerRecurrenceRule> exrules = exceptionRules();
236 if (!exrules.isEmpty())
237 return *exrules.begin();
238 return QOrganizerRecurrenceRule();
239}
240
241/*!
242 Returns the recurrence rules which describe the dates on which the todo
243 does not occur, where it otherwise would occur as described by the recurrence rules
244 set the \l setRecurrenceRules().
245 */
246QSet<QOrganizerRecurrenceRule> QOrganizerTodo::exceptionRules() const
247{
248 QOrganizerItemRecurrence rec = detail(detailType: QOrganizerItemDetail::TypeRecurrence);
249 return rec.exceptionRules();
250}
251
252/*!
253 Sets the priority of the todo to \a priority.
254 */
255void QOrganizerTodo::setPriority(QOrganizerItemPriority::Priority priority)
256{
257 QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority);
258 pd.setPriority(priority);
259 saveDetail(detail: &pd);
260}
261
262/*!
263 Returns the priority of the task.
264 */
265QOrganizerItemPriority::Priority QOrganizerTodo::priority() const
266{
267 QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority);
268 return pd.priority();
269}
270
271/*!
272 Sets the percentage of progress completed on the task described
273 by the todo item to \a percentage. Note that the \a percentage must
274 be between 0 and 100, otherwise ignored.
275 */
276void QOrganizerTodo::setProgressPercentage(int percentage)
277{
278 if (percentage >= 0 && percentage <= 100) {
279 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
280 tp.setPercentageComplete(percentage);
281 saveDetail(detail: &tp);
282 }
283}
284
285/*!
286 Returns the percentage of progress completed on the task described
287 by the todo.
288 */
289int QOrganizerTodo::progressPercentage() const
290{
291 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
292 return tp.percentageComplete();
293}
294
295/*!
296 Sets the progress status of the task to \a status.
297 */
298void QOrganizerTodo::setStatus(QOrganizerTodoProgress::Status status)
299{
300 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
301 tp.setStatus(status);
302 saveDetail(detail: &tp);
303}
304
305/*!
306 Returns the progress status of the task described by the todo.
307 */
308QOrganizerTodoProgress::Status QOrganizerTodo::status() const
309{
310 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
311 return tp.status();
312}
313
314/*!
315 Sets the date and time at which the task was completed to \a finishedDateTime.
316 */
317void QOrganizerTodo::setFinishedDateTime(const QDateTime &finishedDateTime)
318{
319 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
320 tp.setFinishedDateTime(finishedDateTime);
321 saveDetail(detail: &tp);
322}
323
324/*!
325 Returns the date and time at which the task was completed.
326 */
327QDateTime QOrganizerTodo::finishedDateTime() const
328{
329 QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress);
330 return tp.finishedDateTime();
331}
332
333QT_END_NAMESPACE_ORGANIZER
334

source code of qtpim/src/organizer/items/qorganizertodo.cpp