[Korganizer-devel] [Bug 167114] Ability to sort to-do list by completion date

Sergio Martins iamsergio at gmail.com
Sat Jan 15 02:35:31 CET 2011


https://bugs.kde.org/show_bug.cgi?id=167114


Sergio Martins <iamsergio at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED




--- Comment #3 from Sergio Martins <iamsergio gmail com>  2011-01-15 02:35:23 ---
commit 3bcdde2aa6c1043fbd1cb0d18e02ff5f50c63f37
branch master
Author: Sergio Martins <iamsergio at gmail.com>
Date:   Sat Jan 15 01:31:57 2011 +0000

    When sorting by completion, untie completed to-dos by completion date.

    Also, "sort completed to-dos separately" only makes sense if we're not
sorting by completion date, so I fixed this too.
    BUG: 167114

diff --git a/korganizer/views/todoview/kotodoviewsortfilterproxymodel.cpp
b/korganizer/views/todoview/kotodoviewsortfilterproxymodel.cpp
index 0262b2a..81a05f7 100644
--- a/korganizer/views/todoview/kotodoviewsortfilterproxymodel.cpp
+++ b/korganizer/views/todoview/kotodoviewsortfilterproxymodel.cpp
@@ -74,7 +74,7 @@ bool KOTodoViewSortFilterProxyModel::filterAcceptsRow(
 bool KOTodoViewSortFilterProxyModel::lessThan( const QModelIndex &left,
                                                const QModelIndex &right )
const
 {
-  if ( KOPrefs::instance()->sortCompletedTodosSeparately() ) {
+  if ( KOPrefs::instance()->sortCompletedTodosSeparately() && left.column() !=
KOTodoModel::PercentColumn ) {
     QModelIndex cLeft = left.sibling( left.row(), KOTodoModel::PercentColumn
);
     QModelIndex cRight = right.sibling( right.row(),
KOTodoModel::PercentColumn );

@@ -122,6 +122,11 @@ bool KOTodoViewSortFilterProxyModel::lessThan( const
QModelIndex &left,
         return fallbackComparison == 1;
       }
     }
+  } else if ( right.column() == KOTodoModel::PercentColumn ) {
+    const int comparison = compareCompletion( left, right );
+    if ( comparison != 0 ) {
+      return comparison == -1;
+    }
   }

   if ( left.data() == right.data() ) {
@@ -192,6 +197,33 @@ int KOTodoViewSortFilterProxyModel::compareDueDates( const
QModelIndex &left, co
  *  0 - equal
  *  1 - bigger than
  */
+int KOTodoViewSortFilterProxyModel::compareCompletion( const QModelIndex
&left, const QModelIndex &right ) const
+{
+  Q_ASSERT( left.column() == KOTodoModel::PercentColumn );
+  Q_ASSERT( right.column() == KOTodoModel::PercentColumn );
+
+  const int leftValue = sourceModel()->data( left ).toInt();
+  const int rightValue = sourceModel()->data( right ).toInt();
+
+  if ( leftValue == 100 && rightValue == 100 ) {
+    // Untie with the completion date
+    const Todo::Ptr leftTodo = CalendarSupport::todo( left.data(
KOTodoModel::TodoRole ).value<Akonadi::Item>() );
+    const Todo::Ptr rightTodo = CalendarSupport::todo( right.data(
KOTodoModel::TodoRole ). value<Akonadi::Item>() );
+
+    if ( !leftTodo || !rightTodo ) {
+      return 0;
+    } else {
+      return ( leftTodo->completed() > rightTodo->completed() ) ? -1 : 1;
+    }
+  } else {
+    return ( leftValue < rightValue ) ? -1 : 1;
+  }
+}
+
+/* -1 - less than
+ *  0 - equal
+ *  1 - bigger than
+ */
 int KOTodoViewSortFilterProxyModel::comparePriorities( const QModelIndex
&left, const QModelIndex &right ) const
 {
   Q_ASSERT( left.column() == KOTodoModel::PriorityColumn );
diff --git a/korganizer/views/todoview/kotodoviewsortfilterproxymodel.h
b/korganizer/views/todoview/kotodoviewsortfilterproxymodel.h
index 8e14ff2..517667c 100644
--- a/korganizer/views/todoview/kotodoviewsortfilterproxymodel.h
+++ b/korganizer/views/todoview/kotodoviewsortfilterproxymodel.h
@@ -51,6 +51,7 @@ class KOTodoViewSortFilterProxyModel : public
QSortFilterProxyModel
   private:
     int compareDueDates( const QModelIndex &left, const QModelIndex &right )
const;
     int comparePriorities( const QModelIndex &left, const QModelIndex &right )
const;
+    int compareCompletion( const QModelIndex &left, const QModelIndex &right )
const;
     QStringList mCategories;
     Qt::SortOrder mSortOrder;
 };

-- 
Configure bugmail: https://bugs.kde.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.


More information about the Korganizer-devel mailing list