1 /***************************************************************************
2     Copyright (C) 2008-2009 Robby Stephenson <robby@periapsis.org>
3  ***************************************************************************/
4 
5 /***************************************************************************
6  *                                                                         *
7  *   This program is free software; you can redistribute it and/or         *
8  *   modify it under the terms of the GNU General Public License as        *
9  *   published by the Free Software Foundation; either version 2 of        *
10  *   the License or (at your option) version 3 or any later version        *
11  *   accepted by the membership of KDE e.V. (or its successor approved     *
12  *   by the membership of KDE e.V.), which shall act as a proxy            *
13  *   defined in Section 14 of version 3 of the license.                    *
14  *                                                                         *
15  *   This program is distributed in the hope that it will be useful,       *
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
18  *   GNU General Public License for more details.                          *
19  *                                                                         *
20  *   You should have received a copy of the GNU General Public License     *
21  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
22  *                                                                         *
23  ***************************************************************************/
24 
25 #ifndef TELLICO_GROUPSORTMODEL_H
26 #define TELLICO_GROUPSORTMODEL_H
27 
28 #include "abstractsortmodel.h"
29 
30 namespace Tellico {
31   namespace Data {
32     class EntryGroup;
33   }
34 
35 class StringComparison;
36 class FieldComparison;
37 
38 /**
39  * @author Robby Stephenson
40  */
41 class GroupSortModel : public AbstractSortModel {
42 Q_OBJECT
43 
44 public:
45   GroupSortModel(QObject* parent);
46   virtual ~GroupSortModel();
47 
48   virtual void setSourceModel(QAbstractItemModel* sourceModel) Q_DECL_OVERRIDE;
49   QString entrySortField() const;
50   void setEntrySortField(const QString& fieldName);
51 
52 protected:
53   virtual bool lessThan(const QModelIndex& left, const QModelIndex& right) const Q_DECL_OVERRIDE;
54 
55 private Q_SLOTS:
56   void clearComparisons();
57 
58 private:
59   FieldComparison* getEntryComparison(const QModelIndex& index, const QString& fieldName) const;
60   StringComparison* getGroupComparison(Data::EntryGroup* group) const;
61 
62   mutable FieldComparison* m_entryComparison;
63   mutable StringComparison* m_groupComparison;
64 };
65 
66 } // end namespace
67 #endif
68