-
Notifications
You must be signed in to change notification settings - Fork 0
/
boardmodel.h
62 lines (49 loc) · 1.43 KB
/
boardmodel.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
#ifndef BOARD_H
#define BOARD_H
#include <QAbstractListModel>
#include <QObject>
#include <QTime>
#include <QVector>
#include "piece.h"
#include "qqml.h"
#include "piecesmodel.h"
class PiecesModel;
class BoardModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(PiecesModel* pieces READ pieces CONSTANT)
Q_PROPERTY(int turn READ turn NOTIFY turnChanged)
public:
enum BoardRole {
SquareColorRole = Qt::UserRole + 1,
CellCoordRole,
BoardIndexRole,
PieceRole,
RankRole,
FileRole,
MoveRole,
CaptureRole
};
// Q_ENUM(BoardRole)
BoardModel(QObject *parent = nullptr);
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
QHash<int, QByteArray> roleNames() const;
void setActivePiece(int index);
void toggleTurn();
inline PiecesModel* pieces() const { return m_pieces; }
inline int turn() const { return m_turn; }
public slots:
void addPiece(QByteArray p);
void initFromFEN(QByteArray fen);
void makeMove(int sourceIndex, int destiantionIndex, QTime timestamp);
void appendHistoryState(QByteArray sourcePos, QByteArray destinationPos, int capturedIndex, QTime timestamp, int type);
void clear();
signals:
void turnChanged();
private:
PiecesModel* m_pieces;
QHash<int, PiecesModel::SquareStatus> m_board;
int m_turn = Piece::White;
};
#endif // BOARD_H