-
Notifications
You must be signed in to change notification settings - Fork 5
/
model.h
110 lines (75 loc) · 2.84 KB
/
model.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright 2016 Adam Reichold
This file is part of QMediathekView.
QMediathekView is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
QMediathekView is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with QMediathekView. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef MODEL_H
#define MODEL_H
#include <QAbstractTableModel>
#include <QCache>
class QStringListModel;
#include "schema.h"
#include "database.h"
namespace QMediathekView
{
class Model : public QAbstractTableModel
{
Q_OBJECT
Q_DISABLE_COPY(Model)
public:
Model(Database& database, QObject* parent = 0);
~Model();
public:
int columnCount(const QModelIndex& parent) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
int rowCount(const QModelIndex& parent) const override;
QModelIndex index(int row, int column, const QModelIndex& parent) const override;
QVariant data(const QModelIndex& index, int role) const override;
void filter(const QString& channel, const QString& topic, const QString& title);
void sort(int column, Qt::SortOrder order) override;
protected:
bool canFetchMore(const QModelIndex& parent) const override;
void fetchMore(const QModelIndex& parent) override;
public:
QAbstractItemModel* channels() const;
QAbstractItemModel* topics() const;
public:
QString title(const QModelIndex& index) const;
QString description(const QModelIndex& index) const;
QString website(const QModelIndex& index) const;
QString url(const QModelIndex& index) const;
QString urlSmall(const QModelIndex& index) const;
QString urlLarge(const QModelIndex& index) const;
public:
void update();
private:
const Database& m_database;
QString m_channel;
QString m_topic;
QString m_title;
Database::SortColumn m_sortColumn = Database::SortColumn::SortChannel;
Database::SortOrder m_sortOrder = Database::SortOrder::SortAscending;
QVector< quintptr > m_id;
int m_fetched = 0;
void query();
mutable QCache< quintptr, Show > m_cache;
template< typename Member >
using ResultOf = typename std::decay< typename std::result_of< Member(Show) >::type >::type;
template< typename Member >
ResultOf< Member > fetchShow(const quintptr id, Member member) const;
QStringListModel* m_channels;
QStringListModel* m_topics;
void fetchChannels();
void fetchTopics();
};
} // QMediathekView
#endif // MODEL_H