SGSolve
sgstatecombomodel.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 SGSTATECOMBOMODEL_HPP
23 #define SGSTATECOMBOMODEL_HPP
24 
25 #include "sgplotcontroller.hpp"
26 #include <QAbstractListModel>
27 #include <QComboBox>
28 
30 
42 class SGStateComboModel : public QAbstractListModel
43 {
44  Q_OBJECT;
45 private:
48 
49 public:
52  controller(_controller)
53  {
54  connect(controller,SIGNAL(solutionChanged()),
55  this,SLOT(changeLayout()));
56  }
57 
59  int rowCount(const QModelIndex & parent) const
60  {
61  if (controller->hasSolution())
62  return controller->getCurrentIter()->getActions().size()+1;
63  else
64  return 1;
65  } // rowCount
66 
68  QVariant data(const QModelIndex & index, int role) const
69  {
70  if (index.row()>0)
71  {
72  QString dataString = QString("S")+QString::number(index.row()-1);
73  // if ( (index.row()-1) == controller->getCurrentIter()->getBestState())
74  // dataString += QString("*");
75  return dataString;
76  }
77  else if (index.row()==0)
78  return QString("-");
79  }
80 
81 public slots:
84  void changeState(int index)
85  { controller->setState(index-1); }
86 
88  void changeLayout()
89  {
90  emit layoutChanged();
91  }
92 
93 }; // SGStateComboModel_V2
94 
95 #endif
SGStateComboModel::controller
SGPlotController * controller
The associated SGPlotController object.
Definition: sgstatecombomodel.hpp:44
SGPlotController
Handles the plot settings for SGSolutionHandler.
Definition: sgplotcontroller.hpp:41
SGPlotController::getCurrentIter
list< SGIteration_MaxMinMax >::const_iterator getCurrentIter() const
Access method for the current SGIteration_MaxMinMax pointer.
Definition: sgplotcontroller.hpp:125
SGStateComboModel::changeState
void changeState(int index)
Definition: sgstatecombomodel.hpp:84
SGStateComboModel::data
QVariant data(const QModelIndex &index, int role) const
Reimplement data.
Definition: sgstatecombomodel.hpp:68
SGPlotController::hasSolution
bool hasSolution() const
Returns true if a solution has been loaded.
Definition: sgplotcontroller.hpp:133
SGStateComboModel
Model for stateCombo.
Definition: sgstatecombomodel.hpp:43
SGStateComboModel::changeLayout
void changeLayout()
Signals to the GUI to change the layout.
Definition: sgstatecombomodel.hpp:88
SGStateComboModel::rowCount
int rowCount(const QModelIndex &parent) const
Reimplement rowcount.
Definition: sgstatecombomodel.hpp:59
SGPlotController::setState
bool setState(int newState)
Sets the current state.
Definition: sgplotcontroller.cpp:83
SGStateComboModel::SGStateComboModel
SGStateComboModel(SGPlotController *_controller)
Constructor.
Definition: sgstatecombomodel.hpp:51