author | zecke <zecke> | 2002-10-18 20:49:06 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-10-18 20:49:06 (UTC) |
commit | a680c9464bbdea863b623b0449a15146ccaf66c0 (patch) (side-by-side diff) | |
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 { -/* internal class for sorting */ +/* internal class for sorting + * + * Inspired by todoxmlio.cpp from TT + */ @@ -414,3 +417,39 @@ struct OTodoXMLContainer { }; - /* + +namespace { + inline QString string( const OTodo& todo) { + return todo.summary().isEmpty() ? + todo.description().left(20 ) : + todo.summary(); + } + inline int completed( const OTodo& todo1, const OTodo& todo2) { + int ret = 0; + if ( todo1.isCompleted() ) ret++; + if ( todo2.isCompleted() ) ret--; + return ret; + } + inline int priority( const OTodo& t1, const OTodo& t2) { + return ( t1.priority() - t2.priority() ); + } + inline int description( const OTodo& t1, const OTodo& t2) { + return QString::compare( string(t1), string(t2) ); + } + inline int deadline( const OTodo& t1, const OTodo& t2) { + int ret = 0; + if ( t1.hasDueDate() && + t2.hasDueDate() ) + ret = t2.dueDate().daysTo( t1.dueDate() ); + else if ( t1.hasDueDate() ) + ret = -1; + else if ( t2.hasDueDate() ) + ret = 1; + else + ret = 0; + + return ret; + } + +}; + +/* * Returns: @@ -450,2 +489,4 @@ public: int compareItems( Item d1, Item d2 ) { + bool seComp, sePrio, seDesc, seDeadline; + seComp = sePrio = seDeadline = seDesc = false; int ret =0; @@ -461,5 +502,4 @@ public: case 0: { - ret = 0; - if ( con1->todo.isCompleted() ) ret++; - if ( con2->todo.isCompleted() ) ret--; + ret = completed( con1->todo, con2->todo ); + seComp = TRUE; break; @@ -468,7 +508,4 @@ public: case 1: { - ret = con1->todo.priority() - con2->todo.priority(); - qWarning(" priority %d %d %d", ret, - con1->todo.priority(), - con2->todo.priority() - ); + ret = priority( con1->todo, con2->todo ); + sePrio = TRUE; break; @@ -477,5 +514,4 @@ public: case 2: { - QString str1 = string( con1->todo ); - QString str2 = string( con2->todo ); - ret = QString::compare( str1, str2 ); + ret = description( con1->todo, con2->todo ); + seDesc = TRUE; break; @@ -484,14 +520,4 @@ public: case 3: { - /* either bot got a dueDate - * or one of them got one - */ - if ( con1->todo.hasDueDate() && - con2->todo.hasDueDate() ) - ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); - - - else if ( con1->todo.hasDueDate() ) - ret = -1; - else if ( con2->todo.hasDueDate() ) - ret = 0; + ret = deadline( con1->todo, con2->todo ); + seDeadline = TRUE; break; @@ -502,2 +528,6 @@ public: }; + /* + * FIXME do better sorting if the first sort criteria + * ret equals 0 start with complete and so on... + */ @@ -506,3 +536,41 @@ public: ret = ret * -1; - return ret; + + if ( ret ) + return ret; + + // default did not gave difference let's try it other way around + /* + * General try if already checked if not test + * and return + * 1.Completed + * 2.Priority + * 3.Description + * 4.DueDate + */ + if (!seComp ) { + if ( (ret = completed( con1->todo, con2->todo ) ) ) { + if (!m_asc ) ret *= -1; + return ret; + } + } + if (!sePrio ) { + if ( (ret = priority( con1->todo, con2->todo ) ) ) { + if (!m_asc ) ret *= -1; + return ret; + } + } + if (!seDesc ) { + if ( (ret = description(con1->todo, con2->todo ) ) ) { + if (!m_asc) ret *= -1; + return ret; + } + } + if (!seDeadline) { + if ( (ret = deadline( con1->todo, con2->todo ) ) ) { + if (!m_asc) ret *= -1; + return ret; + } + } + + return 0; } 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 { -/* internal class for sorting */ +/* internal class for sorting + * + * Inspired by todoxmlio.cpp from TT + */ @@ -414,3 +417,39 @@ struct OTodoXMLContainer { }; - /* + +namespace { + inline QString string( const OTodo& todo) { + return todo.summary().isEmpty() ? + todo.description().left(20 ) : + todo.summary(); + } + inline int completed( const OTodo& todo1, const OTodo& todo2) { + int ret = 0; + if ( todo1.isCompleted() ) ret++; + if ( todo2.isCompleted() ) ret--; + return ret; + } + inline int priority( const OTodo& t1, const OTodo& t2) { + return ( t1.priority() - t2.priority() ); + } + inline int description( const OTodo& t1, const OTodo& t2) { + return QString::compare( string(t1), string(t2) ); + } + inline int deadline( const OTodo& t1, const OTodo& t2) { + int ret = 0; + if ( t1.hasDueDate() && + t2.hasDueDate() ) + ret = t2.dueDate().daysTo( t1.dueDate() ); + else if ( t1.hasDueDate() ) + ret = -1; + else if ( t2.hasDueDate() ) + ret = 1; + else + ret = 0; + + return ret; + } + +}; + +/* * Returns: @@ -450,2 +489,4 @@ public: int compareItems( Item d1, Item d2 ) { + bool seComp, sePrio, seDesc, seDeadline; + seComp = sePrio = seDeadline = seDesc = false; int ret =0; @@ -461,5 +502,4 @@ public: case 0: { - ret = 0; - if ( con1->todo.isCompleted() ) ret++; - if ( con2->todo.isCompleted() ) ret--; + ret = completed( con1->todo, con2->todo ); + seComp = TRUE; break; @@ -468,7 +508,4 @@ public: case 1: { - ret = con1->todo.priority() - con2->todo.priority(); - qWarning(" priority %d %d %d", ret, - con1->todo.priority(), - con2->todo.priority() - ); + ret = priority( con1->todo, con2->todo ); + sePrio = TRUE; break; @@ -477,5 +514,4 @@ public: case 2: { - QString str1 = string( con1->todo ); - QString str2 = string( con2->todo ); - ret = QString::compare( str1, str2 ); + ret = description( con1->todo, con2->todo ); + seDesc = TRUE; break; @@ -484,14 +520,4 @@ public: case 3: { - /* either bot got a dueDate - * or one of them got one - */ - if ( con1->todo.hasDueDate() && - con2->todo.hasDueDate() ) - ret = con1->todo.dueDate().daysTo( con2->todo.dueDate() ); - - - else if ( con1->todo.hasDueDate() ) - ret = -1; - else if ( con2->todo.hasDueDate() ) - ret = 0; + ret = deadline( con1->todo, con2->todo ); + seDeadline = TRUE; break; @@ -502,2 +528,6 @@ public: }; + /* + * FIXME do better sorting if the first sort criteria + * ret equals 0 start with complete and so on... + */ @@ -506,3 +536,41 @@ public: ret = ret * -1; - return ret; + + if ( ret ) + return ret; + + // default did not gave difference let's try it other way around + /* + * General try if already checked if not test + * and return + * 1.Completed + * 2.Priority + * 3.Description + * 4.DueDate + */ + if (!seComp ) { + if ( (ret = completed( con1->todo, con2->todo ) ) ) { + if (!m_asc ) ret *= -1; + return ret; + } + } + if (!sePrio ) { + if ( (ret = priority( con1->todo, con2->todo ) ) ) { + if (!m_asc ) ret *= -1; + return ret; + } + } + if (!seDesc ) { + if ( (ret = description(con1->todo, con2->todo ) ) ) { + if (!m_asc) ret *= -1; + return ret; + } + } + if (!seDeadline) { + if ( (ret = deadline( con1->todo, con2->todo ) ) ) { + if (!m_asc) ret *= -1; + return ret; + } + } + + return 0; } |