File indexing completed on 2024-05-19 05:19:22
0001 /* 0002 This file is part of KJots. 0003 0004 SPDX-FileCopyrightText: 2020 Igor Poboiko <igor.poboiko@gmail.com> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "notesortproxymodel.h" 0010 0011 #include <akonadi_version.h> 0012 #include <Akonadi/EntityTreeModel> 0013 0014 #include "noteshared/notepinattribute.h" 0015 0016 using namespace Akonadi; 0017 0018 NoteSortProxyModel::NoteSortProxyModel(QObject *parent) 0019 : QSortFilterProxyModel(parent) 0020 { 0021 setDynamicSortFilter(true); 0022 } 0023 0024 bool NoteSortProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 0025 { 0026 0027 const Item leftItem = left.data(EntityTreeModel::ItemRole).value<Item>(); 0028 const Item rightItem = right.data(EntityTreeModel::ItemRole).value<Item>(); 0029 const bool leftPinned = leftItem.hasAttribute<NoteShared::NotePinAttribute>(); 0030 const bool rightPinned = rightItem.hasAttribute<NoteShared::NotePinAttribute>(); 0031 0032 if (!leftPinned && rightPinned) { 0033 return true; 0034 } 0035 if (!rightPinned && leftPinned) { 0036 return false; 0037 } 0038 0039 return QSortFilterProxyModel::lessThan(left, right); 0040 } 0041 0042 #include "moc_notesortproxymodel.cpp"