diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,7 @@ #Atelier Dependencies find_package(AtCore REQUIRED COMPONENTS AtCore + AtCoreWidgets ) find_package(Qwt6 REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,6 +12,6 @@ ecm_create_qm_loader(atelier_SRCS atelier) -target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCore::AtCore KF5::XmlGui KF5::ConfigWidgets) +target_link_libraries(atelier AtelierWidgets AtelierDialogs Atelier3D AtCoreWidgets AtCore::AtCore KF5::XmlGui KF5::ConfigWidgets) install(TARGETS atelier RUNTIME DESTINATION bin) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -3,13 +3,10 @@ set(widgets_SRCS gcodeeditorwidget.cpp - axiscontrol.cpp bedextruderwidget.cpp - plotwidget.cpp pushgcodewidget.cpp ratescontrolwidget.cpp printprogresswidget.cpp - logwidget.cpp videomonitorwidget.cpp atcoreinstancewidget.cpp thermowidget.cpp diff --git a/src/widgets/atcoreinstancewidget.h b/src/widgets/atcoreinstancewidget.h --- a/src/widgets/atcoreinstancewidget.h +++ b/src/widgets/atcoreinstancewidget.h @@ -18,6 +18,9 @@ #pragma once #include +#include +#include +#include #include #include #include @@ -69,13 +72,14 @@ QAction *m_stopAction; QSettings m_settings; QString m_theme; + AxisControl *m_axisControl; + LogWidget *m_logWidget; + PlotWidget *m_plotWidget; void initConnectsToAtCore(); void printFile(const QUrl& fileName); void pausePrint(); void stopPrint(); void disableMotors(); - void checkReceivedCommand(const QByteArray &message); - void checkPushedCommands(const QByteArray &bmsg); void handlePrinterStatusChanged(AtCore::STATES newState); void checkTemperature(uint sensorType, uint number, uint temp); void axisControlClicked(QChar axis, int value); diff --git a/src/widgets/atcoreinstancewidget.cpp b/src/widgets/atcoreinstancewidget.cpp --- a/src/widgets/atcoreinstancewidget.cpp +++ b/src/widgets/atcoreinstancewidget.cpp @@ -34,6 +34,22 @@ m_theme = palette().text().color().value() >= QColor(Qt::lightGray).value() ? QString("dark") : QString("light") ; ui = new Ui::AtCoreInstanceWidget; ui->setupUi(this); + + auto layout = new QHBoxLayout(); + m_axisControl = new AxisControl(); + layout->addWidget(m_axisControl); + ui->gridLayout_3->addLayout(layout, 2, 2, Qt::AlignHCenter); + + m_plotWidget = new PlotWidget(); + layout = new QHBoxLayout(); + layout->addWidget(m_plotWidget); + ui->gridLayout_3->addLayout(layout, 3, 0, 1, 3, Qt::AlignHCenter); + + m_logWidget = new LogWidget(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/Atelier_"))); + layout = new QHBoxLayout(); + layout->addWidget(m_logWidget); + ui->gridLayout_2->addLayout(layout, 2, 0, Qt::AlignHCenter); + ui->printProgressWidget->setVisible(false); buildToolbar(); buildConnectionToolbar(); @@ -203,39 +219,39 @@ // Connect AtCore temperatures changes on Atelier Plot connect(&m_core.temperature(), &Temperature::bedTemperatureChanged, [ this ](const float& temp) { checkTemperature(0x00, 0, temp); - ui->plotWidget->appendPoint(i18n("Actual Bed"), temp); - ui->plotWidget->update(); + m_plotWidget->appendPoint(i18n("Actual Bed"), temp); + m_plotWidget->update(); ui->bedExtWidget->updateBedTemp(temp); }); connect(&m_core.temperature(), &Temperature::bedTargetTemperatureChanged, [ this ](const float& temp) { checkTemperature(0x01, 0, temp); - ui->plotWidget->appendPoint(i18n("Target Bed"), temp); - ui->plotWidget->update(); + m_plotWidget->appendPoint(i18n("Target Bed"), temp); + m_plotWidget->update(); ui->bedExtWidget->updateBedTargetTemp(temp); }); connect(&m_core.temperature(), &Temperature::extruderTemperatureChanged, [ this ](const float& temp) { checkTemperature(0x02, 0, temp); - ui->plotWidget->appendPoint(i18n("Actual Ext.1"), temp); - ui->plotWidget->update(); + m_plotWidget->appendPoint(i18n("Actual Ext.1"), temp); + m_plotWidget->update(); ui->bedExtWidget->updateExtTemp(temp); }); connect(&m_core.temperature(), &Temperature::extruderTargetTemperatureChanged, [ this ](const float& temp) { checkTemperature(0x03, 0, temp); - ui->plotWidget->appendPoint(i18n("Target Ext.1"), temp); - ui->plotWidget->update(); + m_plotWidget->appendPoint(i18n("Target Ext.1"), temp); + m_plotWidget->update(); ui->bedExtWidget->updateExtTargetTemp(temp); }); connect(ui->pushGCodeWidget, &PushGCodeWidget::push, [ this ](QString command) { - ui->logWidget->addLog("Push " + command); + m_logWidget->appendLog("Push " + command); m_core.pushCommand(command); }); // Fan, Flow and Speed management connect(ui->ratesControlWidget, &RatesControlWidget::fanSpeedChanged, &m_core, &AtCore::setFanSpeed); connect(ui->ratesControlWidget, &RatesControlWidget::flowRateChanged, &m_core, &AtCore::setFlowRate); connect(ui->ratesControlWidget, &RatesControlWidget::printSpeedChanged, &m_core, &AtCore::setPrinterSpeed); - connect(ui->axisViewWidget, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked); + connect(m_axisControl, &AxisControl::clicked, this, &AtCoreInstanceWidget::axisControlClicked); } void AtCoreInstanceWidget::printFile(const QUrl& fileName) @@ -292,21 +308,21 @@ m_connectToolBar->setHidden(true); m_toolBar->setHidden(false); stateString = i18n("Connecting..."); - connect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); - connect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); + connect(&m_core, &AtCore::receivedMessage, m_logWidget, &LogWidget::appendRLog); + connect(m_core.serial(), &SerialLayer::pushedCommand, m_logWidget, &LogWidget::appendSLog); } break; case AtCore::IDLE: { stateString = i18n("Connected to ") + m_core.serial()->portName(); emit extruderCountChanged(m_core.extruderCount()); - ui->logWidget->addLog(i18n("Serial connected")); + m_logWidget->appendLog(i18n("Serial connected")); emit disableDisconnect(false); enableControls(true); } break; case AtCore::DISCONNECTED: { stateString = i18n("Not Connected"); - disconnect(&m_core, &AtCore::receivedMessage, this, &AtCoreInstanceWidget::checkReceivedCommand); - disconnect(m_core.serial(), &SerialLayer::pushedCommand, this, &AtCoreInstanceWidget::checkPushedCommands); - ui->logWidget->addLog(i18n("Serial disconnected")); + disconnect(&m_core, &AtCore::receivedMessage, m_logWidget, &LogWidget::appendRLog); + disconnect(m_core.serial(), &SerialLayer::pushedCommand, m_logWidget, &LogWidget::appendSLog); + m_logWidget->appendLog(i18n("Serial disconnected")); m_core.setSerialTimerInterval(100); m_connectButton->setText(i18n("Connect")); m_connectButton->setIcon(QIcon::fromTheme("network-connect",QIcon(QString(":/%1/connect").arg(m_theme)))); @@ -383,22 +399,7 @@ msg = msg.arg(QString::number(number)) .arg(QString::number(temp)); - ui->logWidget->addRLog(msg); -} - -void AtCoreInstanceWidget::checkReceivedCommand(const QByteArray &message) -{ - ui->logWidget->addRLog(QString::fromUtf8(message)); -} - -void AtCoreInstanceWidget::checkPushedCommands(const QByteArray &bmsg) -{ - QString msg = QString::fromUtf8(bmsg); - QRegExp _newLine(QChar::fromLatin1('\n')); - QRegExp _return(QChar::fromLatin1('\r')); - msg.replace(_newLine, QStringLiteral("\\n")); - msg.replace(_return, QStringLiteral("\\r")); - ui->logWidget->addSLog(msg); + m_logWidget->appendLog(msg); } void AtCoreInstanceWidget::axisControlClicked(QChar axis, int value) diff --git a/src/widgets/atcoreinstancewidget.ui b/src/widgets/atcoreinstancewidget.ui --- a/src/widgets/atcoreinstancewidget.ui +++ b/src/widgets/atcoreinstancewidget.ui @@ -27,16 +27,10 @@ Controllers - - - - - - - + @@ -46,9 +40,6 @@ Advanced - - - @@ -93,35 +84,18 @@ - - PlotWidget - QWidget -
plotwidget.h
- 1 -
PrintProgressWidget QWidget
printprogresswidget.h
1
- - AxisControl - QGraphicsView -
axiscontrol.h
-
BedExtruderWidget QWidget
bedextruderwidget.h
1
- - LogWidget - QWidget -
logwidget.h
- 1 -
PushGCodeWidget QWidget diff --git a/src/widgets/axiscontrol.h b/src/widgets/axiscontrol.h deleted file mode 100644 --- a/src/widgets/axiscontrol.h +++ /dev/null @@ -1,85 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2016> - Author: Lays Rodrigues - laysrodriguessilva@gmail.com - Chris Rizzitello - rizzitello@kde.org - - 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 . -*/ -#pragma once - -#include -#include -#include - -/* Usage: - * - * Create a instance of PrinterHotendPositionVisualController and - * connect the clicked signal, it will give you the axis and value - * that was clicked. - */ - -class PieButton : public QObject, public QGraphicsEllipseItem -{ - Q_OBJECT -public: - PieButton(QLatin1Char axis, int value, int size, int angle); - void setPalette(QPalette palette); -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *); - void hoverEnterEvent(QGraphicsSceneHoverEvent *); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *); -signals: - void clicked(QLatin1Char axis, int value); -private: - QLatin1Char _axis; - int _value; - QPalette _palette; -}; - -class RectButton : public QObject, public QGraphicsRectItem -{ - Q_OBJECT - -public: - RectButton(QLatin1Char axis, int value, int size); - void setPalette(QPalette palette); -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *); - void hoverEnterEvent(QGraphicsSceneHoverEvent *); - void hoverLeaveEvent(QGraphicsSceneHoverEvent *); -signals: - void clicked(QLatin1Char axis, int value); -private: - QLatin1Char _axis; - int _value; - QPalette _palette; -}; - -class AxisControl : public QGraphicsView -{ - Q_OBJECT - -public: - explicit AxisControl(QWidget *parent = nullptr); - -private: - void setLabels(QGraphicsItem *item, QLatin1Char axis, int value); - -protected: - void resizeEvent(QResizeEvent *); - -signals: - void clicked(QLatin1Char axis, int value); - -}; diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp deleted file mode 100644 --- a/src/widgets/axiscontrol.cpp +++ /dev/null @@ -1,181 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2016> - Author: Lays Rodrigues - laysrodriguessilva@gmail.com - Chris Rizzitello - rizzitello@kde.org - - 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 "axiscontrol.h" - -PieButton::PieButton(QLatin1Char axis, int value, int size, int angle) : _axis(axis), _value(value) -{ - const int delta = 16; // Qt Docs: angle is 16th of a degree. - setBrush(_palette.button()); - setStartAngle(angle * delta); - setSpanAngle(90 * delta); - setRect(QRect(QPoint(size * -1, size * -1), QPoint(size, size))); - setZValue(size * -1); - setAcceptHoverEvents(true); - setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); -} - -void PieButton::setPalette(QPalette palette) -{ - _palette = palette; -} - -void PieButton::mousePressEvent(QGraphicsSceneMouseEvent *) -{ - emit clicked(_axis, _value); -} - -void PieButton::hoverEnterEvent(QGraphicsSceneHoverEvent *) -{ - setBrush(_palette.highlight()); -} - -void PieButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *) -{ - setBrush(_palette.button()); -} - -RectButton::RectButton(QLatin1Char axis, int value, int size) : _axis(axis), _value(value) -{ - setBrush(_palette.button()); - setRect(QRect(QPoint(0, 0), QPoint(size, size))); - setAcceptHoverEvents(true); - setZValue(size * -1); - setToolTip(QStringLiteral("Move the hotend to the %1 by %2 units").arg(axis).arg(value)); -} - -void RectButton::setPalette(QPalette palette) -{ - _palette = palette; -} - -void RectButton::mousePressEvent(QGraphicsSceneMouseEvent *) -{ - emit clicked(_axis, _value); -} - -void RectButton::hoverEnterEvent(QGraphicsSceneHoverEvent *) -{ - setBrush(_palette.highlight()); -} - -void RectButton::hoverLeaveEvent(QGraphicsSceneHoverEvent *) -{ - setBrush(_palette.button()); -} -/* About the Magic Numbers - I don't have experience programming with QGraphicsScene, - Tomaz is helping me, but until we have a better solution, all the values - that are dividing or multiplying the items is based only in tests and errors. - Those values was choosen because it fit better on the alignment of the items - in the scene. If you have a better solution, please share with us. - Lays Rodrigues - Jan/2017 -*/ -AxisControl::AxisControl(QWidget *parent) : - QGraphicsView(parent) -{ - setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform); - - setScene(new QGraphicsScene()); - - auto createPie = [ this ](QLatin1Char axis, int value, int size, int angle) { - auto pie = new PieButton(axis, value, size, angle); - pie->setPalette(this->palette()); - connect(pie, &PieButton::clicked, this, &AxisControl::clicked); - if (abs(value) == 25) { - setLabels(pie, axis, value); - } - scene()->addItem(pie); - }; - - auto createRect = [ this ](QLatin1Char axis, int value, int size, int xPos, int yPos) { - auto z = new RectButton(axis, value, size); - z->setPalette(this->palette()); - z->setPos(xPos, yPos); - connect(z, &RectButton::clicked, this, &AxisControl::clicked); - if (abs(value) == 25) { - setLabels(z, axis, value); - } - scene()->addItem(z); - }; - - int currPieSize = 25; - for (auto value : { - 1, 10, 25 - }) { - createPie(QLatin1Char('X'), value, currPieSize, -45); // Left - createPie(QLatin1Char('X'), value * -1, currPieSize, 135); // Right - createPie(QLatin1Char('Y'), value, currPieSize, 45); // Top - createPie(QLatin1Char('Y'), value * -1, currPieSize, 225); // Bottom - currPieSize += 25; - } - - int currZSize = 25; - int xPos = sceneRect().width() - 50; - int yPos = -75; //Align with the origin of the scene 3 * 25 - for (auto value : { - 25, 10, 1, -1, -10, -25 - }) { - createRect(QLatin1Char('Z'), value, currZSize, xPos, yPos); - yPos += currZSize; - } - setSceneRect(scene()->itemsBoundingRect()); -} - -void AxisControl::resizeEvent(QResizeEvent *) -{ - fitInView(sceneRect(), Qt::KeepAspectRatio); -} - -void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char axis, int value) -{ - auto *lb = new QGraphicsSimpleTextItem(); - lb->setBrush(palette().buttonText()); - - if (this->logicalDpiX() <= 96) { - lb->setText((value < 0) ? QStringLiteral(" -") + axis : QStringLiteral(" ") + axis); - } else { - lb->setText((value < 0) ? QStringLiteral("-") + axis : QStringLiteral(" ") + axis); - } - - if (axis.toLatin1() == 'X') { - lb->setY(item->y() - lb->boundingRect().width()); - if (value < 0) { - lb->setX(item->x() - item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); - } else { - lb->setX(item->x() + item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); - } - } else if (axis.toLatin1() == 'Y') { - lb->setX(item->x() - lb->boundingRect().width() / 2); - if (value < 0) { - lb->setY(item->y() + item->boundingRect().height() / 1.5); - } else { - lb->setY(item->y() - item->boundingRect().height()); - } - } else { - - lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); - -#ifndef Q_OS_WIN - lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); -#else - lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().height()); -#endif - } - scene()->addItem(lb); -} diff --git a/src/widgets/logwidget.h b/src/widgets/logwidget.h deleted file mode 100644 --- a/src/widgets/logwidget.h +++ /dev/null @@ -1,43 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2017> - Author: Lays Rodrigues - laysrodrigues@gmail.com - Chris Rizzitello - rizzitello@kde.org - - 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 . -*/ -#pragma once -#include -#include -#include -#include - -class LogWidget : public QWidget -{ -public: - explicit LogWidget(QWidget *parent = nullptr); - void addLog(QString msg); - void addRLog(QString msg); - void addSLog(QString msg); - -private: - void saveLog(); - QTemporaryFile *logFile; - QPlainTextEdit *log; - QPushButton *btnSave; - QString logHeader(); - QString rLogHeader(); - QString sLogHeader(); - QString getTime(); - void writeTempFile(QString text); -}; diff --git a/src/widgets/logwidget.cpp b/src/widgets/logwidget.cpp deleted file mode 100644 --- a/src/widgets/logwidget.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2017> - Author: Lays Rodrigues - laysrodrigues@gmail.com - Chris Rizzitello - rizzitello@kde.org - - 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 "logwidget.h" -#include -#include -#include -#include -#include - -LogWidget::LogWidget(QWidget *parent) : QWidget(parent), - logFile(new QTemporaryFile(QDir::tempPath() + QStringLiteral("/Atelier_"))) -{ - QVBoxLayout *layout = new QVBoxLayout(); - btnSave = new QPushButton(i18n("Save Logfile")); - log = new QPlainTextEdit(); - log->setReadOnly(true); - log->setMaximumBlockCount(1000); - - layout->addWidget(log); - layout->addWidget(btnSave); - this->setLayout(layout); - - connect(btnSave, &QPushButton::clicked, this, &LogWidget::saveLog); - -} - -void LogWidget::saveLog() -{ - QString fileName = QDir::homePath() + QChar::fromLatin1('/') + QFileInfo(logFile->fileName()).fileName(); - QString saveFileName = QFileDialog::getSaveFileName(this, i18n("Save Log to file"), fileName); - QFile::copy(logFile->fileName(), saveFileName); - logFile->close(); -} - -QString LogWidget::logHeader() -{ - return QStringLiteral("[%1] ").arg(getTime()); -} - -QString LogWidget::rLogHeader() -{ - return QStringLiteral("[%1]< ").arg(getTime()); -} - -QString LogWidget::sLogHeader() -{ - return QStringLiteral("[%1]> ").arg(getTime()); -} - -void LogWidget::writeTempFile(QString text) -{ - /* - A QTemporaryFile will always be opened in QIODevice::ReadWrite mode, - this allows easy access to the data in the file. This function will - return true upon success and will set the fileName() to the unique - filename used. - */ - logFile->open(); - logFile->seek(logFile->size()); - logFile->write(text.toLatin1()); - logFile->putChar('\n'); - logFile->close(); -} - -void LogWidget::addLog(QString msg) -{ - QString message(logHeader() + msg); - log->appendPlainText(message); - writeTempFile(message); -} - -void LogWidget::addRLog(QString msg) -{ - QString message(rLogHeader() + msg); - log->appendPlainText(message); - writeTempFile(message); -} - -void LogWidget::addSLog(QString msg) -{ - QString message(sLogHeader() + msg); - log->appendPlainText(message); - writeTempFile(message); -} - -QString LogWidget::getTime() -{ - return QTime::currentTime().toString(QStringLiteral("hh:mm:ss:zzz")); -} diff --git a/src/widgets/plotwidget.h b/src/widgets/plotwidget.h deleted file mode 100644 --- a/src/widgets/plotwidget.h +++ /dev/null @@ -1,114 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2016> - Author: Patrick José Pereira - patrickjp@kde.org - Tomaz Canabrava - Lays Rodrigues - Chris Rizzitello - - 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 . -*/ - -#pragma once - -#include -#include -#include - -class PlotWidget : public QWidget -{ - Q_OBJECT - -public: - explicit PlotWidget(QWidget *parent = nullptr); - ~PlotWidget(); - - /** - * @brief Create a new plot - * - * @param name p_name: plot name - */ - void newPlot(const QString &name); - - /** - * @brief Delete plot with name - * - * @param name p_name: name - */ - void deletePlot(const QString &name); - - /** - * @brief Append point to plot - * - * @param name p_name: plot name - * @param value p_value: value - */ - void appendPoint(const QString &name, float value); - - /** - * @brief Update plot list, need to run after ALL plots added - * - */ - void update(); -private: - class plot - { - public: - explicit plot() : _series(new QLineSeries()) - { - }; - - ~plot() - { - // Series will be deleted with chart - }; - - void pushPoint(float value) - { - QDateTime now = QDateTime::currentDateTime(); - _series->append(now.toMSecsSinceEpoch(), value); - } - - void setName(const QString &name) - { - _name = name; - _series->setName(_name); - - //Add 3 initial points to plot - QDateTime now = QDateTime::currentDateTime(); - _series->append(now.toMSecsSinceEpoch() - 2 * 60e3, 0.0); - _series->append(now.toMSecsSinceEpoch() - 60e3, 0.0); - _series->append(now.toMSecsSinceEpoch(), 0.0); - } - - QLineSeries *serie() const - { - return _series; - } - - QString name() const - { - return _name; - } - - private: - QLineSeries *_series; - QString _name; - }; - QChartView *_chart; - QDateTimeAxis *_axisX; - QValueAxis *_axisY; - - QHash _name2Index; - QVector _plots; -}; diff --git a/src/widgets/plotwidget.cpp b/src/widgets/plotwidget.cpp deleted file mode 100644 --- a/src/widgets/plotwidget.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* Atelier KDE Printer Host for 3D Printing - Copyright (C) <2016> - Author: Patrick José Pereira - patrickjp@kde.org - Tomaz Canabrava - Lays Rodrigues - Chris Rizzitello - - 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()), - _axisX(new QDateTimeAxis()), - _axisY(new QValueAxis()) -{ - QHBoxLayout *mainLayout = new QHBoxLayout; - mainLayout->addWidget(_chart); - setLayout(mainLayout); - - _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()); - _chart->setRenderHint(QPainter::Antialiasing); - if (palette().text().color().value() >= QColor(Qt::lightGray).value()) { - _chart->chart()->setTheme(QChart::ChartThemeDark); - } - - 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")); - -} - -void PlotWidget::newPlot(const QString &name) -{ - _name2Index[name] = _plots.size(); - plot _newPlot; - _newPlot.setName(name); - _chart->chart()->addSeries(_newPlot.serie()); - _newPlot.serie()->attachAxis(_axisY); - _newPlot.serie()->attachAxis(_axisX); - _plots.append(_newPlot); -} - -void PlotWidget::deletePlot(const QString &name) -{ - _plots.remove(_name2Index[name]); - _name2Index.remove(name); -} - -void PlotWidget::appendPoint(const QString &name, float value) -{ - _plots[_name2Index[name]].pushPoint(value); -} - -void PlotWidget::update() -{ - _chart->chart()->axisX()->setRange(QDateTime::currentDateTime().addSecs(-120), QDateTime::currentDateTime()); -} - -PlotWidget::~PlotWidget() -{ -}