SGSolve
sgplotcontroller.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 SGPLOTCONTROLLER_HPP
23 #define SGPLOTCONTROLLER_HPP
24 
25 #include <QObject>
26 #include <QComboBox>
27 #include <QScrollBar>
28 #include <QDebug>
29 #include "sgsolution_maxminmax.hpp"
30 
32 
40 class SGPlotController : public QObject
41 {
42  Q_OBJECT
43 
44 public:
46 
49  enum PlotMode
50  {
52  Generation
53  };
55 
60  {
62  Final
63  };
64 
65 private:
67  int state;
69  int action;
74  int iteration;
75 
78 
81 
84 
86  list<SGIteration_MaxMinMax>::const_iterator currentIter;
88  list< SGStep >::const_iterator currentStep;
89 
91  bool solnLoaded;
92 
94  QComboBox * stateCombo;
96  QComboBox * actionCombo;
98  QComboBox * solutionModeCombo;
100  QScrollBar * iterSlider;
103  QScrollBar * stepSlider;
104 public:
106  SGPlotController(QComboBox * _stateCombo,
107  QComboBox *_actionCombo,
108  QScrollBar * _iterSlider,
109  QScrollBar * _stepSlider,
110  QComboBox * _solutionModeCombo);
111 
113  int getState() const { return state; }
115  int getAction() const { return action; }
117  int getActionIndex() const { return actionIndex; }
119  int getIteration() const { return iteration; }
121  PlotMode getPlotMode() const { return plotMode; }
123  SolutionMode getMode () const { return mode; }
125  list<SGIteration_MaxMinMax>::const_iterator getCurrentIter() const { return currentIter; }
127  int getCurrentIterIndex() const { return iteration; }
129  const SGStep & getCurrentStep() const { return *currentStep; }
131  int getStepSliderPosition() const { return stepSlider->sliderPosition(); }
133  bool hasSolution() const { return solnLoaded; }
135  const SGSolution_MaxMinMax * getSolution() const { return soln; }
137  void setSolution(SGSolution_MaxMinMax * newSoln);
139  bool setState(int newState);
141  void setPlotMode(PlotMode newMode) { plotMode = newMode; }
143  bool setActionIndex(int newActionIndex);
145  bool setAction(int newAction);
147  bool setIteration(int newIter);
150  {
151  if (!solnLoaded)
152  return;
153 
154  iterSlider->setSliderPosition(std::max(iterSlider->minimum(),
155  iterSlider->value()-1));
156  // iterSliderUpdate(iterSlider->value());
157  }
160  {
161  if (!solnLoaded)
162  return;
163 
164  iterSlider->setSliderPosition(std::min(iterSlider->maximum(),
165  iterSlider->value()+1));
166  // iterSliderUpdate(iterSlider->value());
167  }
170  void setCurrentDirection(SGPoint point, int state);
172 
174  void synchronizeSliders();
175 
177  void synchronizeIterSlider();
179  void synchronizeStepSlider();
180 
181 signals:
187  void stateChanged();
190 
191 
192 public slots:
194  void iterSliderUpdate(int value);
196  void prevAction();
198  void nextAction();
200  void changeAction(int newAction);
201 
203  void changeMode(int newMode);
204 
205  // //! Slot used to set up the sliders when changing between Progress
206  // //! and Final modes.
207  // void setSliderRanges(int start, int end);
208 
209 
210 
211 }; // SGPlotController
212 
213 
214 
215 #endif
SGPlotController::stateCombo
QComboBox * stateCombo
Points to the stateCombo QComboBox selector.
Definition: sgplotcontroller.hpp:94
SGPlotController::synchronizeIterSlider
void synchronizeIterSlider()
Synchronizes iterSlider.
Definition: sgplotcontroller.cpp:198
SGPlotController::synchronizeStepSlider
void synchronizeStepSlider()
Synchronizes stepSlider.
Definition: sgplotcontroller.cpp:218
SGPlotController::solutionModeCombo
QComboBox * solutionModeCombo
Points to the solutionMode QComboBox selector.
Definition: sgplotcontroller.hpp:98
SGPlotController
Handles the plot settings for SGSolutionHandler.
Definition: sgplotcontroller.hpp:41
SGPlotController::actionChanged
void actionChanged()
Signal to the solutionHandler that the action changed.
SGPlotController::getStepSliderPosition
int getStepSliderPosition() const
Returns the position of the stepSlider.
Definition: sgplotcontroller.hpp:131
SGPlotController::actionIndex
int actionIndex
Definition: sgplotcontroller.hpp:72
SGPlotController::moveBackwards
void moveBackwards()
Decrements the current iteration.
Definition: sgplotcontroller.hpp:159
SGPlotController::getCurrentIter
list< SGIteration_MaxMinMax >::const_iterator getCurrentIter() const
Access method for the current SGIteration_MaxMinMax pointer.
Definition: sgplotcontroller.hpp:125
SGPlotController::getCurrentStep
const SGStep & getCurrentStep() const
Access method for the current SGStep pointer.
Definition: sgplotcontroller.hpp:129
SGStep
A single step of the max-min-max algorithm.
Definition: sgstep.hpp:36
SGPlotController::prevAction
void prevAction()
Decrements the action.
Definition: sgplotcontroller.cpp:249
SGPlotController::Progress
@ Progress
Definition: sgplotcontroller.hpp:61
SGPlotController::moveForwards
void moveForwards()
Increments the current iteration.
Definition: sgplotcontroller.hpp:149
SGPlotController::Final
@ Final
Definition: sgplotcontroller.hpp:62
SGPlotController::setCurrentDirection
void setCurrentDirection(SGPoint point, int state)
Definition: sgplotcontroller.cpp:170
SGPlotController::hasSolution
bool hasSolution() const
Returns true if a solution has been loaded.
Definition: sgplotcontroller.hpp:133
SGPlotController::currentIter
list< SGIteration_MaxMinMax >::const_iterator currentIter
Points to the current SGiteration.
Definition: sgplotcontroller.hpp:86
SGPlotController::iterSliderUpdate
void iterSliderUpdate(int value)
Slot when the iter and start sliders are moved.
Definition: sgplotcontroller.cpp:235
SGPlotController::setSolution
void setSolution(SGSolution_MaxMinMax *newSoln)
Sets the solution.
Definition: sgplotcontroller.cpp:45
SGPlotController::iterSlider
QScrollBar * iterSlider
Points to the iterSlider QScrollBar for selecting the current iteration.
Definition: sgplotcontroller.hpp:100
SGPlotController::changeMode
void changeMode(int newMode)
Toggles the solution mode.
Definition: sgplotcontroller.cpp:335
SGPlotController::iteration
int iteration
The current iteration.
Definition: sgplotcontroller.hpp:74
SGPlotController::PlotMode
PlotMode
Plot mode for the detailPlot.
Definition: sgplotcontroller.hpp:50
SGPlotController::synchronizeSliders
void synchronizeSliders()
Synchronizes sliders with controls.
Definition: sgplotcontroller.cpp:192
SGPlotController::SGPlotController
SGPlotController(QComboBox *_stateCombo, QComboBox *_actionCombo, QScrollBar *_iterSlider, QScrollBar *_stepSlider, QComboBox *_solutionModeCombo)
Constructor.
Definition: sgplotcontroller.cpp:24
SGPlotController::solutionChanged
void solutionChanged()
Signal to the state and action models that the solution changed.
SGPlotController::getPlotMode
PlotMode getPlotMode() const
Access method for the current plot mode.
Definition: sgplotcontroller.hpp:121
SGPlotController::setIteration
bool setIteration(int newIter)
Sets the current iteration.
Definition: sgplotcontroller.cpp:140
SGPlotController::iterationChanged
void iterationChanged()
Signal to solutionHandler that the iteration changed.
SGSolution_MaxMinMax
Records the progress of SGSolver_MaxMinMax::solve().
Definition: sgsolution_maxminmax.hpp:40
SGPlotController::nextAction
void nextAction()
Increments the action.
Definition: sgplotcontroller.cpp:292
SGPlotController::setPlotMode
void setPlotMode(PlotMode newMode)
Sets the plot mode.
Definition: sgplotcontroller.hpp:141
SGPlotController::soln
SGSolution_MaxMinMax * soln
The current solution object.
Definition: sgplotcontroller.hpp:77
SGPlotController::stepSlider
QScrollBar * stepSlider
Definition: sgplotcontroller.hpp:103
SGPoint
A vector in .
Definition: sgpoint.hpp:35
SGPlotController::SolutionMode
SolutionMode
Solution mode.
Definition: sgplotcontroller.hpp:60
SGPlotController::stateChanged
void stateChanged()
Signal to the actionCombo that the state changed.
SGPlotController::getMode
SolutionMode getMode() const
Access method for the current solution mode.
Definition: sgplotcontroller.hpp:123
SGPlotController::plotMode
PlotMode plotMode
The current plot mode.
Definition: sgplotcontroller.hpp:80
SGPlotController::setState
bool setState(int newState)
Sets the current state.
Definition: sgplotcontroller.cpp:83
SGPlotController::getState
int getState() const
Access method for the current state.
Definition: sgplotcontroller.hpp:113
SGPlotController::changeAction
void changeAction(int newAction)
Sets the action.
Definition: sgplotcontroller.cpp:350
SGPlotController::mode
SolutionMode mode
The current solution mode.
Definition: sgplotcontroller.hpp:83
SGPlotController::getCurrentIterIndex
int getCurrentIterIndex() const
Access method for the current SGIteration_MaxMinMax pointer.
Definition: sgplotcontroller.hpp:127
SGPlotController::setAction
bool setAction(int newAction)
Sets the current action.
Definition: sgplotcontroller.cpp:99
SGPlotController::Directions
@ Directions
Definition: sgplotcontroller.hpp:51
SGPlotController::getActionIndex
int getActionIndex() const
Access method for the current action index.
Definition: sgplotcontroller.hpp:117
SGPlotController::action
int action
Current action.
Definition: sgplotcontroller.hpp:69
SGPlotController::getIteration
int getIteration() const
Access method for the current iteration number.
Definition: sgplotcontroller.hpp:119
SGPlotController::solnLoaded
bool solnLoaded
Indicates when an SGSolution object has been loaded.
Definition: sgplotcontroller.hpp:91
SGPlotController::getAction
int getAction() const
Access method for the current action.
Definition: sgplotcontroller.hpp:115
SGPlotController::state
int state
Current state.
Definition: sgplotcontroller.hpp:67
SGPlotController::actionCombo
QComboBox * actionCombo
Points to the actionCombo QComboBox selector.
Definition: sgplotcontroller.hpp:96
SGPlotController::currentStep
list< SGStep >::const_iterator currentStep
Points to the current step.
Definition: sgplotcontroller.hpp:88
SGPlotController::setActionIndex
bool setActionIndex(int newActionIndex)
Sets the current action index.
Definition: sgplotcontroller.cpp:116
SGPlotController::getSolution
const SGSolution_MaxMinMax * getSolution() const
Returns the current solution.
Definition: sgplotcontroller.hpp:135
SGPlotController::Generation
@ Generation
Definition: sgplotcontroller.hpp:52