30 #include <QHBoxLayout>
31 #include <QVBoxLayout>
32 #include <QGridLayout>
35 #include <QToolButton>
36 #include <QtCore/QChildEvent>
37 #include <QtCore/QDir>
38 #include <QtGui/QContextMenuEvent>
47 StatItem::StatItem(
const QString &
name,
bool cacheOn,
const std::vector<qreal> & x,
const std::vector<qreal> & y,
const QString & unit,
const QMenu * menu, QGridLayout * grid, QWidget * parent) :
58 if(
y.size() == 1 || (
y.size() > 1 &&
_cacheOn))
93 _value->setText(QString::number(
y,
'g', 3));
101 if (
_x.size() &&
x <
_x.back())
110 _value->setText(QString::number(
y,
'g', 3));
139 _menu =
new QMenu(
this);
140 _menu->addMenu(
"Add to figure...");
141 _button =
new QToolButton(
this);
142 _button->setIcon(QIcon(
":/images/Plot16.png"));
143 _button->setPopupMode(QToolButton::InstantPopup);
145 _name =
new QLabel(
this);
146 _name->setTextInteractionFlags(Qt::TextSelectableByMouse);
147 _name->setWordWrap(
true);
148 _value =
new QLabel(
this);
149 _value->setTextInteractionFlags(Qt::TextSelectableByMouse);
150 _unit =
new QLabel(
this);
154 int row = grid->rowCount();
166 QHBoxLayout * layout =
new QHBoxLayout(
this);
167 this->setLayout(layout);
169 layout->addWidget(
_name);
170 layout->addWidget(
_value);
171 layout->addWidget(
_unit);
172 layout->addStretch();
173 layout->setContentsMargins(0,0,0,0);
191 QList<QAction *> actions = menu->actions();
192 QMenu * plotMenu =
_menu->addMenu(
"Add to figure...");
193 for(
int i=0;
i<actions.size(); ++
i)
195 action = plotMenu->addAction(actions.at(
i)->text());
202 QAction *
action = qobject_cast<QAction*>(sender());
222 this->setLayout(
new QVBoxLayout());
223 this->layout()->setContentsMargins(0,0,0,0);
224 this->layout()->addWidget(
_statBox);
227 _plotMenu->addAction(tr(
"<New figure>"));
239 QMap<QString, QWidget*> figuresTmp =
_figures;
240 for(QMap<QString, QWidget*>::iterator
iter = figuresTmp.begin();
iter!=figuresTmp.end(); ++
iter)
249 for(
int i=0;
i<items.size(); ++
i)
257 std::vector<qreal>
vx,
vy;
263 std::vector<qreal>
vx,
vy(1);
270 std::vector<qreal>
vx(1),
vy(1);
276 void StatsToolBox::updateStat(
const QString & statFullName,
const std::vector<qreal> & x,
const std::vector<qreal> & y,
bool cacheOn)
286 if(
y.size() == 1 &&
x.size() == 1)
290 else if(
y.size() == 1 &&
x.size() == 0)
302 QStringList
list = statFullName.split(
'/');
313 unit +=
"/" +
list.at(
i);
339 if(
_statBox->itemText(
i).compare(grp) == 0)
348 QWidget * newWidget =
new QWidget(
_statBox);
349 index =
_statBox->addItem(newWidget, grp);
350 QVBoxLayout * layout =
new QVBoxLayout(newWidget);
351 newWidget->setLayout(layout);
352 QGridLayout * grid =
new QGridLayout();
353 grid->setVerticalSpacing(2);
354 grid->setColumnStretch(0, 1);
355 layout->addLayout(grid);
356 layout->addStretch();
359 QVBoxLayout * layout = qobject_cast<QVBoxLayout *>(
_statBox->widget(index)->layout());
365 QGridLayout * grid = qobject_cast<QGridLayout *>(layout->itemAt(0)->layout());
373 item->setObjectName(statFullName);
376 connect(item, SIGNAL(plotRequested(
const StatItem *,
const QString &)),
this, SLOT(
plot(
const StatItem *,
const QString &)));
377 connect(
this, SIGNAL(
menuChanged(
const QMenu *)), item, SLOT(updateMenu(
const QMenu *)));
383 QWidget * fig =
_figures.value(plotName, (QWidget*)0);
387 plot = fig->findChild<
UPlot *>(plotName);
392 if(!
plot->contains(stat->objectName()))
396 connect(stat, SIGNAL(valueAdded(qreal)), curve, SLOT(
addValue(qreal)));
397 connect(stat, SIGNAL(valueAdded(qreal, qreal)), curve, SLOT(
addValue(qreal, qreal)));
398 connect(stat, SIGNAL(valuesChanged(
const std::vector<qreal> &,
const std::vector<qreal> &)), curve, SLOT(setData(
const std::vector<qreal> &,
const std::vector<qreal> &)));
399 if(stat->
value().compare(
"*") == 0)
401 plot->setMaxVisibleItems(0);
414 if(!
plot->addCurve(curve))
424 plot->activateWindow();
429 QString
id = tr(
"Figure 0");
432 id =
_plotMenu->actions().last()->text();
434 id.replace(tr(
"Figure "),
"");
435 QString newPlotName = QString(tr(
"Figure %1")).arg(
id.toInt()+1);
437 QDialog * figure =
new QDialog(0, Qt::Window);
438 _figures.insert(newPlotName, figure);
439 QHBoxLayout * hLayout =
new QHBoxLayout(figure);
440 hLayout->setContentsMargins(0,0,0,0);
441 figure->setWindowTitle(newPlotName);
442 figure->setAttribute(Qt::WA_DeleteOnClose,
true);
443 connect(figure, SIGNAL(destroyed(QObject*)),
this, SLOT(
figureDeleted(QObject*)));
448 newPlot->setObjectName(newPlotName);
449 hLayout->addWidget(newPlot);
451 figure->setSizeGripEnabled(
true);
456 connect(stat, SIGNAL(valueAdded(qreal)), curve, SLOT(
addValue(qreal)));
457 connect(stat, SIGNAL(valueAdded(qreal, qreal)), curve, SLOT(
addValue(qreal, qreal)));
458 connect(stat, SIGNAL(valuesChanged(
const std::vector<qreal> &,
const std::vector<qreal> &)), curve, SLOT(setData(
const std::vector<qreal> &,
const std::vector<qreal> &)));
459 if(stat->
value().compare(
"*") == 0)
492 QWidget *
plot = qobject_cast<QWidget*>(obj);
496 QList<QAction*> actions =
_plotMenu->actions();
497 for(
int i=0;
i<actions.size(); ++
i)
499 if(actions.at(
i)->text().compare(
plot->windowTitle()) == 0)
524 QList<UPlot *> plots =
i.value()->findChildren<
UPlot *>();
525 if (plots.size() == 1)
527 QStringList
names = plots[0]->curveNames();
528 plots[0]->clearData();
537 QList<StatItem*> items =
_statBox->currentWidget()->findChildren<
StatItem*>();
538 for (
int i = 0;
i<items.size(); ++
i)
548 QMenu * menu = topMenu.addMenu(tr(
"Add all statistics from tab \"%1\" to...").
arg(
_statBox->itemText(
_statBox->currentIndex())));
549 QList<QAction* > actions =
_plotMenu->actions();
550 menu->addActions(actions);
551 QAction * aClearFigures = topMenu.addAction(tr(
"Clear all figures"));
552 QAction *
action = topMenu.exec(event->globalPos());
556 if(
action == aClearFigures)
562 for(
int i=0;
i<actions.size(); ++
i)
566 plotName = actions.at(
i)->text();
573 if(!plotName.isEmpty() &&
_statBox->currentWidget())
575 QList<StatItem*> items =
_statBox->currentWidget()->findChildren<
StatItem*>();
576 for(
int i=0;
i<items.size(); ++
i)
578 this->
plot(items.at(
i), plotName);
579 if(plotName.compare(tr(
"<New figure>")) == 0)
581 plotName =
_plotMenu->actions().last()->text();
589 curvesPerFigure.clear();
591 curveThresholds.clear();
594 QList<UPlot *> plots =
i.value()->findChildren<
UPlot *>();
595 if(plots.size() == 1)
597 QStringList
names = plots[0]->curveNames();
598 curvesPerFigure.append(
names.size());
599 curveNames.append(
names);
602 curveThresholds.append(plots[0]->isThreshold(
names[
j])?QString::number(plots[0]->getThresholdValue(
names[
j])):
"NA");
624 this->
plot(item,
"");
638 QString plotName =
_plotMenu->actions().last()->text();
639 QWidget * fig =
_figures.value(plotName, (QWidget*)0);
648 UERROR(
"There are no figures, cannot add threshold \"%s\"",
name.toStdString().c_str());
655 if(QDir(workingDirectory).exists())
660 QList<UPlot *> plots =
i.value()->findChildren<
UPlot *>();
661 if(plots.size() == 1)
673 UWARN(
"The directory \"%s\" doesn't exist, using \"%s\" instead...",
674 workingDirectory.toStdString().c_str(),