BCESolve
bcetablemodel.hpp
1// This file is part of the BCESolve library for games of incomplete
2// information
3// Copyright (C) 2022 Benjamin A. Brooks
4//
5// BCESolve free software: you can redistribute it and/or modify it
6// 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// BCESolve is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see
17// <http://www.gnu.org/licenses/>.
18//
19// Benjamin A. Brooks
20// ben@benjaminbrooks.net
21// Chicago, IL
22
23#ifndef BCETABLEMODEL_HPP
24#define BCETABLEMODEL_HPP
25
26#include <QtWidgets>
27#include <QAbstractTableModel>
28#include <QTableView>
29#include "bcegame.hpp"
30
32
39class BCETableModel : public QAbstractTableModel
40{
41 Q_OBJECT
42
43public:
46 int _state):
47 game(_game), state(_state)
48 {}
49
51
53 Qt::ItemFlags flags(const QModelIndex & index) const
54 { return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable; }
55
58 { emit layoutChanged(); }
59
61 bool setState(int newState)
62 {
63 if (newState < 0 || newState > game->getNumStates())
64 return false;
65 state = newState;
66 return true;
67 }
68
69protected:
71 int state;
74
75};
76
77
78
79
80
81#endif
int getNumStates() const
Returns the number of states.
Definition: bceabstractgame.hpp:247
The base class for games of incomplete information.
Definition: bcegame.hpp:40
Table models for BCEViewer.
Definition: bcetablemodel.hpp:40
bool setState(int newState)
Sets the state to newState.
Definition: bcetablemodel.hpp:61
BCETableModel(BCEGame *_game, int _state)
Constructor.
Definition: bcetablemodel.hpp:45
int state
The state that the model is associated with.
Definition: bcetablemodel.hpp:71
Qt::ItemFlags flags(const QModelIndex &index) const
Returns flags.
Definition: bcetablemodel.hpp:53
void emitLayoutChanged()
Emits layoutChanged signal.
Definition: bcetablemodel.hpp:57
BCEGame * game
Pointer to the associated game.
Definition: bcetablemodel.hpp:73