Cute Chess 0.1
pgngameentrymodel.h
1/*
2 This file is part of Cute Chess.
3 Copyright (C) 2008-2018 Cute Chess authors
4
5 Cute Chess is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 Cute Chess is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with Cute Chess. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef PGN_GAME_ENTRY_MODEL_H
20#define PGN_GAME_ENTRY_MODEL_H
21
22#include <QAbstractItemModel>
23#include <QList>
24#include <QFuture>
25#include <QFutureWatcher>
26#include <pgngamefilter.h>
27class PgnGameEntry;
28
33{
34 Q_OBJECT
35
36 public:
38 PgnGameEntryModel(QObject* parent = nullptr);
39
41 const PgnGameEntry* entryAt(int row) const;
49 int entryCount() const;
54 int sourceIndex(int row) const;
56 void setEntries(const QList<const PgnGameEntry*>& entries);
57
58 // Inherited from QAbstractItemModel
59 virtual QModelIndex index(int row, int column,
60 const QModelIndex& parent = QModelIndex()) const;
61 virtual QModelIndex parent(const QModelIndex& index) const;
62 virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
63 virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
64 virtual QVariant data(const QModelIndex& index, int role) const;
65 virtual QVariant headerData(int section, Qt::Orientation orientation,
66 int role = Qt::DisplayRole) const;
67
68 public slots:
70 void setFilter(const PgnGameFilter& filter);
71
72 protected:
73 // Inherited from QAbstractItemModel
74 virtual bool canFetchMore(const QModelIndex& parent) const;
75 virtual void fetchMore(const QModelIndex& parent);
76
77 private slots:
78 void onResultsReady();
79
80 private:
81 void applyFilter(const PgnGameFilter& filter);
82
84 QVector<int> m_indexes;
85 int m_entryCount;
86 QFuture<int> m_filtered;
87 QFutureWatcher<int> m_watcher;
88 PgnGameFilter m_filter;
89};
90
91#endif // PGN_GAME_ENTRY_MODEL_H
void setFilter(const PgnGameFilter &filter)
Definition pgngameentrymodel.cpp:101
PgnGameEntryModel(QObject *parent=nullptr)
Definition pgngameentrymodel.cpp:42
int entryCount() const
Definition pgngameentrymodel.cpp:60
void setEntries(const QList< const PgnGameEntry * > &entries)
Definition pgngameentrymodel.cpp:65
int sourceIndex(int row) const
Definition pgngameentrymodel.cpp:55
const PgnGameEntry * entryAt(int row) const
Definition pgngameentrymodel.cpp:50
An entry in a PGN collection.
Definition pgngameentry.h:41
A filter for chess games in a PGN database.
Definition pgngamefilter.h:38