author | zecke <zecke> | 2002-09-25 11:59:24 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-25 11:59:24 (UTC) |
commit | 38240090027bd68d8dd15d7d46ecf17792edb732 (patch) (unidiff) | |
tree | 589ef486d7169c57592ed8667f6c84d43f882d48 /libopie/pim/otodoaccessxml.cpp | |
parent | 5f2dd0a2340914b4983ebce3813187034e2cb9dc (diff) | |
download | opie-38240090027bd68d8dd15d7d46ecf17792edb732.zip opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.gz opie-38240090027bd68d8dd15d7d46ecf17792edb732.tar.bz2 |
Add a sort function and filter function to TodoAccess
This would allow us todo a paint hack in QTable
Diffstat (limited to 'libopie/pim/otodoaccessxml.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp index 5fe733c..692483e 100644 --- a/libopie/pim/otodoaccessxml.cpp +++ b/libopie/pim/otodoaccessxml.cpp | |||
@@ -1,4 +1,5 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qvector.h> | ||
2 | 3 | ||
3 | #include <qpe/global.h> | 4 | #include <qpe/global.h> |
4 | #include <qpe/stringutil.h> | 5 | #include <qpe/stringutil.h> |
@@ -256,6 +257,7 @@ OTodo OTodoAccessXML::todo( QAsciiDict<int>* dict, Opie::XMLElement* element)con | |||
256 | ev.setSummary( it.data() ); | 257 | ev.setSummary( it.data() ); |
257 | break; | 258 | break; |
258 | case OTodo::Priority: | 259 | case OTodo::Priority: |
260 | qWarning("ParsePriority " + it.data() ); | ||
259 | ev.setPriority( it.data().toInt() ); | 261 | ev.setPriority( it.data().toInt() ); |
260 | break; | 262 | break; |
261 | case OTodo::DateDay: | 263 | case OTodo::DateDay: |
@@ -364,3 +366,146 @@ QString OTodoAccessXML::toString( const OTodo& ev )const { | |||
364 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | 366 | QString OTodoAccessXML::toString( const QArray<int>& ints ) const { |
365 | return Qtopia::Record::idsToString( ints ); | 367 | return Qtopia::Record::idsToString( ints ); |
366 | } | 368 | } |
369 | |||
370 | /* internal class for sorting */ | ||
371 | |||
372 | struct OTodoXMLContainer { | ||
373 | OTodo todo; | ||
374 | }; | ||
375 | /* | ||
376 | * Returns: | ||
377 | * 0 if item1 == item2 | ||
378 | * | ||
379 | * non-zero if item1 != item2 | ||
380 | * | ||
381 | * This function returns int rather than bool so that reimplementations | ||
382 | * can return one of three values and use it to sort by: | ||
383 | * | ||
384 | * 0 if item1 == item2 | ||
385 | * | ||
386 | * > 0 (positive integer) if item1 > item2 | ||
387 | * | ||
388 | * < 0 (negative integer) if item1 < item2 | ||
389 | * | ||
390 | */ | ||
391 | class OTodoXMLVector : public QVector<OTodoXMLContainer> { | ||
392 | public: | ||
393 | OTodoXMLVector(int size, bool asc, int sort) | ||
394 | : QVector<OTodoXMLContainer>( size ) | ||
395 | { | ||
396 | setAutoDelete( true ); | ||
397 | m_asc = asc; | ||
398 | m_sort = sort; | ||
399 | } | ||
400 | /* return the summary/description */ | ||
401 | QString string( const OTodo& todo) { | ||
402 | return todo.summary().isEmpty() ? | ||
403 | todo.description().left(20 ) : | ||
404 | todo.summary(); | ||
405 | } | ||
406 | /** | ||
407 | * we take the sortorder( switch on it ) | ||
408 | * | ||
409 | */ | ||
410 | int compareItems( Item d1, Item d2 ) { | ||
411 | qWarning("compare items"); | ||
412 | int ret =0; | ||
413 | OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; | ||
414 | OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; | ||
415 | |||
416 | /* same item */ | ||
417 | if ( con1->todo.uid() == con2->todo.uid() ) | ||
418 | return 0; | ||
419 | qWarning("m_sort %d", m_sort ); | ||
420 | |||
421 | switch ( m_sort ) { | ||
422 | /* completed */ | ||
423 | case 0: { | ||
424 | ret = 0; | ||
425 | if ( con1->todo.isCompleted() ) ret++; | ||
426 | if ( con2->todo.isCompleted() ) ret--; | ||
427 | break; | ||
428 | } | ||
429 | /* priority */ | ||
430 | case 1: { | ||
431 | ret = con1->todo.priority() - con2->todo.priority(); | ||
432 | qWarning(" priority %d %d %d", ret, | ||
433 | con1->todo.priority(), | ||
434 | con2->todo.priority() | ||
435 | ); | ||
436 | break; | ||
437 | } | ||
438 | /* description */ | ||
439 | case 2: { | ||
440 | QString str1 = string( con1->todo ); | ||
441 | QString str2 = string( con2->todo ); | ||
442 | ret = QString::compare( str1, str2 ); | ||
443 | break; | ||
444 | } | ||
445 | /* deadline */ | ||
446 | case 3: { | ||
447 | /* either bot got a dueDate | ||
448 | * or one of them got one | ||
449 | */ | ||
450 | if ( con1->todo.hasDueDate() && | ||
451 | con2->todo.hasDueDate() ) | ||
452 | ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); | ||
453 | else if ( con1->todo.hasDueDate() ) | ||
454 | ret = -1; | ||
455 | else if ( con2->todo.hasDueDate() ) | ||
456 | ret = 0; | ||
457 | break; | ||
458 | } | ||
459 | default: | ||
460 | ret = 0; | ||
461 | break; | ||
462 | }; | ||
463 | |||
464 | /* twist it we're not ascending*/ | ||
465 | if (!m_asc) | ||
466 | ret = ret * -1; | ||
467 | return ret; | ||
468 | } | ||
469 | private: | ||
470 | bool m_asc; | ||
471 | int m_sort; | ||
472 | |||
473 | }; | ||
474 | |||
475 | QArray<int> OTodoAccessXML::sorted( bool asc, int sortOrder, | ||
476 | int sortFilter, int cat ) { | ||
477 | OTodoXMLVector vector(m_events.count(), asc,sortOrder ); | ||
478 | QMap<int, OTodo>::Iterator it; | ||
479 | int item = 0; | ||
480 | |||
481 | bool bCat = sortFilter & 1 ? true : false; | ||
482 | bool bOver = sortFilter & 0 ? true : false; | ||
483 | bool bOnly = split & 2 ? true : false; | ||
484 | for ( it = m_events.begin(); it != m_events.end(); ++it ) { | ||
485 | |||
486 | /* show category */ | ||
487 | if ( bCat ) | ||
488 | if (!(*it).categories().contains( cat ) ) | ||
489 | continue; | ||
490 | /* isOverdue but we should not show overdue */ | ||
491 | if ( (*it).isOverdue() && ( !bOver || !bOnly ) ) | ||
492 | continue; | ||
493 | if ( !(*it).isOverdue() && bOnly ) | ||
494 | continue; | ||
495 | |||
496 | |||
497 | OTodoXMLContainer* con = new OTodoXMLContainer(); | ||
498 | con->todo = (*it); | ||
499 | vector.insert(item, con ); | ||
500 | item++; | ||
501 | } | ||
502 | vector.resize( item ); | ||
503 | /* sort it now */ | ||
504 | vector.sort(); | ||
505 | /* now get the uids */ | ||
506 | QArray<int> array( vector.count() ); | ||
507 | for (uint i= 0; i < vector.count(); i++ ) { | ||
508 | array[i] = ( vector.at(i) )->todo.uid(); | ||
509 | } | ||
510 | return array; | ||
511 | }; | ||