23 #include "baseexperimentgui.h"
24 #include <QVBoxLayout>
25 #include <QGridLayout>
31 QWidget(parent, flags),
32 DataUploaderDownloader<__BaseExperiment_internal::OperationControl, __BaseExperiment_internal::OperationStatus>(1, BlockUploader, this, experiment->getUploaderDownloader()),
33 m_experiment(experiment),
35 m_operationSelectionGroup(NULL),
36 m_operationsListLabel(NULL),
37 m_operationsList(NULL),
38 m_selectedOperationInfo(NULL),
39 m_startSelectedOperationButton(NULL),
40 m_currentOperationControlGroup(NULL),
41 m_currentOperationInfo(NULL),
42 m_stopCurrentOperationButton(NULL),
43 m_steppableOperationControlGroup(NULL),
44 m_pauseOperationButton(NULL),
45 m_stepOperationButton(NULL),
46 m_delaySliderLabel(NULL),
48 m_runningOperationID(-1)
51 QVBoxLayout* mainLayout =
new QVBoxLayout(
this);
55 m_operationSelectionGroup =
new QGroupBox(
"Operation Selection",
this);
56 mainLayout->addWidget(m_operationSelectionGroup);
59 QGridLayout* layout =
new QGridLayout(m_operationSelectionGroup);
62 m_operationsListLabel =
new QLabel(
"Operation: ", m_operationSelectionGroup);
63 layout->addWidget(m_operationsListLabel, 0, 0);
66 m_operationsList =
new QComboBox(m_operationSelectionGroup);
67 QSizePolicy operationsListSizePolicy = m_operationsList->sizePolicy();
68 operationsListSizePolicy.setHorizontalStretch(1);
69 m_operationsList->setSizePolicy(operationsListSizePolicy);
70 connect(m_operationsList, SIGNAL(currentIndexChanged(
int)),
this, SLOT(currentOperationChanged(
int)));
71 layout->addWidget(m_operationsList, 0, 1);
74 m_selectedOperationInfo =
new QLabel(
"Invalid operation", m_operationSelectionGroup);
75 layout->addWidget(m_selectedOperationInfo, 1, 0, 1, 2);
78 m_startSelectedOperationButton =
new QPushButton(
"Start Operation", m_operationSelectionGroup);
79 connect(m_startSelectedOperationButton, SIGNAL(clicked()),
this, SLOT(startOperation()));
80 layout->addWidget(m_startSelectedOperationButton, 2, 0, 1, 2);
85 m_currentOperationControlGroup =
new QGroupBox(
"Current Operation Control",
this);
86 mainLayout->addWidget(m_currentOperationControlGroup);
89 QVBoxLayout* layout =
new QVBoxLayout(m_currentOperationControlGroup);
92 m_currentOperationInfo =
new QLabel(
"No running operation", m_currentOperationControlGroup);
93 layout->addWidget(m_currentOperationInfo);
96 m_stopCurrentOperationButton =
new QPushButton(
"Stop Operation", m_currentOperationControlGroup);
97 connect(m_stopCurrentOperationButton, SIGNAL(clicked()),
this, SLOT(stopOperation()));
98 layout->addWidget(m_stopCurrentOperationButton);
103 m_steppableOperationControlGroup =
new QGroupBox(
"Steppable Operation Control",
this);
104 mainLayout->addWidget(m_steppableOperationControlGroup);
107 QGridLayout* layout =
new QGridLayout(m_steppableOperationControlGroup);
110 m_pauseOperationButton =
new QPushButton(
"Pause", m_steppableOperationControlGroup);
111 m_pauseOperationButton->setCheckable(
true);
112 connect(m_pauseOperationButton, SIGNAL(clicked(
bool)),
this, SLOT(pauseOperation(
bool)));
113 layout->addWidget(m_pauseOperationButton, 0, 0, 1, 2);
116 m_stepOperationButton =
new QPushButton(
"Step", m_steppableOperationControlGroup);
117 connect(m_stepOperationButton, SIGNAL(clicked()),
this, SLOT(stepOperation()));
118 layout->addWidget(m_stepOperationButton, 1, 0, 1, 2);
121 m_delaySliderLabel =
new QLabel(
"Interval between steps:", m_steppableOperationControlGroup);
122 layout->addWidget(m_delaySliderLabel, 2, 0);
125 m_delaySlider =
new QSlider(Qt::Horizontal, m_steppableOperationControlGroup);
126 QSizePolicy delaySliderSizePolicy = m_delaySlider->sizePolicy();
127 delaySliderSizePolicy.setHorizontalStretch(1);
128 m_delaySlider->setSizePolicy(delaySliderSizePolicy);
129 m_delaySlider->setRange(0, 100);
130 m_delaySlider->setValue(delayToSliderValue(m_experiment->
currentInterval()));
131 connect(m_delaySlider, SIGNAL(valueChanged(
int)),
this, SLOT(changeDelay(
int)));
132 layout->addWidget(m_delaySlider, 2, 1);
136 updateOperationsList();
153 updateOperationsList();
157 m_currentOperationInfo->setText(describeOperation(m_runningOperationID,
"Running operation: "));
159 if (m_operations[m_runningOperationID]->getUseSeparateThread()) {
160 if (m_operations[m_runningOperationID]->getSteppable()) {
161 enableWidgets(
false,
true,
true,
true);
163 enableWidgets(
false,
true,
false,
false);
166 enableWidgets(
false,
false,
false,
false);
170 m_runningOperationID = -1;
171 currentOperationChanged(m_operationsList->currentIndex());
172 m_currentOperationInfo->setText(
"No running operation");
175 m_stepOperationButton->setEnabled(
true);
178 m_stepOperationButton->setEnabled(
false);
182 m_delaySlider->blockSignals(
true);
183 m_delaySlider->setValue(delayToSliderValue(d->
delay));
184 m_delaySlider->blockSignals(
false);
195 void BaseExperimentGUI::currentOperationChanged(
int index)
197 m_selectedOperationInfo->setText(describeOperation(((index < 0) ? index : (index + 1)),
"Selected operation: "));
199 if (m_runningOperationID == -1) {
201 enableWidgets(
false,
false,
false,
false);
203 if (m_operations[index + 1]->getUseSeparateThread()) {
204 if (m_operations[index + 1]->getSteppable()) {
205 enableWidgets(
true,
false,
true,
true);
207 enableWidgets(
true,
false,
false,
false);
210 enableWidgets(
true,
false,
false,
false);
216 void BaseExperimentGUI::startOperation()
218 if (m_operationsList->currentIndex() == -1) {
224 if (m_pauseOperationButton->isChecked()) {
229 d->operationID = m_operationsList->currentIndex() + 1;
231 m_startSelectedOperationButton->setEnabled(
false);
234 void BaseExperimentGUI::stopOperation()
241 void BaseExperimentGUI::pauseOperation(
bool pause)
248 if (m_runningOperationID != -1) {
249 m_stepOperationButton->setEnabled(
true);
253 m_stepOperationButton->setEnabled(
false);
257 void BaseExperimentGUI::stepOperation()
264 void BaseExperimentGUI::changeDelay(
int delay)
269 d->interval = sliderValueToDelay(delay);
272 void BaseExperimentGUI::updateOperationsList()
277 m_operationsList->clear();
280 for (
int i = 1; i < m_operations.size(); i++) {
281 m_operationsList->insertItem(i - 1, m_operations[i]->getName());
285 m_operationsList->setCurrentIndex(0);
288 void BaseExperimentGUI::enableWidgets(
bool enableStart,
bool enableStop,
bool enablePause,
bool enableDelay)
290 m_startSelectedOperationButton->setEnabled(enableStart);
291 m_stopCurrentOperationButton->setEnabled(enableStop);
292 m_pauseOperationButton->setEnabled(enablePause);
293 if ((enablePause) && (m_runningOperationID != -1)) {
294 m_stepOperationButton->setEnabled(m_pauseOperationButton->isChecked());
296 m_stepOperationButton->setEnabled(
false);
298 m_delaySlider->setEnabled(enableDelay);
301 QString BaseExperimentGUI::describeOperation(
int id, QString prefix)
const
306 str =
"Invalid operation";
308 str = prefix + m_operations[id]->getName();
309 if (m_operations[
id]->getUseSeparateThread()) {
310 if (m_operations[
id]->getSteppable()) {
311 str +=
"; it is a STEPPABLE THREAD operation";
313 str +=
"; it is a THREAD operation";
316 str +=
"; it is an IMMEDIATE operation";
323 unsigned long BaseExperimentGUI::sliderValueToDelay(
int value)
const
328 return (
unsigned long) pow((
double) 1.1, (
double) value);
332 int BaseExperimentGUI::delayToSliderValue(
unsigned long interval)
const
337 return (
int) (log((
double) interval) / log((
double) 1.1));