7 #include <QDialogButtonBox>
13 #include <QPushButton>
15 #include <QVBoxLayout>
16 #include <QHBoxLayout>
17 #include <QGridLayout>
18 #include <QFormLayout>
21 #include <QMessageBox>
23 #include <QElapsedTimer>
31 "Please press one of the following key: \n \
32 - 'y': When you hear 'yes' \n \
33 - 'n': When you hear 'no' \n \
34 - 'z': To undo the last operation \n \
35 - 'r': Toggle the refresh mode for the summary (continuous / non-continuous) \n \
36 - 's': To show (refresh) the summary of the negotiation \n \
37 - 'q': To quit the program \n";
39 this->createUsageBox();
40 this->createCounterBox();
41 this->createSummaryBox();
42 this->buttonBox =
new QDialogButtonBox(QDialogButtonBox::Close);
43 connect(buttonBox, SIGNAL(accepted()),
this, SLOT(accept()));
44 connect(buttonBox, SIGNAL(rejected()),
this, SLOT(reject()));
45 QVBoxLayout *mainLayout =
new QVBoxLayout;
46 mainLayout->addWidget(this->usageBox, 0, Qt::AlignTop);
47 mainLayout->addWidget(this->counterBox, 0, Qt::AlignTop);
48 mainLayout->addWidget(this->summaryBox, 1);
49 mainLayout->addWidget(this->buttonBox, 0, Qt::AlignBottom);
50 this->setLayout(mainLayout);
51 this->setWindowTitle(tr(
"Negotiation Study"));
53 this->Calculator = NULL;
55 this->timer =
new QElapsedTimer();
59 void MainWindow::createUsageBox()
62 this->usageBox =
new QGroupBox(tr(
"Usage"));
63 QHBoxLayout *layout =
new QHBoxLayout;
64 QLabel* usageLabel =
new QLabel (tr (this->Usage.c_str()));
65 layout->addWidget (usageLabel);
66 this->usageBox->setLayout(layout);
69 void MainWindow::createCounterBox()
71 this->counterBox =
new QGroupBox(tr(
"Counter"));
72 QGridLayout *layout =
new QGridLayout;
73 this->numberOfYesLabel =
new QLabel(tr(
"Yes: 0"));
74 layout->addWidget(this->numberOfYesLabel, 0, 0);
75 this->numberOfNoLabel =
new QLabel(tr(
"No: 0"));
76 layout->addWidget(this->numberOfNoLabel, 0, 1);
78 f = this->numberOfYesLabel->font();
81 this->numberOfYesLabel->setFont (f);
82 f = this->numberOfNoLabel->font();
85 this->numberOfNoLabel->setFont (f);
86 this->counterBox->setLayout(layout);
89 void MainWindow::createSummaryBox()
91 this->summaryBox =
new QGroupBox(tr(
"Summary"));
92 QGridLayout *layout =
new QGridLayout;
93 this->eTimeLabel =
new QLabel(tr(
"Elapsed Time: 0.00 min"));
94 layout->addWidget(this->eTimeLabel, 0, 0, Qt::AlignTop);
95 this->ratioLabel =
new QLabel(tr(
"Ratio of 'yes' over 'no': 0.00"));
96 layout->addWidget(this->ratioLabel, 0, 1, Qt::AlignTop);
97 this->yRateLabel =
new QLabel(tr(
"Rate of 'yes': 0.00 / min"));
98 layout->addWidget(this->yRateLabel, 1, 0, Qt::AlignTop);
99 this->nRateLabel =
new QLabel(tr(
"Rate of 'no': 0.00 / min"));
100 layout->addWidget(this->nRateLabel, 1, 1, Qt::AlignTop);
106 this->customPlot->
graph(0)->
setName(
"Current Binomial Distribution");
107 this->customPlot->
graph(0)->
setPen(QPen(Qt::blue));
108 this->customPlot->
graph(0)->
setBrush(QBrush(QColor(0, 0, 255, 20)));
119 layout->addWidget(this->customPlot, 2, 0, 1, 2);
120 layout->setRowStretch (0, 0);
121 layout->setRowStretch (1, 0);
122 layout->setRowStretch (2, 1);
123 this->summaryBox->setLayout(layout);
143 if (this->ListOfOperations.size() >= 1)
144 this->ListOfOperations.pop_back();
160 this->RefreshMode = ! this->RefreshMode;
169 if (this->counterBox == NULL)
172 unsigned int n = std::count (this->ListOfOperations.begin(), this->ListOfOperations.end(),
MainWindow::Operation_No);
173 this->numberOfYesLabel->setText(tr(
"Yes: %1").arg(y));
174 this->numberOfNoLabel->setText(tr(
"No: %1").arg(n));
180 if (this->summaryBox == NULL)
184 unsigned int n = std::count (this->ListOfOperations.begin(), this->ListOfOperations.end(),
MainWindow::Operation_No);
185 float ratio = this->ListOfOperations.size() ? (float)(y)/(float)(this->ListOfOperations.size()) : 0;
186 float elapsed_minutes = (float) this->timer->elapsed() / (1000.0 * 60.0);
187 float yrate = (float)(y) / elapsed_minutes;
188 float nrate = (float)(n) / elapsed_minutes;
190 this->eTimeLabel->setText(tr(
"Elapsed Time: %1 min").arg(QString::number (elapsed_minutes,
'f', 2 )));
191 this->ratioLabel->setText(tr(
"Ratio of 'yes' over 'no': %1").arg(QString::number (ratio,
'f', 2 )));
192 this->yRateLabel->setText(tr(
"Rate of 'yes': %1 / min").arg(QString::number (yrate,
'f', 2 )));
193 this->nRateLabel->setText(tr(
"Rate of 'no': %1 / min").arg(QString::number (nrate,
'f', 2 )));
195 if (this->Calculator == NULL ||
196 !this->ListOfOperations.size())
202 std::vector<float> pmf;
205 for (
unsigned int i=0; i<this->ListOfOperations.size(); i++)
209 max_p = std::max (p, max_p);
212 QVector<double> x0(this->ListOfOperations.size()), y0(this->ListOfOperations.size());
213 for (
unsigned int i=0; i<this->ListOfOperations.size(); ++i)
219 QVector<double> x1 (2), y1 (2);
229 this->customPlot->
replot();
Represents the range an axis is encompassing.
0x008 Plottables are selectable (e.g. graphs, curves, bars,... see QCPAbstractPlottable) ...
void SetNumberOfExperiments(unsigned int n)
void setPen(const QPen &pen)
void setData(QCPDataMap *data, bool copy=false)
QCPGraph * graph(int index) const
void setBrush(const QBrush &brush)
The central class of the library. This is the QWidget which displays the plot and interacts with the ...
Q_SLOT void replot(QCustomPlot::RefreshPriority refreshPriority=QCustomPlot::rpHint)
void SetProbabilityOfSuccess(float p)
0x001 Axis ranges are draggable (see QCPAxisRect::setRangeDrag, QCPAxisRect::setRangeDragAxes) ...
QCPGraph * addGraph(QCPAxis *keyAxis=0, QCPAxis *valueAxis=0)
void setName(const QString &name)
void keyPressEvent(QKeyEvent *e)
void setTickLabels(bool show)
0x002 Axis ranges are zoomable with the mouse wheel (see QCPAxisRect::setRangeZoom, QCPAxisRect::setRangeZoomAxes)
float GetProbabilityMassFunction(unsigned int k) const
void setInteractions(const QCP::Interactions &interactions)
void rescaleAxes(bool onlyEnlarge, bool includeErrorBars) const
void setFont(const QFont &font)