summaryrefslogtreecommitdiff
path: root/libopie
authorzecke <zecke>2002-10-18 20:49:06 (UTC)
committer zecke <zecke>2002-10-18 20:49:06 (UTC)
commita680c9464bbdea863b623b0449a15146ccaf66c0 (patch) (unidiff)
tree3a71b9172b3ebee7cdd07a9ed119fe9504580494 /libopie
parent1b84985ad03a39a82c5dc6a80a88e2c73ef14355 (diff)
downloadopie-a680c9464bbdea863b623b0449a15146ccaf66c0.zip
opie-a680c9464bbdea863b623b0449a15146ccaf66c0.tar.gz
opie-a680c9464bbdea863b623b0449a15146ccaf66c0.tar.bz2
Fix sorting
Now if one columns equals another we try harder to find a difference Fixed DueDate sorting... This makes the UI more appealing
Diffstat (limited to 'libopie') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie/pim/otodoaccessxml.cpp120
1 files changed, 94 insertions, 26 deletions
diff --git a/libopie/pim/otodoaccessxml.cpp b/libopie/pim/otodoaccessxml.cpp
index 385fd27..591e467 100644
--- a/libopie/pim/otodoaccessxml.cpp
+++ b/libopie/pim/otodoaccessxml.cpp
@@ -407,12 +407,51 @@ QString OTodoAccessXML::toString( const QArray<int>& ints ) const {
407 return Qtopia::Record::idsToString( ints ); 407 return Qtopia::Record::idsToString( ints );
408} 408}
409 409
410/* internal class for sorting */ 410/* internal class for sorting
411 *
412 * Inspired by todoxmlio.cpp from TT
413 */
411 414
412struct OTodoXMLContainer { 415struct OTodoXMLContainer {
413 OTodo todo; 416 OTodo todo;
414}; 417};
415 /* 418
419namespace {
420 inline QString string( const OTodo& todo) {
421 return todo.summary().isEmpty() ?
422 todo.description().left(20 ) :
423 todo.summary();
424 }
425 inline int completed( const OTodo& todo1, const OTodo& todo2) {
426 int ret = 0;
427 if ( todo1.isCompleted() ) ret++;
428 if ( todo2.isCompleted() ) ret--;
429 return ret;
430 }
431 inline int priority( const OTodo& t1, const OTodo& t2) {
432 return ( t1.priority() - t2.priority() );
433 }
434 inline int description( const OTodo& t1, const OTodo& t2) {
435 return QString::compare( string(t1), string(t2) );
436 }
437 inline int deadline( const OTodo& t1, const OTodo& t2) {
438 int ret = 0;
439 if ( t1.hasDueDate() &&
440 t2.hasDueDate() )
441 ret = t2.dueDate().daysTo( t1.dueDate() );
442 else if ( t1.hasDueDate() )
443 ret = -1;
444 else if ( t2.hasDueDate() )
445 ret = 1;
446 else
447 ret = 0;
448
449 return ret;
450 }
451
452};
453
454/*
416 * Returns: 455 * Returns:
417 * 0 if item1 == item2 456 * 0 if item1 == item2
418 * 457 *
@@ -448,6 +487,8 @@ public:
448 * 487 *
449 */ 488 */
450 int compareItems( Item d1, Item d2 ) { 489 int compareItems( Item d1, Item d2 ) {
490 bool seComp, sePrio, seDesc, seDeadline;
491 seComp = sePrio = seDeadline = seDesc = false;
451 int ret =0; 492 int ret =0;
452 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1; 493 OTodoXMLContainer* con1 = (OTodoXMLContainer*)d1;
453 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2; 494 OTodoXMLContainer* con2 = (OTodoXMLContainer*)d2;
@@ -459,52 +500,79 @@ public:
459 switch ( m_sort ) { 500 switch ( m_sort ) {
460 /* completed */ 501 /* completed */
461 case 0: { 502 case 0: {
462 ret = 0; 503 ret = completed( con1->todo, con2->todo );
463 if ( con1->todo.isCompleted() ) ret++; 504 seComp = TRUE;
464 if ( con2->todo.isCompleted() ) ret--;
465 break; 505 break;
466 } 506 }
467 /* priority */ 507 /* priority */
468 case 1: { 508 case 1: {
469 ret = con1->todo.priority() - con2->todo.priority(); 509 ret = priority( con1->todo, con2->todo );
470 qWarning(" priority %d %d %d", ret, 510 sePrio = TRUE;
471 con1->todo.priority(),
472 con2->todo.priority()
473 );
474 break; 511 break;
475 } 512 }
476 /* description */ 513 /* description */
477 case 2: { 514 case 2: {
478 QString str1 = string( con1->todo ); 515 ret = description( con1->todo, con2->todo );
479 QString str2 = string( con2->todo ); 516 seDesc = TRUE;
480 ret = QString::compare( str1, str2 );
481 break; 517 break;
482 } 518 }
483 /* deadline */ 519 /* deadline */
484 case 3: { 520 case 3: {
485 /* either bot got a dueDate 521 ret = deadline( con1->todo, con2->todo );
486 * or one of them got one 522 seDeadline = TRUE;
487 */
488 if ( con1->todo.hasDueDate() &&
489 con2->todo.hasDueDate() )
490 ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() );
491
492
493 else if ( con1->todo.hasDueDate() )
494 ret = -1;
495 else if ( con2->todo.hasDueDate() )
496 ret = 0;
497 break; 523 break;
498 } 524 }
499 default: 525 default:
500 ret = 0; 526 ret = 0;
501 break; 527 break;
502 }; 528 };
529 /*
530 * FIXME do better sorting if the first sort criteria
531 * ret equals 0 start with complete and so on...
532 */
503 533
504 /* twist it we're not ascending*/ 534 /* twist it we're not ascending*/
505 if (!m_asc) 535 if (!m_asc)
506 ret = ret * -1; 536 ret = ret * -1;
507 return ret; 537
538 if ( ret )
539 return ret;
540
541 // default did not gave difference let's try it other way around
542 /*
543 * General try if already checked if not test
544 * and return
545 * 1.Completed
546 * 2.Priority
547 * 3.Description
548 * 4.DueDate
549 */
550 if (!seComp ) {
551 if ( (ret = completed( con1->todo, con2->todo ) ) ) {
552 if (!m_asc ) ret *= -1;
553 return ret;
554 }
555 }
556 if (!sePrio ) {
557 if ( (ret = priority( con1->todo, con2->todo ) ) ) {
558 if (!m_asc ) ret *= -1;
559 return ret;
560 }
561 }
562 if (!seDesc ) {
563 if ( (ret = description(con1->todo, con2->todo ) ) ) {
564 if (!m_asc) ret *= -1;
565 return ret;
566 }
567 }
568 if (!seDeadline) {
569 if ( (ret = deadline( con1->todo, con2->todo ) ) ) {
570 if (!m_asc) ret *= -1;
571 return ret;
572 }
573 }
574
575 return 0;
508 } 576 }
509 private: 577 private:
510 bool m_asc; 578 bool m_asc;