diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -186,7 +186,7 @@ * @return State of the printer * @sa setState(),stateChanged(),AtCore::STATES */ - AtCore::STATES state(void); + AtCore::STATES state(); /** * @brief extruderCount diff --git a/src/core/atcore.cpp b/src/core/atcore.cpp --- a/src/core/atcore.cpp +++ b/src/core/atcore.cpp @@ -48,26 +48,26 @@ * Provides a private data set for atcore. */ struct AtCore::AtCorePrivate { - IFirmware *firmwarePlugin = nullptr;//!< @param firmwarePlugin: pointer to firmware plugin - SerialLayer *serial = nullptr; //!< @param serial: pointer to the serial layer - QPluginLoader pluginLoader; //!< @param pluginLoader: QPluginLoader - QMap plugins; //!< @param plugins: Map of plugins name / path - QByteArray lastMessage; //!< @param lastMessage: lastMessage from the printer - int extruderCount = 1; //!< @param extruderCount: extruder count - Temperature temperature; //!< @param temperature: Temperature object - QStringList commandQueue; //!< @param commandQueue: the list of commands to send to the printer - bool ready = false; //!< @param ready: True if printer is ready for a command - QTimer *tempTimer = nullptr; //!< @param tempTimer: timer connected to the checkTemperature function - float percentage; //!< @param percentage: print job percent - QByteArray posString; //!< @param posString: stored string from last M114 return - AtCore::STATES printerState; //!< @param printerState: State of the Printer - QStringList serialPorts; //!< @param seralPorts: Detected serial Ports - QTimer *serialTimer = nullptr; //!< @param serialTimer: Timer connected to locateSerialPorts - bool sdCardMounted = false; //!< @param sdCardMounted: True if Sd Card is mounted. - bool sdCardReadingFileList = false; //!< @param sdCardReadingFileList: True while getting file names from sd card - bool sdCardPrinting = false; //!< @param sdCardPrinting: True if currently printing from sd card. - QString sdCardFileName; //!< @param sdCardFileName: name of file being used from sd card. - QStringList sdCardFileList; //!< @param sdCardFileList: List of files on sd card. + IFirmware *firmwarePlugin = nullptr; //!< @param firmwarePlugin: pointer to firmware plugin + SerialLayer *serial = nullptr; //!< @param serial: pointer to the serial layer + QPluginLoader pluginLoader; //!< @param pluginLoader: QPluginLoader + QMap plugins; //!< @param plugins: Map of plugins name / path + QByteArray lastMessage; //!< @param lastMessage: lastMessage from the printer + int extruderCount = 1; //!< @param extruderCount: extruder count + Temperature temperature; //!< @param temperature: Temperature object + QStringList commandQueue; //!< @param commandQueue: the list of commands to send to the printer + bool ready = false; //!< @param ready: True if printer is ready for a command + QTimer *tempTimer = nullptr; //!< @param tempTimer: timer connected to the checkTemperature function + float percentage = float(0); //!< @param percentage: print job percent + QByteArray posString; //!< @param posString: stored string from last M114 return + AtCore::STATES printerState = AtCore::DISCONNECTED; //!< @param printerState: State of the Printer + QStringList serialPorts; //!< @param seralPorts: Detected serial Ports + QTimer *serialTimer = nullptr; //!< @param serialTimer: Timer connected to locateSerialPorts + bool sdCardMounted = false; //!< @param sdCardMounted: True if Sd Card is mounted. + bool sdCardReadingFileList = false; //!< @param sdCardReadingFileList: True while getting file names from sd card + bool sdCardPrinting = false; //!< @param sdCardPrinting: True if currently printing from sd card. + QString sdCardFileName; //!< @param sdCardFileName: name of file being used from sd card. + QStringList sdCardFileList; //!< @param sdCardFileList: List of files on sd card. }; AtCore::AtCore(QObject *parent) : @@ -139,10 +139,14 @@ qCDebug(ATCORE_CORE) << "Waiting requestFirmware."; QTimer::singleShot(500, this, &AtCore::requestFirmware); return; - } else if (message.contains("Grbl")) { + } + + if (message.contains("Grbl")) { loadFirmwarePlugin(QString::fromLatin1("grbl")); return; - } else if (message.contains("Smoothie")) { + } + + if (message.contains("Smoothie")) { loadFirmwarePlugin(QString::fromLatin1("smoothie")); return; } @@ -225,11 +229,12 @@ connect(d->serial, &SerialLayer::receivedCommand, this, &AtCore::findFirmware); d->serialTimer->stop(); return true; - } else { - qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; - emit atcoreMessage(tr("Failed to open device in read/write mode.")); - return false; } + + qCDebug(ATCORE_CORE) << "Failed to open device for Read / Write."; + emit atcoreMessage(tr("Failed to open device in read/write mode.")); + return false; + } bool AtCore::serialInitialized() const @@ -362,8 +367,8 @@ //Process the gcode with a printThread. //The Thread processes the gcode without freezing the libary. //Only sends a command back when the printer is ready, avoiding buffer overflow in the printer. - QThread *thread = new QThread(); - PrintThread *printThread = new PrintThread(this, fileName); + auto thread = new QThread(); + auto printThread = new PrintThread(this, fileName); printThread->moveToThread(thread); connect(printThread, &PrintThread::printProgressChanged, this, &AtCore::printProgressChanged, Qt::QueuedConnection); @@ -421,17 +426,17 @@ } } -AtCore::STATES AtCore::state(void) +AtCore::STATES AtCore::state() { return d->printerState; } void AtCore::setState(AtCore::STATES state) { if (state != d->printerState) { qCDebug(ATCORE_CORE) << QStringLiteral("Atcore state changed from [%1] to [%2]") - .arg(QVariant::fromValue(d->printerState).value(), - QVariant::fromValue(state).value()); + .arg(QVariant::fromValue(d->printerState).toString(), + QVariant::fromValue(state).toString()); d->printerState = state; if (state == AtCore::STATES::FINISHEDPRINT && d->sdCardPrinting) { //Clean up the sd card print @@ -495,11 +500,7 @@ bool AtCore::firmwarePluginLoaded() const { - if (firmwarePlugin()) { - return true; - } else { - return false; - } + return firmwarePlugin(); } QMap AtCore::findFirmwarePlugins(const QString &path) diff --git a/src/core/gcodecommands.cpp b/src/core/gcodecommands.cpp --- a/src/core/gcodecommands.cpp +++ b/src/core/gcodecommands.cpp @@ -535,12 +535,12 @@ return code; case M104: - code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1).arg(value2)); + code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1, value2)); code = value1.isEmpty() ? GCode::commandRequiresArgument.arg(QStringLiteral("M"), QString::number(gcode)) : code ; return code; case M106: - code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1).arg(value2)); + code = value2.isEmpty() ? code.append(QStringLiteral(" S%1").arg(value1)) : code.append(QStringLiteral(" P%1 S%2").arg(value1, value2)); code = value1.isEmpty() ? QStringLiteral("M106") : code ; return code; diff --git a/src/core/ifirmware.cpp b/src/core/ifirmware.cpp --- a/src/core/ifirmware.cpp +++ b/src/core/ifirmware.cpp @@ -43,6 +43,8 @@ { } +IFirmware::~IFirmware() = default; + void IFirmware::init(AtCore *parent) { d->parent = parent; @@ -54,10 +56,6 @@ return d->parent; } -IFirmware::~IFirmware() -{ -} - void IFirmware::checkCommand(const QByteArray &lastMessage) { validateCommand(QString::fromLatin1(lastMessage)); diff --git a/src/core/printthread.h b/src/core/printthread.h --- a/src/core/printthread.h +++ b/src/core/printthread.h @@ -43,7 +43,7 @@ * @param parent: Parent of the tread * @param fileName: gcode File to print */ - PrintThread(AtCore *parent, QString fileName); + PrintThread(AtCore *parent, const QString &fileName); signals: /** * @brief Print job has finished diff --git a/src/core/printthread.cpp b/src/core/printthread.cpp --- a/src/core/printthread.cpp +++ b/src/core/printthread.cpp @@ -55,7 +55,7 @@ }; //!<@param options: injectable commands. }; -PrintThread::PrintThread(AtCore *parent, QString fileName) : d(new PrintThreadPrivate) +PrintThread::PrintThread(AtCore *parent, const QString &fileName) : d(new PrintThreadPrivate) { d->core = parent; d->state = d->core->state(); @@ -176,8 +176,8 @@ } if (newState != d->state) { qCDebug(PRINT_THREAD) << QStringLiteral("State changed from [%1] to [%2]") - .arg(QVariant::fromValue(d->state).value(), - QVariant::fromValue(newState).value()); + .arg(QVariant::fromValue(d->state).toString(), + QVariant::fromValue(newState).toString()); disconnect(d->core, &AtCore::stateChanged, this, &PrintThread::setState); d->state = newState; emit stateChanged(d->state); diff --git a/src/core/seriallayer.cpp b/src/core/seriallayer.cpp --- a/src/core/seriallayer.cpp +++ b/src/core/seriallayer.cpp @@ -56,11 +56,11 @@ class SerialLayer::SerialLayerPrivate { public: - bool _serialOpened; //!< @param _serialOpened: is serial port opened - QSerialPort::SerialPortError _lastError; //!< @param _lastError: the last reported error - QByteArray _rawData; //!< @param _rawData: the raw serial data - QVector _rByteCommands; //!< @param _rByteCommand: received Messages - QVector _sByteCommands; //!< @param _sByteCommand: sent Messages + bool _serialOpened = false; //!< @param _serialOpened: is serial port opened + QSerialPort::SerialPortError _lastError = QSerialPort::NoError; //!< @param _lastError: the last reported error + QByteArray _rawData; //!< @param _rawData: the raw serial data + QVector _rByteCommands; //!< @param _rByteCommand: received Messages + QVector _sByteCommands; //!< @param _sByteCommand: sent Messages }; SerialLayer::SerialLayer(const QString &port, int32_t baud, QObject *parent) : diff --git a/src/widgets/about.cpp b/src/widgets/about.cpp --- a/src/widgets/about.cpp +++ b/src/widgets/about.cpp @@ -32,41 +32,38 @@ setWindowTitle(QStringLiteral("About Atcore")); setWindowIcon(QIcon::fromTheme(QStringLiteral("help-about"), style()->standardIcon(QStyle::SP_MessageBoxInformation))); - QLabel *lbl_version = new QLabel(tr("Version: %1").arg(QCoreApplication::applicationVersion())); - QLabel *lbl_qt_version = new QLabel(tr("Using Qt: %1").arg(QString::fromLatin1(qVersion()))); - QLabel *lbl_authors = new QLabel(tr("Authors:\n" - " Chris Rizzitello \n" - " Patrick José Pereira \n" - " Lays Rodrigues \n" - " Tomaz Canabrava " - "")); + auto lbl_version = new QLabel(tr("Version: %1").arg(QCoreApplication::applicationVersion())); + auto lbl_qt_version = new QLabel(tr("Using Qt: %1").arg(QString::fromLatin1(qVersion()))); + auto lbl_authors = new QLabel(tr("Authors:\n" + " Chris Rizzitello \n" + " Patrick José Pereira \n" + " Lays Rodrigues \n" + " Tomaz Canabrava " + "")); - QLabel *lbl_icon = new QLabel(); + auto lbl_icon = new QLabel(); lbl_icon->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); lbl_icon->setScaledContents(true); lbl_icon->setPixmap(QPixmap(QStringLiteral(":/icon/atcore"))); - QPushButton *btn_close = new QPushButton(tr("Close")); + auto btn_close = new QPushButton(tr("Close")); connect(btn_close, &QPushButton::clicked, this, &QDialog::close); - QVBoxLayout *versionInfo = new QVBoxLayout; + auto versionInfo = new QVBoxLayout; versionInfo->addWidget(lbl_version); versionInfo->addWidget(lbl_qt_version); - QVBoxLayout *topLayout = new QVBoxLayout; + auto topLayout = new QVBoxLayout; topLayout->setContentsMargins(0, 0, 0, 0); topLayout->addWidget(lbl_icon); topLayout->addItem(versionInfo); - QVBoxLayout *mainLayout = new QVBoxLayout; + auto mainLayout = new QVBoxLayout; mainLayout->addItem(topLayout); mainLayout->addWidget(lbl_authors); mainLayout->addWidget(btn_close); setLayout(mainLayout); } -About::~About() -{ - -} +About::~About() = default; diff --git a/src/widgets/logwidget.h b/src/widgets/logwidget.h --- a/src/widgets/logwidget.h +++ b/src/widgets/logwidget.h @@ -73,7 +73,7 @@ * @brief Append text in temporary file * @param text */ - void writeTempFile(QString text); + void writeTempFile(const QString &text); /** * @brief flush unwritten strings to temp file diff --git a/src/widgets/logwidget.cpp b/src/widgets/logwidget.cpp --- a/src/widgets/logwidget.cpp +++ b/src/widgets/logwidget.cpp @@ -30,18 +30,18 @@ logFile(tempFile) { QSize iconSize = QSize(fontMetrics().height(), fontMetrics().height()); - auto *page = new QWidget; + auto page = new QWidget(this); textLog = new QPlainTextEdit; textLog->setReadOnly(true); textLog->setMaximumBlockCount(1000); auto pageLayout = new QVBoxLayout; pageLayout->addWidget(textLog); page->setLayout(pageLayout); - QStackedWidget *mainStack = new QStackedWidget; + auto mainStack = new QStackedWidget; mainStack->insertWidget(0, page); - page = new QWidget; + page = new QWidget(this); auto textbox = new QTextEdit; textbox->setReadOnly(true); textbox->setHtml(tr("\ @@ -117,7 +117,7 @@ writeTempFile(message); } -void LogWidget::writeTempFile(QString text) +void LogWidget::writeTempFile(const QString &text) { //Add text to our unsynced string list when that hits 100 sync to the temp file. unsyncedStrings.append(text); diff --git a/src/widgets/plotwidget.cpp b/src/widgets/plotwidget.cpp --- a/src/widgets/plotwidget.cpp +++ b/src/widgets/plotwidget.cpp @@ -44,7 +44,7 @@ _chart->chart()->setTheme(QChart::ChartThemeDark); } - QHBoxLayout *mainLayout = new QHBoxLayout; + auto mainLayout = new QHBoxLayout; mainLayout->addWidget(_chart); setLayout(mainLayout); } @@ -94,6 +94,4 @@ _chart->chart()->axisY()->setRange(0, maxTemp); } -PlotWidget::~PlotWidget() -{ -} +PlotWidget::~PlotWidget() = default; diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp --- a/src/widgets/printwidget.cpp +++ b/src/widgets/printwidget.cpp @@ -109,7 +109,7 @@ setLayout(mainLayout); } -QString PrintWidget::postPauseCommand(void) const +QString PrintWidget::postPauseCommand() const { return linePostPause->text(); } diff --git a/unittests/atcoretests.cpp b/unittests/atcoretests.cpp --- a/unittests/atcoretests.cpp +++ b/unittests/atcoretests.cpp @@ -139,7 +139,7 @@ core->clearSdCardFileList(); args = sSpy.takeLast(); - QVERIFY(args.at(0).toStringList() == QStringList()); + QVERIFY(args.at(0).toStringList().isEmpty()); } void AtCoreTests::testSerialTimerIntervalChanged()