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 "qorganizertodooccurrence.h" |
35 | |
36 | #include <QtCore/qdatetime.h> |
37 | |
38 | #include "qorganizeritemid.h" |
39 | #include "qorganizeritemparent.h" |
40 | #include "qorganizertodotime.h" |
41 | |
42 | QT_BEGIN_NAMESPACE_ORGANIZER |
43 | |
44 | /*! |
45 | \class QOrganizerTodoOccurrence |
46 | \brief The QOrganizerTodoOccurrence class provides an occurrence of a task which should be completed |
47 | \inmodule QtOrganizer |
48 | \ingroup organizer-items |
49 | |
50 | A todo occurrence is a specific instance of a todo item. An occurrence |
51 | which is retrieved from a manager may not actually be persisted in that |
52 | manager (for example, it may be generated automatically from the |
53 | recurrence rule of the parent todo stored in the manager), in which case |
54 | it will have a zero-id and differ from the parent todo only in its start |
55 | date. Alternatively, it may be persisted in the manager (that is, the |
56 | client has saved the occurrence previously) where it is stored as an exception |
57 | to its parent todo. |
58 | */ |
59 | |
60 | /*! |
61 | Sets the date time at which the task should be started to \a startDateTime. For all-day tasks, |
62 | the time part can be set to any valid value. |
63 | */ |
64 | void QOrganizerTodoOccurrence::setStartDateTime(const QDateTime &startDateTime) |
65 | { |
66 | QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime); |
67 | ttr.setStartDateTime(startDateTime); |
68 | saveDetail(detail: &ttr); |
69 | } |
70 | |
71 | /*! |
72 | Returns the date time at which the task should be started. For all-day tasks, the time part is |
73 | meaningless. |
74 | */ |
75 | QDateTime QOrganizerTodoOccurrence::startDateTime() const |
76 | { |
77 | QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime); |
78 | return ttr.startDateTime(); |
79 | } |
80 | |
81 | /*! |
82 | Sets the date time by which the task should be completed to \a dueDateTime. For all-day tasks, |
83 | the time part can be set to any valid value. |
84 | */ |
85 | void QOrganizerTodoOccurrence::setDueDateTime(const QDateTime &dueDateTime) |
86 | { |
87 | QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime); |
88 | ttr.setDueDateTime(dueDateTime); |
89 | saveDetail(detail: &ttr); |
90 | } |
91 | |
92 | /*! |
93 | Returns the date time by which the task should be completed. For all-day tasks, the time part is |
94 | meaningless. |
95 | */ |
96 | QDateTime QOrganizerTodoOccurrence::dueDateTime() const |
97 | { |
98 | QOrganizerTodoTime ttr = detail(detailType: QOrganizerItemDetail::TypeTodoTime); |
99 | return ttr.dueDateTime(); |
100 | } |
101 | |
102 | /*! |
103 | Sets the todo occurrence's parent to be the todo identified by the |
104 | given \a parentId. |
105 | */ |
106 | void QOrganizerTodoOccurrence::setParentId(const QOrganizerItemId &parentId) |
107 | { |
108 | QOrganizerItemParent origin = detail(detailType: QOrganizerItemDetail::TypeParent); |
109 | origin.setParentId(parentId); |
110 | saveDetail(detail: &origin); |
111 | } |
112 | |
113 | /*! |
114 | Returns the id of the todo which is this occurrence's parent. |
115 | */ |
116 | QOrganizerItemId QOrganizerTodoOccurrence::parentId() const |
117 | { |
118 | QOrganizerItemParent origin = detail(detailType: QOrganizerItemDetail::TypeParent); |
119 | return origin.parentId(); |
120 | } |
121 | |
122 | /*! |
123 | Sets the date at which this occurrence was originally going to occur, |
124 | to the given \a date. |
125 | */ |
126 | void QOrganizerTodoOccurrence::setOriginalDate(const QDate &date) |
127 | { |
128 | QOrganizerItemParent origin = detail(detailType: QOrganizerItemDetail::TypeParent); |
129 | origin.setOriginalDate(date); |
130 | saveDetail(detail: &origin); |
131 | } |
132 | |
133 | /*! |
134 | Returns the date at which the occurrence was originally going to occur. |
135 | */ |
136 | QDate QOrganizerTodoOccurrence::originalDate() const |
137 | { |
138 | QOrganizerItemParent origin = detail(detailType: QOrganizerItemDetail::TypeParent); |
139 | return origin.originalDate(); |
140 | } |
141 | |
142 | /*! |
143 | Sets the priority of the todo occurrence to \a priority. |
144 | */ |
145 | void QOrganizerTodoOccurrence::setPriority(QOrganizerItemPriority::Priority priority) |
146 | { |
147 | QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority); |
148 | pd.setPriority(priority); |
149 | saveDetail(detail: &pd); |
150 | } |
151 | |
152 | /*! |
153 | Returns the priority of the todo occurrence.. |
154 | */ |
155 | QOrganizerItemPriority::Priority QOrganizerTodoOccurrence::priority() const |
156 | { |
157 | QOrganizerItemPriority pd = detail(detailType: QOrganizerItemDetail::TypePriority); |
158 | return pd.priority(); |
159 | } |
160 | |
161 | /*! |
162 | Sets the percentage of progress completed on the task described |
163 | by the todo occurrence item to \a percentage. Note that the given |
164 | \a percentage must be between 0 and 100, otherwise ignored. |
165 | */ |
166 | void QOrganizerTodoOccurrence::setProgressPercentage(int percentage) |
167 | { |
168 | if (percentage >= 0 && percentage <= 100) { |
169 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
170 | tp.setPercentageComplete(percentage); |
171 | saveDetail(detail: &tp); |
172 | } |
173 | } |
174 | |
175 | /*! |
176 | Returns the percentage of progress completed on the task described |
177 | by the todo occurrence. |
178 | */ |
179 | int QOrganizerTodoOccurrence::progressPercentage() const |
180 | { |
181 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
182 | return tp.percentageComplete(); |
183 | } |
184 | |
185 | /*! |
186 | Sets the progress status of the todo occurrence to \a status. |
187 | */ |
188 | void QOrganizerTodoOccurrence::setStatus(QOrganizerTodoProgress::Status status) |
189 | { |
190 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
191 | tp.setStatus(status); |
192 | saveDetail(detail: &tp); |
193 | } |
194 | |
195 | /*! |
196 | Returns the progress status of the task described by the todo occurrence. |
197 | */ |
198 | QOrganizerTodoProgress::Status QOrganizerTodoOccurrence::status() const |
199 | { |
200 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
201 | return tp.status(); |
202 | } |
203 | |
204 | /*! |
205 | Sets the date and time at which the task described by the todo occurrence was completed to \a finishedDateTime. |
206 | */ |
207 | void QOrganizerTodoOccurrence::setFinishedDateTime(const QDateTime &finishedDateTime) |
208 | { |
209 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
210 | tp.setFinishedDateTime(finishedDateTime); |
211 | saveDetail(detail: &tp); |
212 | } |
213 | |
214 | /*! |
215 | Returns the date and time at which the task described by the todo occurrence was completed. |
216 | */ |
217 | QDateTime QOrganizerTodoOccurrence::finishedDateTime() const |
218 | { |
219 | QOrganizerTodoProgress tp = detail(detailType: QOrganizerItemDetail::TypeTodoProgress); |
220 | return tp.finishedDateTime(); |
221 | } |
222 | |
223 | QT_END_NAMESPACE_ORGANIZER |
224 | |