Summary: | Ability to sort to-do list by completion date | ||
---|---|---|---|
Product: | [Applications] korganizer | Reporter: | Socceroos <skduff> |
Component: | general | Assignee: | kdepim bugs <kdepim-bugs> |
Status: | RESOLVED FIXED | ||
Severity: | wishlist | CC: | winter |
Priority: | NOR | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Platform: | Ubuntu | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
Description
Socceroos
2008-07-21 01:50:42 UTC
Do you mean sorting by the due date, or the actual date the to-do was completed? Allen, the actual date the to-do was completed. If you were able to use this information you could create some nifty reports on your efficiency. commit 3bcdde2aa6c1043fbd1cb0d18e02ff5f50c63f37 branch master Author: Sergio Martins <iamsergio@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; }; |