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))
60 _value->setNum(y[y.size()-1]);
93 _value->setText(QString::number(y,
'g', 3));
101 if (
_x.size() && x <
_x.back())
110 _value->setText(QString::number(y,
'g', 3));
122 _value->setNum(y[y.size()-1]);
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();
159 grid->addWidget(
_button, row, 3);
160 grid->addWidget(
_name, row, 0);
161 grid->addWidget(
_value, row, 1);
162 grid->addWidget(
_unit, row, 2);
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->setMargin(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()->setMargin(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)
242 iter.value()->close();
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(
'/');
311 for(
int i=3; i<list.size(); ++i)
313 unit +=
"/" + list.at(i);
316 else if(list.size() == 2)
321 else if(list.size() == 1)
337 for(
int i=0; i<
_statBox->count(); ++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)
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);
495 _figures.remove(plot->windowTitle());
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)
522 for (QMap<QString, QWidget*>::iterator i =
_figures.begin(); i !=
_figures.end(); ++i)
524 QList<UPlot *> plots = i.value()->findChildren<
UPlot *>();
525 if (plots.size() == 1)
528 plots[0]->clearData();
535 QList<StatItem*> items =
_statBox->currentWidget()->findChildren<
StatItem*>();
536 for (
int i = 0; i<items.size(); ++i)
545 QMenu * menu = topMenu.addMenu(tr(
"Add all statistics from tab \"%1\" to...").arg(
_statBox->itemText(
_statBox->currentIndex())));
546 QList<QAction* > actions =
_plotMenu->actions();
547 menu->addActions(actions);
548 QAction * aClearFigures = topMenu.addAction(tr(
"Clear all figures"));
549 QAction * action = topMenu.exec(event->globalPos());
553 if(action == aClearFigures)
559 for(
int i=0; i<actions.size(); ++i)
561 if(actions.at(i) == action)
563 plotName = actions.at(i)->text();
570 if(!plotName.isEmpty())
572 QList<StatItem*> items =
_statBox->currentWidget()->findChildren<
StatItem*>();
573 for(
int i=0; i<items.size(); ++i)
575 this->
plot(items.at(i), plotName);
576 if(plotName.compare(tr(
"<New figure>")) == 0)
578 plotName =
_plotMenu->actions().last()->text();
586 curvesPerFigure.clear();
588 for(QMap<QString, QWidget*>::iterator i=
_figures.begin(); i!=
_figures.end(); ++i)
590 QList<UPlot *> plots = i.value()->findChildren<
UPlot *>();
591 if(plots.size() == 1)
594 curvesPerFigure.append(names.size());
595 curveNames.append(names);
616 this->
plot(item,
"");
631 if(QDir(workingDirectory).exists())
634 for(QMap<QString, QWidget*>::iterator i=
_figures.begin(); i!=
_figures.end(); ++i)
636 QList<UPlot *> plots = i.value()->findChildren<
UPlot *>();
637 if(plots.size() == 1)
649 UWARN(
"The directory \"%s\" doesn't exist, using \"%s\" instead...",
650 workingDirectory.toStdString().c_str(),
std::vector< qreal > yValues() const
void setData(QVector< UPlotItem * > &data)
void valuesChanged(const std::vector< qreal > &, const std::vector< qreal > &)
void updateMenu(const QMenu *menu)
void plotRequested(const StatItem *, const QString &)
GLM_FUNC_DECL genType::row_type row(genType const &m, length_t const &index)
void setPen(const QPen &pen)
void setupUi(QGridLayout *grid)
QPen getRandomPenColored()
#define ULOGGER_DEBUG(...)
void setValues(const std::vector< qreal > &x, const std::vector< qreal > &y)
UPlotCurve * addCurve(const QString &curveName, const QColor &color=QColor())
void addValue(int pos, float val, float *vals, T *point, T *points, int n)
bool contains(const QString &curveName)
StatItem(const QString &name, bool cacheOn, const std::vector< qreal > &x, const std::vector< qreal > &y, const QString &unit=QString(), const QMenu *menu=0, QGridLayout *grid=0, QWidget *parent=0)
void preparePlotRequest()
std::vector< qreal > xValues() const
#define ULOGGER_WARN(...)
ULogger class and convenient macros.
void setMaxVisibleItems(int maxVisibleItems)
#define ULOGGER_ERROR(...)
void setWorkingDirectory(const QString &workingDirectory)