diff --git a/src/widgets/plotwidget.cpp b/src/widgets/plotwidget.cpp index f971578..19f8a0c 100644 --- a/src/widgets/plotwidget.cpp +++ b/src/widgets/plotwidget.cpp @@ -1,94 +1,85 @@ /* Atelier KDE Printer Host for 3D Printing Copyright (C) <2016> Author: Patrick José Pereira - patrickelectric@gmail.com This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "plotwidget.h" #include #include PlotWidget::PlotWidget(QWidget *parent) : QWidget(parent), _chart(new QChartView()), _axisY(new QValueAxis()), _axisX(new QDateTimeAxis()) { QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(_chart); setLayout(mainLayout); newPlot(i18n("Actual Bed")); newPlot(i18n("Target Bed")); // The extruder need to be added after some signal emitted (ExtruderCountChanged) newPlot(i18n("Actual Ext.1")); newPlot(i18n("Target Ext.1")); - update(); + + _axisX->setTickCount(3); + _axisX->setFormat(QStringLiteral("hh:mm:ss")); + _axisY->setLabelFormat(QStringLiteral("%d")); + _axisY->setTitleText(i18n("Temp.")); + + _chart->chart()->addAxis(_axisY, Qt::AlignLeft); + _chart->chart()->addAxis(_axisX, Qt::AlignBottom); + _chart->chart()->axisY()->setRange(0, 3e2); + _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); + + for (auto plot : _plots) { + _chart->chart()->addSeries(plot.serie()); + plot.serie()->attachAxis(_axisY); + plot.serie()->attachAxis(axisX); + } + + _chart->setRenderHint(QPainter::Antialiasing); } void PlotWidget::newPlot(QString name) { // Create a new plot _name2Index[name] = _plots.size(); plot _newPlot; _newPlot.setName(name); _plots.append(_newPlot); } void PlotWidget::deletePlot(QString name) { _plots.remove(_name2Index[name]); _name2Index[name] = -1; } void PlotWidget::appendPoint(QString name, float value) { _plots[_name2Index[name]].pushPoint(value); } void PlotWidget::update() { - // After already executed, update time axis - if (firstTimeCheck == false) { - _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); - return; - } - - firstTimeCheck = false; - - _axisX->setTickCount(3); - _axisX->setFormat(QStringLiteral("hh:mm:ss")); - - _axisY->setLabelFormat(QStringLiteral("%d")); - _axisY->setTitleText(i18n("Temp.")); - - _chart->chart()->addAxis(_axisY, Qt::AlignLeft); - _chart->chart()->addAxis(_axisX, Qt::AlignBottom); - - _chart->chart()->axisY()->setRange(0, 3e2); _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); - - for (auto plot : _plots) { - _chart->chart()->addSeries(plot.serie()); - plot.serie()->attachAxis(_axisY); - plot.serie()->attachAxis(_axisX); - } - - _chart->setRenderHint(QPainter::Antialiasing); } PlotWidget::~PlotWidget() { }