Store library in database.
[dorian] / model / sortedlibrary.cpp
1 #include "sortedlibrary.h"
2 #include "book.h"
3
4 SortedLibrary::SortedLibrary(QObject *parent): QSortFilterProxyModel(parent)
5 {
6     setSourceModel(Library::instance());
7 }
8
9 void SortedLibrary::sortBy(SortBy key)
10 {
11     mSortBy = key;
12 }
13
14 bool SortedLibrary::lessThan(const QModelIndex &left,
15                              const QModelIndex &right) const
16 {
17     Book *leftBook = Library::instance()->book(left);
18     Book *rightBook = Library::instance()->book(right);
19
20     QString leftString;
21     QString rightString;
22
23     switch (mSortBy) {
24     case SortByTitle:
25         leftString = leftBook->shortName();
26         rightString = rightBook->shortName();
27         break;
28     default:
29         leftString = leftBook->creators[0];
30         rightString = rightBook->creators[0];
31         break;
32     }
33
34     return QString::localeAwareCompare(leftString, rightString);
35 }