author | zecke <zecke> | 2003-05-07 16:02:41 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-05-07 16:02:41 (UTC) |
commit | accd04a63230ac46978f77deae1b0d1419618730 (patch) (unidiff) | |
tree | 6a54ce4cdda8d86a781838b7b990939e2962d461 /libopie2/opiepim/otodo.cpp | |
parent | ef9b40f99443fabed972d29ce47c2ccb29e77210 (diff) | |
download | opie-accd04a63230ac46978f77deae1b0d1419618730.zip opie-accd04a63230ac46978f77deae1b0d1419618730.tar.gz opie-accd04a63230ac46978f77deae1b0d1419618730.tar.bz2 |
try to use less memory and only create objects like
ORecur, OPimState, OPimNotifyManager and OPimMaintainer if necessary
-rw-r--r-- | libopie2/opiepim/otodo.cpp | 81 |
1 files changed, 66 insertions, 15 deletions
diff --git a/libopie2/opiepim/otodo.cpp b/libopie2/opiepim/otodo.cpp index ea66d39..f3df119 100644 --- a/libopie2/opiepim/otodo.cpp +++ b/libopie2/opiepim/otodo.cpp | |||
@@ -14,40 +14,44 @@ | |||
14 | 14 | ||
15 | #include "opimstate.h" | 15 | #include "opimstate.h" |
16 | #include "orecur.h" | 16 | #include "orecur.h" |
17 | #include "opimmaintainer.h" | 17 | #include "opimmaintainer.h" |
18 | #include "opimnotifymanager.h" | 18 | #include "opimnotifymanager.h" |
19 | #include "opimresolver.h" | 19 | #include "opimresolver.h" |
20 | 20 | ||
21 | #include "otodo.h" | 21 | #include "otodo.h" |
22 | 22 | ||
23 | 23 | ||
24 | struct OTodo::OTodoData : public QShared { | 24 | struct OTodo::OTodoData : public QShared { |
25 | OTodoData() : QShared() { | 25 | OTodoData() : QShared() { |
26 | recur = 0; | ||
27 | state = 0; | ||
28 | maintainer = 0; | ||
29 | notifiers = 0; | ||
26 | }; | 30 | }; |
27 | 31 | ||
28 | QDate date; | 32 | QDate date; |
29 | bool isCompleted:1; | 33 | bool isCompleted:1; |
30 | bool hasDate:1; | 34 | bool hasDate:1; |
31 | int priority; | 35 | int priority; |
32 | QString desc; | 36 | QString desc; |
33 | QString sum; | 37 | QString sum; |
34 | QMap<QString, QString> extra; | 38 | QMap<QString, QString> extra; |
35 | ushort prog; | 39 | ushort prog; |
36 | OPimState state; | 40 | OPimState *state; |
37 | ORecur recur; | 41 | ORecur *recur; |
38 | OPimMaintainer maintainer; | 42 | OPimMaintainer *maintainer; |
39 | QDate start; | 43 | QDate start; |
40 | QDate completed; | 44 | QDate completed; |
41 | OPimNotifyManager notifiers; | 45 | OPimNotifyManager *notifiers; |
42 | }; | 46 | }; |
43 | 47 | ||
44 | OTodo::OTodo(const OTodo &event ) | 48 | OTodo::OTodo(const OTodo &event ) |
45 | : OPimRecord( event ), data( event.data ) | 49 | : OPimRecord( event ), data( event.data ) |
46 | { | 50 | { |
47 | data->ref(); | 51 | data->ref(); |
48 | // qWarning("ref up"); | 52 | // qWarning("ref up"); |
49 | } | 53 | } |
50 | OTodo::~OTodo() { | 54 | OTodo::~OTodo() { |
51 | 55 | ||
52 | // qWarning("~OTodo " ); | 56 | // qWarning("~OTodo " ); |
53 | if ( data->deref() ) { | 57 | if ( data->deref() ) { |
@@ -142,32 +146,54 @@ QDate OTodo::dueDate()const | |||
142 | return data->date; | 146 | return data->date; |
143 | } | 147 | } |
144 | QDate OTodo::startDate()const { | 148 | QDate OTodo::startDate()const { |
145 | return data->start; | 149 | return data->start; |
146 | } | 150 | } |
147 | QDate OTodo::completedDate()const { | 151 | QDate OTodo::completedDate()const { |
148 | return data->completed; | 152 | return data->completed; |
149 | } | 153 | } |
150 | QString OTodo::description()const | 154 | QString OTodo::description()const |
151 | { | 155 | { |
152 | return data->desc; | 156 | return data->desc; |
153 | } | 157 | } |
158 | bool OTodo::hasState() const{ | ||
159 | if (!data->state ) return false; | ||
160 | return ( data->state->state() != OPimState::Undefined ); | ||
161 | } | ||
154 | OPimState OTodo::state()const { | 162 | OPimState OTodo::state()const { |
155 | return data->state; | 163 | if (!data->state ) { |
164 | OPimState state; | ||
165 | return state; | ||
166 | } | ||
167 | |||
168 | return (*data->state); | ||
169 | } | ||
170 | bool OTodo::hasRecurrence()const { | ||
171 | if (!data->recur) return false; | ||
172 | return data->recur->doesRecur(); | ||
156 | } | 173 | } |
157 | ORecur OTodo::recurrence()const { | 174 | ORecur OTodo::recurrence()const { |
158 | return data->recur; | 175 | if (!data->recur) return ORecur(); |
176 | |||
177 | return (*data->recur); | ||
178 | } | ||
179 | bool OTodo::hasMaintainer()const { | ||
180 | if (!data->maintainer) return false; | ||
181 | |||
182 | return (data->maintainer->mode() != OPimMaintainer::Undefined ); | ||
159 | } | 183 | } |
160 | OPimMaintainer OTodo::maintainer()const { | 184 | OPimMaintainer OTodo::maintainer()const { |
161 | return data->maintainer; | 185 | if (!data->maintainer) return OPimMaintainer(); |
186 | |||
187 | return (*data->maintainer); | ||
162 | } | 188 | } |
163 | void OTodo::setCompleted( bool completed ) | 189 | void OTodo::setCompleted( bool completed ) |
164 | { | 190 | { |
165 | changeOrModify(); | 191 | changeOrModify(); |
166 | data->isCompleted = completed; | 192 | data->isCompleted = completed; |
167 | } | 193 | } |
168 | void OTodo::setHasDueDate( bool hasDate ) | 194 | void OTodo::setHasDueDate( bool hasDate ) |
169 | { | 195 | { |
170 | changeOrModify(); | 196 | changeOrModify(); |
171 | data->hasDate = hasDate; | 197 | data->hasDate = hasDate; |
172 | } | 198 | } |
173 | void OTodo::setDescription(const QString &desc ) | 199 | void OTodo::setDescription(const QString &desc ) |
@@ -192,33 +218,43 @@ void OTodo::setDueDate( const QDate& date ) | |||
192 | data->date = date; | 218 | data->date = date; |
193 | } | 219 | } |
194 | void OTodo::setStartDate( const QDate& date ) { | 220 | void OTodo::setStartDate( const QDate& date ) { |
195 | changeOrModify(); | 221 | changeOrModify(); |
196 | data->start = date; | 222 | data->start = date; |
197 | } | 223 | } |
198 | void OTodo::setCompletedDate( const QDate& date ) { | 224 | void OTodo::setCompletedDate( const QDate& date ) { |
199 | changeOrModify(); | 225 | changeOrModify(); |
200 | data->completed = date; | 226 | data->completed = date; |
201 | } | 227 | } |
202 | void OTodo::setState( const OPimState& state ) { | 228 | void OTodo::setState( const OPimState& state ) { |
203 | changeOrModify(); | 229 | changeOrModify(); |
204 | data->state = state; | 230 | if (data->state ) |
231 | (*data->state) = state; | ||
232 | else | ||
233 | data->state = new OPimState( state ); | ||
205 | } | 234 | } |
206 | void OTodo::setRecurrence( const ORecur& rec) { | 235 | void OTodo::setRecurrence( const ORecur& rec) { |
207 | changeOrModify(); | 236 | changeOrModify(); |
208 | data->recur = rec; | 237 | if (data->recur ) |
238 | (*data->recur) = rec; | ||
239 | else | ||
240 | data->recur = new ORecur( rec ); | ||
209 | } | 241 | } |
210 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { | 242 | void OTodo::setMaintainer( const OPimMaintainer& pim ) { |
211 | changeOrModify(); | 243 | changeOrModify(); |
212 | data->maintainer = pim; | 244 | |
245 | if (data->maintainer ) | ||
246 | (*data->maintainer) = pim; | ||
247 | else | ||
248 | data->maintainer = new OPimMaintainer( pim ); | ||
213 | } | 249 | } |
214 | bool OTodo::isOverdue( ) | 250 | bool OTodo::isOverdue( ) |
215 | { | 251 | { |
216 | if( data->hasDate && !data->isCompleted) | 252 | if( data->hasDate && !data->isCompleted) |
217 | return QDate::currentDate() > data->date; | 253 | return QDate::currentDate() > data->date; |
218 | return false; | 254 | return false; |
219 | } | 255 | } |
220 | void OTodo::setProgress(ushort progress ) | 256 | void OTodo::setProgress(ushort progress ) |
221 | { | 257 | { |
222 | changeOrModify(); | 258 | changeOrModify(); |
223 | data->prog = progress; | 259 | data->prog = progress; |
224 | } | 260 | } |
@@ -251,26 +287,32 @@ QString OTodo::toRichText() const | |||
251 | if (hasDueDate() ){ | 287 | if (hasDueDate() ){ |
252 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; | 288 | text += "<b>" + QObject::tr( "Deadline:") + " </b>"; |
253 | text += dueDate().toString(); | 289 | text += dueDate().toString(); |
254 | text += "<br>"; | 290 | text += "<br>"; |
255 | } | 291 | } |
256 | 292 | ||
257 | text += "<b>" + QObject::tr( "Category:") + "</b> "; | 293 | text += "<b>" + QObject::tr( "Category:") + "</b> "; |
258 | text += categoryNames( "Todo List" ).join(", "); | 294 | text += categoryNames( "Todo List" ).join(", "); |
259 | text += "<br>"; | 295 | text += "<br>"; |
260 | 296 | ||
261 | return text; | 297 | return text; |
262 | } | 298 | } |
299 | bool OTodo::hasNotifiers()const { | ||
300 | if (!data->notifiers) return false; | ||
301 | return data->notifiers->isEmpty(); | ||
302 | } | ||
263 | OPimNotifyManager& OTodo::notifiers() { | 303 | OPimNotifyManager& OTodo::notifiers() { |
264 | return data->notifiers; | 304 | if (!data->notifiers ) |
305 | data->notifiers = new OPimNotifyManager; | ||
306 | return (*data->notifiers); | ||
265 | } | 307 | } |
266 | 308 | ||
267 | bool OTodo::operator<( const OTodo &toDoEvent )const{ | 309 | bool OTodo::operator<( const OTodo &toDoEvent )const{ |
268 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; | 310 | if( !hasDueDate() && !toDoEvent.hasDueDate() ) return true; |
269 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; | 311 | if( !hasDueDate() && toDoEvent.hasDueDate() ) return false; |
270 | if( hasDueDate() && toDoEvent.hasDueDate() ){ | 312 | if( hasDueDate() && toDoEvent.hasDueDate() ){ |
271 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide | 313 | if( dueDate() == toDoEvent.dueDate() ){ // let's the priority decide |
272 | return priority() < toDoEvent.priority(); | 314 | return priority() < toDoEvent.priority(); |
273 | }else{ | 315 | }else{ |
274 | return dueDate() < toDoEvent.dueDate(); | 316 | return dueDate() < toDoEvent.dueDate(); |
275 | } | 317 | } |
276 | } | 318 | } |
@@ -396,29 +438,38 @@ void OTodo::changeOrModify() { | |||
396 | * if you add something to the Data struct | 438 | * if you add something to the Data struct |
397 | * be sure to copy it here | 439 | * be sure to copy it here |
398 | */ | 440 | */ |
399 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { | 441 | void OTodo::copy( OTodoData* src, OTodoData* dest ) { |
400 | dest->date = src->date; | 442 | dest->date = src->date; |
401 | dest->isCompleted = src->isCompleted; | 443 | dest->isCompleted = src->isCompleted; |
402 | dest->hasDate = src->hasDate; | 444 | dest->hasDate = src->hasDate; |
403 | dest->priority = src->priority; | 445 | dest->priority = src->priority; |
404 | dest->desc = src->desc; | 446 | dest->desc = src->desc; |
405 | dest->sum = src->sum; | 447 | dest->sum = src->sum; |
406 | dest->extra = src->extra; | 448 | dest->extra = src->extra; |
407 | dest->prog = src->prog; | 449 | dest->prog = src->prog; |
408 | dest->state = src->state; | 450 | |
409 | dest->recur = src->recur; | 451 | if (src->state ) |
410 | dest->maintainer = src->maintainer; | 452 | dest->state = new OPimState( *src->state ); |
453 | |||
454 | if (src->recur ) | ||
455 | dest->recur = new ORecur( *src->recur ); | ||
456 | |||
457 | if (src->maintainer ) | ||
458 | dest->maintainer = new OPimMaintainer( *src->maintainer ) | ||
459 | ; | ||
411 | dest->start = src->start; | 460 | dest->start = src->start; |
412 | dest->completed = src->completed; | 461 | dest->completed = src->completed; |
413 | dest->notifiers = src->notifiers; | 462 | |
463 | if (src->notifiers ) | ||
464 | dest->notifiers = new OPimNotifyManager( *src->notifiers ); | ||
414 | } | 465 | } |
415 | QString OTodo::type() const { | 466 | QString OTodo::type() const { |
416 | return QString::fromLatin1("OTodo"); | 467 | return QString::fromLatin1("OTodo"); |
417 | } | 468 | } |
418 | QString OTodo::recordField(int /*id*/ )const { | 469 | QString OTodo::recordField(int /*id*/ )const { |
419 | return QString::null; | 470 | return QString::null; |
420 | } | 471 | } |
421 | 472 | ||
422 | int OTodo::rtti(){ | 473 | int OTodo::rtti(){ |
423 | return OPimResolver::TodoList; | 474 | return OPimResolver::TodoList; |
424 | } | 475 | } |