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