author | zecke <zecke> | 2002-10-18 20:49:06 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-18 20:49:06 (UTC) |
commit | a680c9464bbdea863b623b0449a15146ccaf66c0 (patch) (unidiff) | |
tree | 3a71b9172b3ebee7cdd07a9ed119fe9504580494 | |
parent | 1b84985ad03a39a82c5dc6a80a88e2c73ef14355 (diff) | |
download | opie-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
-rw-r--r-- | libopie/pim/otodoaccessxml.cpp | 120 | ||||
-rw-r--r-- | libopie2/opiepim/backend/otodoaccessxml.cpp | 120 |
2 files changed, 188 insertions, 52 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 | |||
@@ -409,3 +409,6 @@ QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | |||
409 | 409 | ||
410 | /* internal class for sorting */ | 410 | /* internal class for sorting |
411 | * | ||
412 | * Inspired by todoxmlio.cpp from TT | ||
413 | */ | ||
411 | 414 | ||
@@ -414,3 +417,39 @@ struct OTodoXMLContainer { | |||
414 | }; | 417 | }; |
415 | /* | 418 | |
419 | namespace { | ||
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: |
@@ -450,2 +489,4 @@ public: | |||
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; |
@@ -461,5 +502,4 @@ public: | |||
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; |
@@ -468,7 +508,4 @@ public: | |||
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; |
@@ -477,5 +514,4 @@ public: | |||
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; |
@@ -484,14 +520,4 @@ public: | |||
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; |
@@ -502,2 +528,6 @@ public: | |||
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 | ||
@@ -506,3 +536,41 @@ public: | |||
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 | } |
diff --git a/libopie2/opiepim/backend/otodoaccessxml.cpp b/libopie2/opiepim/backend/otodoaccessxml.cpp index 385fd27..591e467 100644 --- a/libopie2/opiepim/backend/otodoaccessxml.cpp +++ b/libopie2/opiepim/backend/otodoaccessxml.cpp | |||
@@ -409,3 +409,6 @@ QString OTodoAccessXML::toString( const QArray<int>& ints ) const { | |||
409 | 409 | ||
410 | /* internal class for sorting */ | 410 | /* internal class for sorting |
411 | * | ||
412 | * Inspired by todoxmlio.cpp from TT | ||
413 | */ | ||
411 | 414 | ||
@@ -414,3 +417,39 @@ struct OTodoXMLContainer { | |||
414 | }; | 417 | }; |
415 | /* | 418 | |
419 | namespace { | ||
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: |
@@ -450,2 +489,4 @@ public: | |||
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; |
@@ -461,5 +502,4 @@ public: | |||
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; |
@@ -468,7 +508,4 @@ public: | |||
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; |
@@ -477,5 +514,4 @@ public: | |||
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; |
@@ -484,14 +520,4 @@ public: | |||
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; |
@@ -502,2 +528,6 @@ public: | |||
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 | ||
@@ -506,3 +536,41 @@ public: | |||
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 | } |