SGSolve
sgprobabilitytablemodel.hpp
1 // This file is part of the SGSolve library for stochastic games
2 // Copyright (C) 2019 Benjamin A. Brooks
3 //
4 // SGSolve free software: you can redistribute it and/or modify it
5 // 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 // SGSolve is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see
16 // <http://www.gnu.org/licenses/>.
17 //
18 // Benjamin A. Brooks
19 // ben@benjaminbrooks.net
20 // Chicago, IL
21 
22 #ifndef SGPROBABILITYTABLEMODEL_H
23 #define SGPROBABILITYTABLEMODEL_H
24 
25 #include <QtWidgets>
26 #include <QAbstractTableModel>
27 #include <QTableView>
28 #include "sggame.hpp"
29 #include "sgpayofftablemodel.hpp"
30 
32 
39 {
40  Q_OBJECT
41 
42 private:
44 
46  int nextState;
47 
48 public:
50 
53  int _state, int _nextState):
54  SGPayoffTableModel(_game,_state), nextState(_nextState)
55  { }
56 
58 
61  QVariant data(const QModelIndex & index,
62  int role) const Q_DECL_OVERRIDE;
63 
65 
67  bool setData(const QModelIndex & index, const QVariant & value, int role);
68 
70  bool setNextState(int newState)
71  {
72  if (newState < 0 || newState > game->getNumStates())
73  return false;
74  nextState = newState;
75  return true;
76  }
77 
78 
79 }; // SGProbabilityTableModel
80 
81 #endif
SGProbabilityTableModel
Reimplements SGPayoffTable model to specialize to probabilities.
Definition: sgprobabilitytablemodel.hpp:39
SGProbabilityTableModel::data
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE
Reimplements the data method.
Definition: sgprobabilitytablemodel.cpp:25
SGProbabilityTableModel::setData
bool setData(const QModelIndex &index, const QVariant &value, int role)
Reimplements the setData method.
Definition: sgprobabilitytablemodel.cpp:47
SGGame
Describes a stochastic game.
Definition: sggame.hpp:40
SGProbabilityTableModel::setNextState
bool setNextState(int newState)
Sets nextState.
Definition: sgprobabilitytablemodel.hpp:70
SGPayoffTableModel
Derived class for payoff table models.
Definition: sgpayofftablemodel.hpp:42
SGTableModel::game
SGGame * game
Pointer to the associated game.
Definition: sgtablemodel.hpp:79
SGProbabilityTableModel::nextState
int nextState
Tomorrow's state.
Definition: sgprobabilitytablemodel.hpp:46
SGGame::getNumStates
int getNumStates() const
Returns the number of states.
Definition: sggame.hpp:179
SGProbabilityTableModel::SGProbabilityTableModel
SGProbabilityTableModel(SGGame *_game, int _state, int _nextState)
Constructor.
Definition: sgprobabilitytablemodel.hpp:52