diff --git a/src/widgets/plotwidget.h b/src/widgets/plotwidget.h --- a/src/widgets/plotwidget.h +++ b/src/widgets/plotwidget.h @@ -41,13 +41,13 @@ * @brief Create a new plot * @param name p_name: plot name */ - void newPlot(const QString &name); + void addPlot(const QString &name); /** * @brief Delete plot with name * @param name p_name: name */ - void deletePlot(const QString &name); + void removePlot(const QString &name); /** * @brief Append point to plot @@ -57,9 +57,23 @@ void appendPoint(const QString &name, float value); /** - * @brief Update plot list, need to run after ALL plots added + * @brief plots + * @return List of all named plots */ - void update(); + QStringList plots(); + + /** + * @brief set The Maximum Number of points per series the plot widget stores + * @param newMax: new maximum Number (default:24) + */ + void setMaximumPoints(uint newMax); + + /** + * @brief set the maximum temperature shown on the plot + * @param maxTemp : number greater then 0 + */ + void setMaximumTemperature(uint maxTemp); + private: class plot { @@ -105,10 +119,16 @@ QLineSeries *_series; QString _name; }; + /** + * @brief Update plot list, need to run after ALL plots added + */ + void update(); + QChartView *_chart; QDateTimeAxis *_axisX; QValueAxis *_axisY; QHash _name2Index; QVector _plots; + int m_maximumPoints; }; diff --git a/src/widgets/plotwidget.cpp b/src/widgets/plotwidget.cpp --- a/src/widgets/plotwidget.cpp +++ b/src/widgets/plotwidget.cpp @@ -23,10 +23,11 @@ #include PlotWidget::PlotWidget(QWidget *parent) : - QWidget(parent), - _chart(new QChartView()), - _axisX(new QDateTimeAxis()), - _axisY(new QValueAxis()) + QWidget(parent) + , _chart(new QChartView()) + , _axisX(new QDateTimeAxis()) + , _axisY(new QValueAxis()) + , m_maximumPoints(24) { QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(_chart); @@ -45,16 +46,9 @@ if (palette().text().color().value() >= QColor(Qt::lightGray).value()) { _chart->chart()->setTheme(QChart::ChartThemeDark); } - - newPlot(tr("Actual Bed")); - newPlot(tr("Target Bed")); - // The extruder need to be added after some signal emitted (ExtruderCountChanged) - newPlot(tr("Actual Ext.1")); - newPlot(tr("Target Ext.1")); - } -void PlotWidget::newPlot(const QString &name) +void PlotWidget::addPlot(const QString &name) { _name2Index[name] = _plots.size(); plot _newPlot; @@ -65,22 +59,41 @@ _plots.append(_newPlot); } -void PlotWidget::deletePlot(const QString &name) +void PlotWidget::removePlot(const QString &name) { _plots.remove(_name2Index[name]); _name2Index.remove(name); } void PlotWidget::appendPoint(const QString &name, float value) { + if (_plots[_name2Index[name]].serie()->count() > m_maximumPoints) { + _plots[_name2Index[name]].serie()->remove(0); + } _plots[_name2Index[name]].pushPoint(value); + update(); } void PlotWidget::update() { _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); } +QStringList PlotWidget::plots() +{ + return _name2Index.keys(); +} + +void PlotWidget::setMaximumPoints(uint newMax) +{ + m_maximumPoints = newMax; +} + +void PlotWidget::setMaximumTemperature(uint maxTemp) +{ + _chart->chart()->axisY()->setRange(0, maxTemp); +} + PlotWidget::~PlotWidget() { } diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -52,29 +52,7 @@ connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged); connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort); - connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist); - - connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { - checkTemperature(0x00, 0, temp); - plotWidget->appendPoint(tr("Actual Bed"), temp); - plotWidget->update(); - }); - connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { - checkTemperature(0x01, 0, temp); - plotWidget->appendPoint(tr("Target Bed"), temp); - plotWidget->update(); - }); - connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { - checkTemperature(0x02, 0, temp); - plotWidget->appendPoint(tr("Actual Ext.1"), temp); - plotWidget->update(); - }); - connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { - checkTemperature(0x03, 0, temp); - plotWidget->appendPoint(tr("Target Ext.1"), temp); - plotWidget->update(); - }); } void MainWindow::initMenu() @@ -192,6 +170,31 @@ void MainWindow::makeTempTimelineDock() { plotWidget = new PlotWidget; + //make and connect our plots in the widget. + plotWidget->addPlot(tr("Actual Bed")); + connect(&core->temperature(), &Temperature::bedTemperatureChanged, [ this ](float temp) { + checkTemperature(0x00, 0, temp); + plotWidget->appendPoint(tr("Actual Bed"), temp); + }); + + plotWidget->addPlot(tr("Target Bed")); + connect(&core->temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](float temp) { + checkTemperature(0x01, 0, temp); + plotWidget->appendPoint(tr("Target Bed"), temp); + }); + + plotWidget->addPlot(tr("Actual Ext.1")); + connect(&core->temperature(), &Temperature::extruderTemperatureChanged, [ this ](float temp) { + checkTemperature(0x02, 0, temp); + plotWidget->appendPoint(tr("Actual Ext.1"), temp); + }); + + plotWidget->addPlot(tr("Target Ext.1")); + connect(&core->temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](float temp) { + checkTemperature(0x03, 0, temp); + plotWidget->appendPoint(tr("Target Ext.1"), temp); + }); + tempTimelineDock = new QDockWidget(tr("Temperature Timeline"), this); tempTimelineDock->setWidget(plotWidget); menuView->insertAction(nullptr, tempTimelineDock->toggleViewAction());