diff --git a/src/core/atcore.h b/src/core/atcore.h --- a/src/core/atcore.h +++ b/src/core/atcore.h @@ -120,6 +120,7 @@ * @param parent: parent of the object */ explicit AtCore(QObject *parent = nullptr); + ~AtCore() = default; /** * @brief version @@ -186,7 +187,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,46 @@ * 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. + /** firmwarePlugin: pointer to firmware plugin */ + IFirmware *firmwarePlugin = nullptr; + /** serial: pointer to the serial layer */ + SerialLayer *serial = nullptr; + /** pluginLoader: QPluginLoader */ + QPluginLoader pluginLoader; + /** plugins: Map of plugins name / path */ + QMap plugins; + /** lastMessage: lastMessage from the printer */ + QByteArray lastMessage; + /** extruderCount: extruder count */ + int extruderCount = 1; + /** temperature: Temperature object */ + Temperature temperature; + /** commandQueue: the list of commands to send to the printer */ + QStringList commandQueue; + /** ready: True if printer is ready for a command */ + bool ready = false; + /** tempTimer: timer connected to the checkTemperature function */ + QTimer *tempTimer = nullptr; + /** percentage: print job percent */ + float percentage = 0.0; + /** posString: stored string from last M114 return */ + QByteArray posString; + /** printerState: State of the Printer */ + AtCore::STATES printerState = AtCore::DISCONNECTED; + /** seralPorts: Detected serial Ports */ + QStringList serialPorts; + /** serialTimer: Timer connected to locateSerialPorts */ + QTimer *serialTimer = nullptr; + /** sdCardMounted: True if Sd Card is mounted. */ + bool sdCardMounted = false; + /** sdCardReadingFileList: True while getting file names from sd card */ + bool sdCardReadingFileList = false; + /** sdCardPrinting: True if currently printing from sd card. */ + bool sdCardPrinting = false; + /** sdCardFileName: name of file being used from sd card. */ + QString sdCardFileName; + /** sdCardFileList: List of files on sd card. */ + QStringList sdCardFileList; }; AtCore::AtCore(QObject *parent) : @@ -139,10 +159,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; } @@ -217,19 +241,19 @@ disableResetOnConnect(port); } - d->serial = new SerialLayer(port, baud); + d->serial = new SerialLayer(port, baud, this); connect(d->serial, &SerialLayer::serialError, this, &AtCore::handleSerialError); if (serialInitialized() && d->serial->isWritable()) { setState(AtCore::CONNECTING); connect(d->serial, &SerialLayer::pushedCommand, this, &AtCore::newCommand); 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 +386,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(this); + auto printThread = new PrintThread(this, fileName); printThread->moveToThread(thread); connect(printThread, &PrintThread::printProgressChanged, this, &AtCore::printProgressChanged, Qt::QueuedConnection); @@ -421,17 +445,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 +519,7 @@ bool AtCore::firmwarePluginLoaded() const { - if (firmwarePlugin()) { - return true; - } else { - return false; - } + return firmwarePlugin(); } QMap AtCore::findFirmwarePlugins(const QString &path) @@ -807,7 +827,7 @@ { #if defined(Q_OS_UNIX) //should work on all unix' - QProcess process; + QProcess process(this); QStringList args({QStringLiteral("-F/dev/%1").arg(port), QStringLiteral("-hupcl")}); process.start(QStringLiteral("stty"), args); process.waitForFinished(500); 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.h b/src/core/ifirmware.h --- a/src/core/ifirmware.h +++ b/src/core/ifirmware.h @@ -44,7 +44,7 @@ public: IFirmware(); void init(AtCore *parent); - ~IFirmware() override; + ~IFirmware() override = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/core/ifirmware.cpp b/src/core/ifirmware.cpp --- a/src/core/ifirmware.cpp +++ b/src/core/ifirmware.cpp @@ -45,6 +45,7 @@ void IFirmware::init(AtCore *parent) { + setParent(parent); d->parent = parent; connect(d->parent, &AtCore::receivedMessage, this, &IFirmware::checkCommand); } @@ -54,18 +55,14 @@ return d->parent; } -IFirmware::~IFirmware() -{ -} - void IFirmware::checkCommand(const QByteArray &lastMessage) { validateCommand(QString::fromLatin1(lastMessage)); } void IFirmware::validateCommand(const QString &lastMessage) { - if (lastMessage.contains(d->_ok)) { + if (lastMessage.contains(IFirmwarePrivate::_ok)) { emit readyForCommand(); } } 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,16 @@ 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 + /** _serialOpened: is Serial port opened */ + bool _serialOpened = false; + /** _lastError: the last reported error */ + QSerialPort::SerialPortError _lastError = QSerialPort::NoError; + /** _rawData: the raw serial data */ + QByteArray _rawData; + /** _rByteCommand: received Messages */ + QVector _rByteCommands; + /** _sByteCommand: sent Messages */ + QVector _sByteCommands; }; SerialLayer::SerialLayer(const QString &port, int32_t baud, QObject *parent) : diff --git a/src/plugins/aprinterplugin.h b/src/plugins/aprinterplugin.h --- a/src/plugins/aprinterplugin.h +++ b/src/plugins/aprinterplugin.h @@ -42,7 +42,7 @@ * @brief Create new AprinterPlugin */ AprinterPlugin(); - + ~AprinterPlugin() = default; /** * @brief Check for plugin support of sd cards. * @return True if firmware plugin supports sd cards. diff --git a/src/plugins/grblplugin.h b/src/plugins/grblplugin.h --- a/src/plugins/grblplugin.h +++ b/src/plugins/grblplugin.h @@ -42,6 +42,7 @@ * @brief Create new GrblPlugin */ GrblPlugin(); + ~GrblPlugin() = default; /** * @brief Return Plugin name diff --git a/src/plugins/marlinplugin.h b/src/plugins/marlinplugin.h --- a/src/plugins/marlinplugin.h +++ b/src/plugins/marlinplugin.h @@ -42,6 +42,7 @@ * @brief Create new MarlinPlugin */ MarlinPlugin(); + ~MarlinPlugin() = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/plugins/repetierplugin.h b/src/plugins/repetierplugin.h --- a/src/plugins/repetierplugin.h +++ b/src/plugins/repetierplugin.h @@ -42,6 +42,7 @@ * @brief Create new RepetierPlugin */ RepetierPlugin(); + ~RepetierPlugin() = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/plugins/smoothieplugin.h b/src/plugins/smoothieplugin.h --- a/src/plugins/smoothieplugin.h +++ b/src/plugins/smoothieplugin.h @@ -42,6 +42,7 @@ * @brief Create new SmoothiePlugin */ SmoothiePlugin(); + ~SmoothiePlugin() = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/plugins/sprinterplugin.h b/src/plugins/sprinterplugin.h --- a/src/plugins/sprinterplugin.h +++ b/src/plugins/sprinterplugin.h @@ -42,6 +42,7 @@ * @brief Create new SprinterPlugin */ SprinterPlugin(); + ~SprinterPlugin() = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/plugins/teacupplugin.h b/src/plugins/teacupplugin.h --- a/src/plugins/teacupplugin.h +++ b/src/plugins/teacupplugin.h @@ -42,6 +42,7 @@ * @brief Create new TeacupPlugin */ TeacupPlugin(); + ~TeacupPlugin() = default; /** * @brief Check for plugin support of sd cards. diff --git a/src/widgets/about.h b/src/widgets/about.h --- a/src/widgets/about.h +++ b/src/widgets/about.h @@ -34,6 +34,6 @@ Q_OBJECT public: explicit About(QWidget *parent = 0); - ~About(); + ~About() = default; }; #endif // ABOUT_H 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,36 @@ 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()), this); + auto lbl_qt_version = new QLabel(tr("Using Qt: %1").arg(QString::fromLatin1(qVersion())), this); + 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(this); 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"), this); 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() -{ - -} diff --git a/src/widgets/axiscontrol.cpp b/src/widgets/axiscontrol.cpp --- a/src/widgets/axiscontrol.cpp +++ b/src/widgets/axiscontrol.cpp @@ -28,13 +28,13 @@ , sbValue(new QDoubleSpinBox) { auto mainLayout = new QVBoxLayout; - auto newLabel = new QLabel(tr("Move Axis")); + auto newLabel = new QLabel(tr("Move Axis"), this); sbValue->setSuffix(QStringLiteral(" mm")); sbValue->setDecimals(3); sbValue->setMaximum(100.0); sbValue->setValue(1); - auto comboUnits = new QComboBox(); + auto comboUnits = new QComboBox(this); comboUnits->addItems(QStringList {QStringLiteral("Metric"), QStringLiteral("Imperial")}); connect(comboUnits, QOverload::of(&QComboBox::currentIndexChanged), this, [this](int selection) { @@ -51,14 +51,14 @@ layout->addWidget(sbValue); layout->addWidget(comboUnits); - auto newWidget = new QWidget(); + auto newWidget = new QWidget(this); newWidget->setLayout(layout); newWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); mainLayout->addWidget(newWidget); QSize iconSize = QSize(fontMetrics().height(), fontMetrics().height()); auto glayout = new QGridLayout(); - newLabel = new QLabel(QStringLiteral("X/Y")); + newLabel = new QLabel(QStringLiteral("X/Y"), this); newLabel->setAlignment(Qt::AlignCenter); glayout->addWidget(newLabel, 2, 1); @@ -85,7 +85,7 @@ QPushButton *AxisControl::makeButton(const QLatin1Char axis, int multiplier, const QSize &iconSize, const QString &themeIcon, const QString &fallbackText) { - auto button = new QPushButton(QIcon::fromTheme(themeIcon), QString()); + auto button = new QPushButton(QIcon::fromTheme(themeIcon), QString(), this); button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); if (button->icon().isNull()) { button->setText(fallbackText); @@ -110,14 +110,14 @@ vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-up"), QStringLiteral("↑"))); - auto label = new QLabel(QString(axis)); + auto label = new QLabel(QString(axis), this); label->setAlignment(Qt::AlignCenter); vLayout->addWidget(label); multiplier *= -1; vLayout->addWidget(makeButton(axis, multiplier, iconSize, QStringLiteral("arrow-down"), QStringLiteral("↓"))); - auto widget = new QWidget(); + auto widget = new QWidget(this); widget->setLayout(vLayout); return widget; } diff --git a/src/widgets/commandwidget.h b/src/widgets/commandwidget.h --- a/src/widgets/commandwidget.h +++ b/src/widgets/commandwidget.h @@ -32,6 +32,7 @@ Q_OBJECT public: CommandWidget(QWidget *parent = nullptr); + ~CommandWidget() = default; signals: /** diff --git a/src/widgets/commandwidget.cpp b/src/widgets/commandwidget.cpp --- a/src/widgets/commandwidget.cpp +++ b/src/widgets/commandwidget.cpp @@ -31,11 +31,11 @@ //Begin making content from top to bottom or left to right. //Making child layouts in the order you want to put them // onto the mainLayout - lineCommand = new QLineEdit; + lineCommand = new QLineEdit(this); lineCommand->setPlaceholderText(tr("Send Command")); //we have a few buttons to make here. Lets name this newButton so its easier to reuse - auto newButton = new QPushButton(tr("Send")); + auto newButton = new QPushButton(tr("Send"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit commandPressed(lineCommand->text()); lineCommand->clear(); @@ -49,11 +49,11 @@ mainLayout->addLayout(hBoxLayout); //Start making items for the next layout to place onto the mainLayout. - lineMessage = new QLineEdit; + lineMessage = new QLineEdit(this); lineMessage->setPlaceholderText(tr("Show Message")); //Reuse our button pointer. - newButton = new QPushButton(tr("Send")); + newButton = new QPushButton(tr("Send"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit messagePressed(lineMessage->text()); 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,19 +30,19 @@ logFile(tempFile) { QSize iconSize = QSize(fontMetrics().height(), fontMetrics().height()); - auto *page = new QWidget; - textLog = new QPlainTextEdit; + auto page = new QWidget(this); + textLog = new QPlainTextEdit(this); textLog->setReadOnly(true); textLog->setMaximumBlockCount(1000); auto pageLayout = new QVBoxLayout; pageLayout->addWidget(textLog); page->setLayout(pageLayout); - QStackedWidget *mainStack = new QStackedWidget; + auto mainStack = new QStackedWidget(this); mainStack->insertWidget(0, page); - page = new QWidget; - auto textbox = new QTextEdit; + page = new QWidget(this); + auto textbox = new QTextEdit(this); textbox->setReadOnly(true); textbox->setHtml(tr("\

Special Log Entries

\ @@ -63,11 +63,11 @@ page->setLayout(pageLayout); mainStack->insertWidget(1, page); - auto saveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("document-save"), style()->standardIcon(QStyle::SP_DialogSaveButton)), tr("Save Session Log")); + auto saveButton = new QPushButton(QIcon::fromTheme(QStringLiteral("document-save"), style()->standardIcon(QStyle::SP_DialogSaveButton)), tr("Save Session Log"), this); saveButton->setIconSize(iconSize); connect(saveButton, &QPushButton::clicked, this, &LogWidget::savePressed); - auto helpButton = new QToolButton(); + auto helpButton = new QToolButton(this); helpButton->setCheckable(true); helpButton->setChecked(false); helpButton->setIconSize(iconSize); @@ -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/movementwidget.h b/src/widgets/movementwidget.h --- a/src/widgets/movementwidget.h +++ b/src/widgets/movementwidget.h @@ -36,6 +36,7 @@ * @param parent: Parent of this widget. */ MovementWidget(bool showHomeAndDisableWidgets = true, QWidget *parent = nullptr); + ~MovementWidget() = default; signals: /** diff --git a/src/widgets/movementwidget.cpp b/src/widgets/movementwidget.cpp --- a/src/widgets/movementwidget.cpp +++ b/src/widgets/movementwidget.cpp @@ -27,50 +27,50 @@ { auto mainLayout = new QVBoxLayout; auto hBoxLayout = new QHBoxLayout; - auto newButton = new QPushButton; + auto newButton = new QPushButton(this); if (showHomeAndDisableWidgets) { - newButton = new QPushButton(tr("Home All")); + newButton = new QPushButton(tr("Home All"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit homeAllPressed(); }); - newButton = new QPushButton(tr("Home X")); + newButton = new QPushButton(tr("Home X"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit homeXPressed(); }); - newButton = new QPushButton(tr("Home Y")); + newButton = new QPushButton(tr("Home Y"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit homeYPressed(); }); - newButton = new QPushButton(tr("Home Z")); + newButton = new QPushButton(tr("Home Z"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit homeZPressed(); }); mainLayout->addLayout(hBoxLayout); - newButton = new QPushButton(tr("Disable Motors")); + newButton = new QPushButton(tr("Disable Motors"), this); mainLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit disableMotorsPressed(); }); } - comboMoveAxis = new QComboBox; + comboMoveAxis = new QComboBox(this); comboMoveAxis->addItem(tr("Move X Axis to")); comboMoveAxis->addItem(tr("Move Y Axis to")); comboMoveAxis->addItem(tr("Move Z Axis to")); - sbMoveAxis = new QDoubleSpinBox; + sbMoveAxis = new QDoubleSpinBox(this); sbMoveAxis->setRange(0, 200); - newButton = new QPushButton(tr("Go")); + newButton = new QPushButton(tr("Go"), this); connect(newButton, &QPushButton::clicked, this, [this] { if (comboMoveAxis->currentIndex() == 0) { @@ -90,7 +90,7 @@ hBoxLayout->addWidget(newButton); mainLayout->addLayout(hBoxLayout); - auto axisControl = new AxisControl; + auto axisControl = new AxisControl(this); mainLayout->addWidget(axisControl); connect(axisControl, &AxisControl::clicked, this, &MovementWidget::relativeMove); connect(axisControl, &AxisControl::unitsChanged, this, &MovementWidget::unitsChanged); diff --git a/src/widgets/plotwidget.h b/src/widgets/plotwidget.h --- a/src/widgets/plotwidget.h +++ b/src/widgets/plotwidget.h @@ -35,7 +35,7 @@ public: explicit PlotWidget(QWidget *parent = nullptr); - ~PlotWidget(); + ~PlotWidget() = default; /** * @brief Create a new plot 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); } @@ -93,7 +93,3 @@ { _chart->chart()->axisY()->setRange(0, maxTemp); } - -PlotWidget::~PlotWidget() -{ -} diff --git a/src/widgets/printwidget.cpp b/src/widgets/printwidget.cpp --- a/src/widgets/printwidget.cpp +++ b/src/widgets/printwidget.cpp @@ -29,12 +29,12 @@ QLabel *newLabel = nullptr; QHBoxLayout *hBoxLayout = nullptr; if (showAllControls) { - buttonPrint = new QPushButton(tr("Print File")); + buttonPrint = new QPushButton(tr("Print File"), this); connect(buttonPrint, &QPushButton::clicked, this, [this] { emit printPressed(); }); - newButton = new QPushButton(tr("Emergency Stop")); + newButton = new QPushButton(tr("Emergency Stop"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit emergencyStopPressed(); }); @@ -44,24 +44,24 @@ hBoxLayout->addWidget(newButton); mainLayout->addLayout(hBoxLayout); - newLabel = new QLabel(tr("On Pause:")); + newLabel = new QLabel(tr("On Pause:"), this); - linePostPause = new QLineEdit; + linePostPause = new QLineEdit(this); linePostPause->setPlaceholderText(QStringLiteral("G91,G0 Z1,G90,G1 X0 Y195")); hBoxLayout = new QHBoxLayout; hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(linePostPause); mainLayout->addLayout(hBoxLayout); } - newLabel = new QLabel(tr("Printer Speed")); - sbPrintSpeed = new QSpinBox; + newLabel = new QLabel(tr("Printer Speed"), this); + sbPrintSpeed = new QSpinBox(this); sbPrintSpeed->setRange(1, 300); sbPrintSpeed->setValue(100); sbPrintSpeed->setSuffix(QStringLiteral("%")); - newButton = new QPushButton(tr("Set")); + newButton = new QPushButton(tr("Set"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit printSpeedChanged(sbPrintSpeed->value()); }); @@ -72,13 +72,13 @@ hBoxLayout->addWidget(newButton, 20); mainLayout->addLayout(hBoxLayout); - newLabel = new QLabel(tr("Flow Rate")); - sbFlowRate = new QSpinBox; + newLabel = new QLabel(tr("Flow Rate"), this); + sbFlowRate = new QSpinBox(this); sbFlowRate->setRange(1, 300); sbFlowRate->setValue(100); sbFlowRate->setSuffix(QStringLiteral("%")); - newButton = new QPushButton(tr("Set")); + newButton = new QPushButton(tr("Set"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit flowRateChanged(sbFlowRate->value()); }); @@ -88,12 +88,12 @@ hBoxLayout->addWidget(newButton, 20); mainLayout->addLayout(hBoxLayout); - comboFanSelect = new QComboBox; - sbFanSpeed = new QSpinBox; + comboFanSelect = new QComboBox(this); + sbFanSpeed = new QSpinBox(this); sbFanSpeed->setRange(0, 100); sbFanSpeed->setSuffix(QStringLiteral("%")); - newButton = new QPushButton(tr("Set")); + newButton = new QPushButton(tr("Set"), this); connect(newButton, &QPushButton::clicked, this, [this] { //Fan speed has a range of 0-255. int speed = sbFanSpeed->value() * 255 / 100; @@ -109,7 +109,7 @@ setLayout(mainLayout); } -QString PrintWidget::postPauseCommand(void) const +QString PrintWidget::postPauseCommand() const { return linePostPause->text(); } diff --git a/src/widgets/sdwidget.h b/src/widgets/sdwidget.h --- a/src/widgets/sdwidget.h +++ b/src/widgets/sdwidget.h @@ -34,6 +34,7 @@ * @param parent */ SdWidget(QWidget *parent = nullptr); + ~SdWidget() = default; /** * @brief update the list of files on the card. diff --git a/src/widgets/sdwidget.cpp b/src/widgets/sdwidget.cpp --- a/src/widgets/sdwidget.cpp +++ b/src/widgets/sdwidget.cpp @@ -27,22 +27,22 @@ { auto hBoxLayout = new QHBoxLayout; - auto newButton = new QPushButton(tr("Get List")); + auto newButton = new QPushButton(tr("Get List"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { emit requestSdList(); }); - newButton = new QPushButton(tr("Print Selected")); + newButton = new QPushButton(tr("Print Selected"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { if (listSdFiles->currentRow() != -1) { emit printSdFile(listSdFiles->currentItem()->text()); } }); - newButton = new QPushButton(tr("Delete Selected")); + newButton = new QPushButton(tr("Delete Selected"), this); hBoxLayout->addWidget(newButton); connect(newButton, &QPushButton::clicked, this, [this] { if (listSdFiles->currentRow() != -1) @@ -52,8 +52,8 @@ } }); - auto groupFiles = new QGroupBox(tr("Files On Sd Card")); - listSdFiles = new QListWidget; + auto groupFiles = new QGroupBox(tr("Files On Sd Card"), this); + listSdFiles = new QListWidget(this); auto groupLayout = new QVBoxLayout; groupLayout->addWidget(listSdFiles); groupFiles->setLayout(groupLayout); diff --git a/src/widgets/statuswidget.h b/src/widgets/statuswidget.h --- a/src/widgets/statuswidget.h +++ b/src/widgets/statuswidget.h @@ -36,6 +36,7 @@ * @param parent: parent of this widget. */ StatusWidget(bool showStop = true, QWidget *parent = nullptr); + ~StatusWidget() = default; /** * @brief Set if the status area should show SD card inserted. * @param hasSd diff --git a/src/widgets/statuswidget.cpp b/src/widgets/statuswidget.cpp --- a/src/widgets/statuswidget.cpp +++ b/src/widgets/statuswidget.cpp @@ -29,34 +29,34 @@ //first create the item for the print Progress. auto hBoxLayout = new QHBoxLayout; - printingProgress = new QProgressBar; + printingProgress = new QProgressBar(this); printingProgress->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); hBoxLayout->addWidget(printingProgress); if (showStop) { - auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString()); + auto newButton = new QPushButton(style()->standardIcon(QStyle::SP_BrowserStop), QString(), this); connect(newButton, &QPushButton::clicked, this, [this] { emit stopPressed(); }); hBoxLayout->addWidget(newButton); } - lblTime = new QLabel(QStringLiteral("00:00:00")); + lblTime = new QLabel(QStringLiteral("00:00:00"), this); lblTime->setAlignment(Qt::AlignHCenter); - auto newLabel = new QLabel(QStringLiteral(" / ")); - lblTimeLeft = new QLabel(QStringLiteral("??:??:??")); + auto newLabel = new QLabel(QStringLiteral(" / "), this); + lblTimeLeft = new QLabel(QStringLiteral("??:??:??"), this); lblTimeLeft->setAlignment(Qt::AlignHCenter); hBoxLayout->addWidget(lblTime); hBoxLayout->addWidget(newLabel); hBoxLayout->addWidget(lblTimeLeft); - printProgressWidget = new QWidget(); + printProgressWidget = new QWidget(this); printProgressWidget->setLayout(hBoxLayout); //Then Create the full bar. - newLabel = new QLabel(tr("AtCore State:")); - lblState = new QLabel(tr("Not Connected")); - lblSd = new QLabel(); + newLabel = new QLabel(tr("AtCore State:"), this); + lblState = new QLabel(tr("Not Connected"), this); + lblSd = new QLabel(this); spacer = new QSpacerItem(10, 20, QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); @@ -71,7 +71,7 @@ setLayout(hBoxLayout); printTime = new QTime(); - printTimer = new QTimer(); + printTimer = new QTimer(this); printTimer->setInterval(1000); printTimer->setSingleShot(false); connect(printTimer, &QTimer::timeout, this, &StatusWidget::updatePrintTime); diff --git a/src/widgets/temperaturewidget.h b/src/widgets/temperaturewidget.h --- a/src/widgets/temperaturewidget.h +++ b/src/widgets/temperaturewidget.h @@ -36,6 +36,7 @@ * @param parent */ TemperatureWidget(QWidget *parent = nullptr); + ~TemperatureWidget() = default; /** * @brief Update widget with count extruder controls diff --git a/src/widgets/temperaturewidget.cpp b/src/widgets/temperaturewidget.cpp --- a/src/widgets/temperaturewidget.cpp +++ b/src/widgets/temperaturewidget.cpp @@ -25,16 +25,16 @@ QWidget(parent) { auto *mainLayout = new QVBoxLayout; - checkAndWait = new QCheckBox(tr("Wait Until Temperature Stabilizes")); + checkAndWait = new QCheckBox(tr("Wait Until Temperature Stabilizes"), this); mainLayout->addWidget(checkAndWait); - auto label = new QLabel(tr("Bed Temp")); + auto label = new QLabel(tr("Bed Temp"), this); - sbBedTemp = new QSpinBox; + sbBedTemp = new QSpinBox(this); sbBedTemp->setRange(0, 120); sbBedTemp->setSuffix(QStringLiteral("°C")); - auto *newButton = new QPushButton(tr("Set")); + auto *newButton = new QPushButton(tr("Set"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit bedTempChanged(sbBedTemp->value(), checkAndWait->isChecked()); }); @@ -45,12 +45,12 @@ hboxLayout->addWidget(newButton); mainLayout->addItem(hboxLayout); - comboExtruderSelect = new QComboBox; - sbExtruderTemp = new QSpinBox; + comboExtruderSelect = new QComboBox(this); + sbExtruderTemp = new QSpinBox(this); sbExtruderTemp->setRange(0, 275); sbExtruderTemp->setSuffix(QStringLiteral("°C")); - newButton = new QPushButton(tr("Set")); + newButton = new QPushButton(tr("Set"), this); connect(newButton, &QPushButton::clicked, this, [this] { emit extTempChanged(sbExtruderTemp->value(), comboExtruderSelect->currentIndex(), checkAndWait->isChecked()); }); diff --git a/testclient/mainwindow.h b/testclient/mainwindow.h --- a/testclient/mainwindow.h +++ b/testclient/mainwindow.h @@ -43,7 +43,7 @@ public: explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow() override; + ~MainWindow() override = default; public slots: /** @@ -102,7 +102,7 @@ /** * @brief pluginCB index changed */ - void pluginCBChanged(QString currentText); + void pluginCBChanged(const QString ¤tText); /** * @brief setupActions for KXMLGui diff --git a/testclient/mainwindow.cpp b/testclient/mainwindow.cpp --- a/testclient/mainwindow.cpp +++ b/testclient/mainwindow.cpp @@ -365,44 +365,36 @@ event->accept(); } -MainWindow::~MainWindow() -{ - -} - void MainWindow::checkTemperature(uint sensorType, uint number, float temp) { QString msg; switch (sensorType) { case 0x00: // bed - msg = QString::fromLatin1("Bed Temperature "); + msg = QString::fromLatin1("Bed Temperature"); break; case 0x01: // bed target - msg = QString::fromLatin1("Bed Target Temperature "); + msg = QString::fromLatin1("Bed Target Temperature"); break; case 0x02: // extruder - msg = QString::fromLatin1("Extruder Temperature "); + msg = QString::fromLatin1("Extruder[%1] Temperature").arg(QString::number(number));; break; case 0x03: // extruder target - msg = QString::fromLatin1("Extruder Target Temperature "); + msg = QString::fromLatin1("Extruder[%1] Target Temperature").arg(QString::number(number)); break; case 0x04: // enclosure - msg = QString::fromLatin1("Enclosure Temperature "); + msg = QString::fromLatin1("Enclosure Temperature"); break; case 0x05: // enclosure target - msg = QString::fromLatin1("Enclosure Target Temperature "); + msg = QString::fromLatin1("Enclosure Target Temperature"); break; } - msg.append(QString::fromLatin1("[%1] : %2").arg( - QString::number(number), QString::number(double(temp), 'f', 2) - )); - + msg.append(QString::fromLatin1(": %1").arg(QString::number(double(temp), 'f', 2))); logWidget->appendLog(msg); } /** @@ -485,7 +477,7 @@ } } -void MainWindow::pluginCBChanged(QString currentText) +void MainWindow::pluginCBChanged(const QString ¤tText) { if (core->state() != AtCore::DISCONNECTED) { if (!currentText.contains(tr("Autodetect"))) { 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()