SGSolve
sgsettingshandler.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 SGSETTINGSHANDLER_HPP
23 #define SGSETTINGSHANDLER_HPP
24 
25 #include <QWidget>
26 #include <QMenuBar>
27 #include <QAction>
28 #include <QFormLayout>
29 #include <QLineEdit>
30 #include <QPushButton>
31 #include <QCheckBox>
32 #include <QDialog>
33 #include "sgenv.hpp"
34 
36 
45 class SGDblParamEdit : public QLineEdit
46 {
47  Q_OBJECT;
48 private:
53 public:
55  SGDblParamEdit(QWidget * parent,
56  SGEnv * _env,SG::DBL_PARAM _param):
57  env(_env),
58  param(_param),
59  QLineEdit()
60  {
61  setText(QString::number(env->getParam(param)));
62  connect(this,SIGNAL(textChanged(const QString &)),
63  this,SLOT(changeParam(const QString &)));
64  connect(parent,SIGNAL(restoreDefaultSignal()),
65  this,SLOT(resetParam()));
66  } // constructor
67 
68 private slots:
70  void changeParam(const QString & text)
71  {
72  double newValue = text.toDouble();
73  env->setParam(param,newValue);
74  }
76  void resetParam()
77  { setText(QString::number(env->getParam(param))); }
78 
79 }; // SGDblParamEdit
80 
82 
91 class SGIntParamEdit : public QLineEdit
92 {
93  Q_OBJECT;
94 private:
99 public:
101  SGIntParamEdit(QWidget * parent,
102  SGEnv * _env,SG::INT_PARAM _param):
103  env(_env),
104  param(_param),
105  QLineEdit()
106  {
107  setText(QString::number(env->getParam(param)));
108  connect(this,SIGNAL(textChanged(const QString &)),
109  this,SLOT(changeParam(const QString &)));
110  connect(parent,SIGNAL(restoreDefaultSignal()),
111  this,SLOT(resetParam()));
112  } // constructor
113 
114 private slots:
116  void changeParam(const QString & text)
117  {
118  double newValue = text.toInt();
119  env->setParam(param,newValue);
120  }
122  void resetParam()
123  { setText(QString::number(env->getParam(param))); }
124 
125 }; // SGIntParamEdit
126 
128 
137 class SGBoolParamBox : public QCheckBox
138 {
139  Q_OBJECT;
140 private:
146  void setCheck(bool tf)
147  {
148  if (tf)
149  setCheckState(Qt::Checked);
150  else
151  setCheckState(Qt::Unchecked);
152  }
153 
154 public:
156  SGBoolParamBox(QWidget * parent,
157  SGEnv * _env,
158  SG::BOOL_PARAM _param):
159  env(_env),
160  param(_param),
161  QCheckBox()
162  {
164 
165  connect(this,SIGNAL(clicked(bool)),
166  this,SLOT(changeParam()));
167  connect(parent,SIGNAL(restoreDefaultSignal()),
168  this,SLOT(resetParam()));
169 
170  } // constructor
171 
172 private slots:
174  void changeParam()
175  {
176  env->setParam(param,isChecked());
178  }
180  void resetParam()
181  { setCheck(env->getParam(param)); }
182 }; // SGBoolParamBox
183 
185 
194 class SGSettingsHandler : public QDialog
195 {
196  Q_OBJECT;
197 
198 private:
201 
202 public:
204  SGSettingsHandler(QWidget * parent,
205  SGEnv * _env);
207  virtual ~SGSettingsHandler() {}
208 
209 signals:
214 private slots:
220  {
221  env->restoreDefaults();
222  env->setParam(SG::PRINTTOCOUT,false);
223  emit restoreDefaultSignal();
224  } // restoreDefaults
225 
226 };
227 
228 #endif
SGIntParamEdit::env
SGEnv * env
The associated SGEnv object.
Definition: sgsettingshandler.hpp:98
SGEnv::getParam
double getParam(SG::DBL_PARAM param) const
Method for getting double parameters.
Definition: sgenv.cpp:96
SGDblParamEdit::param
SG::DBL_PARAM param
The double parameter associated with this edit.
Definition: sgsettingshandler.hpp:47
SG::PRINTTOCOUT
@ PRINTTOCOUT
Definition: sgnamespace.hpp:126
SGSettingsHandler::~SGSettingsHandler
virtual ~SGSettingsHandler()
Destructor.
Definition: sgsettingshandler.hpp:207
SGSettingsHandler::env
SGEnv * env
Pointer to the associated SGEnv object.
Definition: sgsettingshandler.hpp:196
SGIntParamEdit::SGIntParamEdit
SGIntParamEdit(QWidget *parent, SGEnv *_env, SG::INT_PARAM _param)
Constructor.
Definition: sgsettingshandler.hpp:101
SGBoolParamBox::setCheck
void setCheck(bool tf)
The set method.
Definition: sgsettingshandler.hpp:146
SGBoolParamBox
Class for changing boolean parameters.
Definition: sgsettingshandler.hpp:138
SGSettingsHandler::closeSettingsHandler
void closeSettingsHandler()
Signals to SGSolutionHandler to delete this widget.
SGIntParamEdit::resetParam
void resetParam()
Slot called when resetting to default values.
Definition: sgsettingshandler.hpp:122
SGSettingsHandler
A widget for setting parameters of the algorithm.
Definition: sgsettingshandler.hpp:195
SG::INT_PARAM
INT_PARAM
Integer parameters.
Definition: sgnamespace.hpp:142
SGBoolParamBox::SGBoolParamBox
SGBoolParamBox(QWidget *parent, SGEnv *_env, SG::BOOL_PARAM _param)
Constructor.
Definition: sgsettingshandler.hpp:156
SGIntParamEdit::changeParam
void changeParam(const QString &text)
Slot called when the QLineEdit is edited.
Definition: sgsettingshandler.hpp:116
SG::DBL_PARAM
DBL_PARAM
Double parameters.
Definition: sgnamespace.hpp:68
SGSettingsHandler::restoreDefaults
void restoreDefaults()
Definition: sgsettingshandler.hpp:219
SGSettingsHandler::SGSettingsHandler
SGSettingsHandler(QWidget *parent, SGEnv *_env)
Constructor.
Definition: sgsettingshandler.cpp:24
SGSettingsHandler::closeWindow
void closeWindow()
Closes the window by sending signal to SGSolutionHandler.
Definition: sgsettingshandler.hpp:216
SGBoolParamBox::changeParam
void changeParam()
Slot called when the check is modified.
Definition: sgsettingshandler.hpp:174
SGSettingsHandler::restoreDefaultSignal
void restoreDefaultSignal()
Signals all of the edits and check boxes to reset to default values.
SGDblParamEdit::env
SGEnv * env
The associated SGEnv object.
Definition: sgsettingshandler.hpp:52
SGEnv
Manages parameters for algorithm behavior.
Definition: sgenv.hpp:35
SGDblParamEdit::SGDblParamEdit
SGDblParamEdit(QWidget *parent, SGEnv *_env, SG::DBL_PARAM _param)
Constructor.
Definition: sgsettingshandler.hpp:55
SGEnv::setParam
void setParam(SG::DBL_PARAM param, double value)
Method for setting double parameters.
Definition: sgenv.cpp:68
SG::BOOL_PARAM
BOOL_PARAM
Boolean parameters.
Definition: sgnamespace.hpp:116
SGIntParamEdit
Class for changing integer parameters.
Definition: sgsettingshandler.hpp:92
SGBoolParamBox::resetParam
void resetParam()
Slot called when resetting to default values.
Definition: sgsettingshandler.hpp:180
SGDblParamEdit::resetParam
void resetParam()
Slot called when resetting to default values.
Definition: sgsettingshandler.hpp:76
SGEnv::restoreDefaults
void restoreDefaults()
Method for restoring default values for all parameters.
Definition: sgenv.cpp:32
SGIntParamEdit::param
SG::INT_PARAM param
The int parameter associated with this edit.
Definition: sgsettingshandler.hpp:93
SGDblParamEdit
Class for changing double parameters.
Definition: sgsettingshandler.hpp:46
SGDblParamEdit::changeParam
void changeParam(const QString &text)
Slot called when the QLineEdit is edited.
Definition: sgsettingshandler.hpp:70
SGBoolParamBox::param
SG::BOOL_PARAM param
The boolean parameter associated with the box.
Definition: sgsettingshandler.hpp:139
SGBoolParamBox::env
SGEnv * env
The associated environment.
Definition: sgsettingshandler.hpp:144