Commit e5ed9bdb authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

AkonadiConsole: Fix sorting items by date in Browser tab

BUG: 250091
FIXED-IN: 4.14.0
parent 9102b4b9
......@@ -311,3 +311,48 @@ void AkonadiBrowserModel::setItemDisplayMode( AkonadiBrowserModel::ItemDisplayMo
}
emit layoutChanged();
}
AkonadiBrowserSortModel::AkonadiBrowserSortModel( AkonadiBrowserModel *model, QObject *parent )
: QSortFilterProxyModel( parent )
, mBrowserModel( model )
{
}
AkonadiBrowserSortModel::~AkonadiBrowserSortModel()
{
}
bool AkonadiBrowserSortModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
{
if ( mBrowserModel->itemDisplayMode() == AkonadiBrowserModel::CalendarMode ) {
if ( left.column() == 1 || left.column() == 2 ) {
const Item leftItem = left.data( EntityTreeModel::ItemRole ).value<Item>();
const Item rightItem = right.data( EntityTreeModel::ItemRole ).value<Item>();
if ( !leftItem.hasPayload<IncidencePtr>() || !rightItem.hasPayload<IncidencePtr>() ) {
return false;
}
const IncidencePtr leftInc = leftItem.payload<IncidencePtr>();
const IncidencePtr rightInc = rightItem.payload<IncidencePtr>();
if ( left.column() == 1 ) {
return leftInc->dtStart() < rightInc->dtStart();
} else if ( left.column() == 2 ) {
return leftInc->dateTime( KCalCore::IncidenceBase::RoleEnd ) < rightInc->dateTime( KCalCore::IncidenceBase::RoleEnd );
}
}
} else if ( mBrowserModel->itemDisplayMode() == AkonadiBrowserModel::MailMode ) {
if ( left.column() == 2 ) {
const Item leftItem = left.data( EntityTreeModel::ItemRole ).value<Item>();
const Item rightItem = right.data( EntityTreeModel::ItemRole ).value<Item>();
if ( !leftItem.hasPayload<MessagePtr>() || !rightItem.hasPayload<MessagePtr>() ) {
return false;
}
const MessagePtr leftMail = leftItem.payload<MessagePtr>();
const MessagePtr rightMail = rightItem.payload<MessagePtr>();
return leftMail->date(false)->dateTime() < rightMail->date(false)->dateTime();
}
}
return QSortFilterProxyModel::lessThan( left, right );
}
......@@ -23,6 +23,8 @@
#include <akonadi/entitytreemodel.h>
#include <akonadi/changerecorder.h>
#include <QSortFilterProxyModel>
using namespace Akonadi;
class AkonadiBrowserModel : public EntityTreeModel
......@@ -60,7 +62,21 @@ private:
State *m_calendarState;
ItemDisplayMode m_itemDisplayMode;
};
class AkonadiBrowserSortModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit AkonadiBrowserSortModel( AkonadiBrowserModel *browserModel, QObject *parent = 0 );
~AkonadiBrowserSortModel();
protected:
bool lessThan( const QModelIndex &left, const QModelIndex &right ) const;
private:
AkonadiBrowserModel *mBrowserModel;
};
#endif
......@@ -156,10 +156,15 @@ BrowserWidget::BrowserWidget(KXmlGuiWindow *xmlGuiWindow, QWidget * parent) :
itemFilter->addMimeTypeExclusionFilter( Collection::mimeType() );
itemFilter->setHeaderGroup( EntityTreeModel::ItemListHeaders );
AkonadiBrowserSortModel *sortModel = new AkonadiBrowserSortModel( mBrowserModel, this );
sortModel->setDynamicSortFilter( true );
sortModel->setSourceModel( itemFilter );
const KConfigGroup group = KGlobal::config()->group( "FavoriteCollectionsModel" );
FavoriteCollectionsModel *favoritesModel = new FavoriteCollectionsModel( mBrowserModel, group, this );
favoritesView->setModel( favoritesModel );
QSplitter *splitter3 = new QSplitter( Qt::Vertical, this );
splitter3->setObjectName( "itemSplitter" );
splitter->addWidget( splitter3 );
......@@ -175,7 +180,7 @@ BrowserWidget::BrowserWidget(KXmlGuiWindow *xmlGuiWindow, QWidget * parent) :
QTimer::singleShot( 0, this, SLOT(modelChanged()) );
itemUi.itemView->setXmlGuiClient( xmlGuiWindow );
itemUi.itemView->setModel( itemFilter );
itemUi.itemView->setModel( sortModel );
itemUi.itemView->setSelectionMode( QAbstractItemView::ExtendedSelection );
connect( itemUi.itemView, SIGNAL(activated(QModelIndex)), SLOT(itemActivated(QModelIndex)) );
connect( itemUi.itemView, SIGNAL(clicked(QModelIndex)), SLOT(itemActivated(QModelIndex)) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment