From 139e880646a575145a4180b7221d85d328cae336 Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 21 Jun 2021 00:14:31 +0100 Subject: [PATCH] Tidying --- src/Insight/Insight.hpp | 4 ++-- src/Insight/InsightWorker.hpp | 2 +- .../UserInterfaces/InsightWindow/AboutWindow.hpp | 2 +- .../UserInterfaces/InsightWindow/InsightWindow.cpp | 7 ++++--- .../UserInterfaces/InsightWindow/InsightWindow.hpp | 4 ++-- .../InsightWindow/TargetWidgets/DIP/BodyWidget.cpp | 1 - .../InsightWindow/TargetWidgets/DIP/BodyWidget.hpp | 10 +++++----- .../TargetWidgets/DIP/DualInlinePackageWidget.hpp | 4 ++-- .../InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp | 6 +----- .../InsightWindow/TargetWidgets/DIP/PinBodyWidget.hpp | 7 ++++--- .../InsightWindow/TargetWidgets/DIP/PinWidget.hpp | 8 ++------ .../InsightWindow/TargetWidgets/QFP/BodyWidget.cpp | 2 -- .../InsightWindow/TargetWidgets/QFP/BodyWidget.hpp | 8 ++++---- .../InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp | 5 ++--- .../InsightWindow/TargetWidgets/QFP/PinBodyWidget.hpp | 7 ++++--- .../InsightWindow/TargetWidgets/QFP/PinWidget.hpp | 7 ++----- .../TargetWidgets/QFP/QuadFlatPackageWidget.hpp | 2 +- .../TargetWidgets/TargetPackageWidget.hpp | 5 +++-- .../InsightWindow/TargetWidgets/TargetPinWidget.hpp | 7 ++++--- src/Logger/Logger.hpp | 2 +- 20 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/Insight/Insight.hpp b/src/Insight/Insight.hpp index 522a155f..4989b203 100644 --- a/src/Insight/Insight.hpp +++ b/src/Insight/Insight.hpp @@ -47,12 +47,12 @@ namespace Bloom * Insight consists of two threads - the main thread where the main Qt event loop runs (for the GUI), and * a single worker thread to handle any blocking/time-expensive operations. */ - QThread* workerThread; + QThread* workerThread = nullptr; void startup(); public: - Insight(EventManager& eventManager): eventManager(eventManager) {}; + explicit Insight(EventManager& eventManager): eventManager(eventManager) {}; void setApplicationConfig(const ApplicationConfig& applicationConfig) { this->applicationConfig = applicationConfig; diff --git a/src/Insight/InsightWorker.hpp b/src/Insight/InsightWorker.hpp index 6f9b599d..687f9260 100644 --- a/src/Insight/InsightWorker.hpp +++ b/src/Insight/InsightWorker.hpp @@ -40,7 +40,7 @@ namespace Bloom void onTargetControllerStateReported(Events::EventPointer event); public: - InsightWorker(EventManager& eventManager): eventManager(eventManager) {}; + explicit InsightWorker(EventManager& eventManager): eventManager(eventManager) {}; void dispatchEvents() { this->eventListener->dispatchCurrentEvents(); diff --git a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.hpp index de62acaf..2bddf2d8 100644 --- a/src/Insight/UserInterfaces/InsightWindow/AboutWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/AboutWindow.hpp @@ -14,7 +14,7 @@ namespace Bloom QWidget* windowWidget = nullptr; public: - AboutWindow(QWidget* parent); + explicit AboutWindow(QWidget* parent); void show() { if (this->windowWidget != nullptr) { diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index c16d2932..fbdd5128 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "InsightWindow.hpp" #include "AboutWindow.hpp" @@ -25,7 +26,7 @@ void InsightWindow::init( QApplication& application, TargetDescriptor targetDescriptor ) { - this->targetDescriptor = targetDescriptor; + this->targetDescriptor = std::move(targetDescriptor); auto mainWindowUiFile = QFile( QString::fromStdString(Paths::compiledResourcesPath() @@ -50,7 +51,7 @@ void InsightWindow::init( this->mainWindowWidget = uiLoader.load(&mainWindowUiFile); this->mainWindowWidget->setStyleSheet(mainWindowStylesheet.readAll()); - application.setWindowIcon(QIcon( + QApplication::setWindowIcon(QIcon( QString::fromStdString(Paths::compiledResourcesPath() + "/src/Insight/UserInterfaces/InsightWindow/Images/BloomIcon.svg" ) @@ -166,7 +167,7 @@ void InsightWindow::activate() { QString::fromStdString(targetVariant.name + " (" + targetVariant.packageName + ")") ); - if (this->isVariantSupported(targetVariant)) { + if (InsightWindow::isVariantSupported(targetVariant)) { auto supportedVariantPtr = &(this->supportedVariantsByName.insert( std::pair(QString::fromStdString(targetVariant.name).toLower(), targetVariant) ).first->second); diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp index aca8e44d..ebe20b82 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.hpp @@ -48,7 +48,7 @@ namespace Bloom const Targets::TargetVariant* selectedVariant = nullptr; bool uiDisabled = false; - bool isVariantSupported(const Targets::TargetVariant& variant); + static bool isVariantSupported(const Targets::TargetVariant& variant); void selectVariant(const Targets::TargetVariant* variant); @@ -84,7 +84,7 @@ namespace Bloom void onTargetIoPortsUpdate(); void close(); void openReportIssuesUrl(); - void openGettingStartedUrl(); + static void openGettingStartedUrl(); void openAboutWindow(); void togglePinIoState(InsightTargetWidgets::TargetPinWidget* pinWidget); diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.cpp index a3b5af0a..56cb10f2 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.cpp @@ -32,7 +32,6 @@ void BodyWidget::drawWidget(QPainter& painter) { painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(targetBodyColor); auto parentContainerWidth = parentWidget->width(); -// this->setFixedSize(parentContainerWidth, parentContainerHeight); auto targetBodyHeight = 150; auto targetBodyWidth = parentContainerWidth; diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.hpp index bce80d7a..d4509d83 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/BodyWidget.hpp @@ -16,23 +16,23 @@ namespace Bloom::InsightTargetWidgets::Dip int disableAlphaLevel = 100; protected: - void paintEvent(QPaintEvent* event); + void paintEvent(QPaintEvent* event) override; void drawWidget(QPainter& painter); public: - BodyWidget(QWidget* parent): QWidget(parent) { + explicit BodyWidget(QWidget* parent): QWidget(parent) { this->setObjectName("target-body"); } - QColor getBodyColor() const { + [[nodiscard]] QColor getBodyColor() const { return this->bodyColor; } - void setBodyColor(QColor color) { + void setBodyColor(const QColor& color) { this->bodyColor = color; } - int getDisableAlphaLevel() const { + [[nodiscard]] int getDisableAlphaLevel() const { return this->disableAlphaLevel; } diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/DualInlinePackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/DualInlinePackageWidget.hpp index 7ceea44d..7203d9d3 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/DualInlinePackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/DualInlinePackageWidget.hpp @@ -25,8 +25,8 @@ namespace Bloom::InsightTargetWidgets::Dip BodyWidget* bodyWidget = nullptr; protected: - void paintEvent(QPaintEvent* event); - void resizeEvent(QResizeEvent* event); + void paintEvent(QPaintEvent* event) override; + void resizeEvent(QResizeEvent* event) override; void drawWidget(QPainter& painter); public: diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp index 09a969b9..8bd041bf 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.cpp @@ -1,25 +1,21 @@ #include #include -#include #include #include #include #include "PinBodyWidget.hpp" #include "src/Logger/Logger.hpp" -#include "src/Exceptions/Exception.hpp" using namespace Bloom::InsightTargetWidgets::Dip; using namespace Bloom::Targets; -using namespace Bloom::Exceptions; void PinBodyWidget::paintEvent(QPaintEvent* event) { auto painter = QPainter(this); this->drawWidget(painter); } -bool PinBodyWidget::event(QEvent* event) -{ +bool PinBodyWidget::event(QEvent* event) { if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { switch (event->type()) { case QEvent::Enter: { diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.hpp index 85d00740..e2c8ce5a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinBodyWidget.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "src/Targets/TargetPinDescriptor.hpp" @@ -38,8 +39,8 @@ namespace Bloom::InsightTargetWidgets::Dip PinBodyWidget( QWidget* parent, - const Targets::TargetPinDescriptor& pinDescriptor - ): QWidget(parent), pinDescriptor(pinDescriptor) { + Targets::TargetPinDescriptor pinDescriptor + ): QWidget(parent), pinDescriptor(std::move(pinDescriptor)) { this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT); this->setObjectName("target-pin-body"); } @@ -52,7 +53,7 @@ namespace Bloom::InsightTargetWidgets::Dip return this->bodyColor; } - void setBodyColor(QColor color) { + void setBodyColor(const QColor& color) { this->bodyColor = color; } diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinWidget.hpp index 5545b1b5..c3cce749 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/PinWidget.hpp @@ -19,12 +19,8 @@ namespace Bloom::InsightTargetWidgets::Dip QLabel* pinDirectionLabel = nullptr; PinBodyWidget* bodyWidget = nullptr; - void setLabelColor(QString hexColor) { + void setLabelColor(const QString& hexColor) { auto style = QString("QLabel { color: " + hexColor + "; }"); - if (this->pinNumberLabel != nullptr) { -// this->pinNumberLabel->setStyleSheet(style); - } - if (this->pinNameLabel != nullptr) { this->pinNameLabel->setStyleSheet(style); } @@ -43,7 +39,7 @@ namespace Bloom::InsightTargetWidgets::Dip const Targets::TargetVariant& targetVariant ); - virtual void updatePinState(const Targets::TargetPinState& pinState) override { + void updatePinState(const Targets::TargetPinState& pinState) override { TargetPinWidget::updatePinState(pinState); if (pinState.ioDirection.has_value()) { diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.cpp index d030c6bd..f90f8c1c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.cpp @@ -1,5 +1,4 @@ #include -#include #include "BodyWidget.hpp" #include "src/Logger/Logger.hpp" @@ -48,4 +47,3 @@ void BodyWidget::drawWidget(QPainter& painter) { 15 )); } - diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.hpp index db4570ee..6bb84109 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/BodyWidget.hpp @@ -16,15 +16,15 @@ namespace Bloom::InsightTargetWidgets::Qfp int disableAlphaLevel = 100; protected: - void paintEvent(QPaintEvent* event); + void paintEvent(QPaintEvent* event) override; void drawWidget(QPainter& painter); public: - BodyWidget(QWidget* parent): QWidget(parent) { + explicit BodyWidget(QWidget* parent): QWidget(parent) { this->setObjectName("target-body"); } - QColor getBodyColor() const { + [[nodiscard]] QColor getBodyColor() const { return this->bodyColor; } @@ -32,7 +32,7 @@ namespace Bloom::InsightTargetWidgets::Qfp this->bodyColor = color; } - int getDisableAlphaLevel() const { + [[nodiscard]] int getDisableAlphaLevel() const { return this->disableAlphaLevel; } diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp index 23f99871..53942eb4 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.cpp @@ -15,8 +15,7 @@ void PinBodyWidget::paintEvent(QPaintEvent* event) { this->drawWidget(painter); } -bool PinBodyWidget::event(QEvent* event) -{ +bool PinBodyWidget::event(QEvent* event) { if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { switch (event->type()) { case QEvent::Enter: { @@ -86,4 +85,4 @@ void PinBodyWidget::drawWidget(QPainter& painter) { pinWidth, pinHeight ); -} \ No newline at end of file +} diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.hpp index fd431317..a6feda8d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinBodyWidget.hpp @@ -2,6 +2,7 @@ #include #include +#include #include "src/Targets/TargetPinDescriptor.hpp" @@ -38,8 +39,8 @@ namespace Bloom::InsightTargetWidgets::Qfp static const int WIDTH = 30; static const int HEIGHT = 40; - PinBodyWidget(QWidget* parent, const Targets::TargetPinDescriptor& pinDescriptor, bool isVertical): - QWidget(parent), pinDescriptor(pinDescriptor), isVertical(isVertical) { + PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical): + QWidget(parent), pinDescriptor(std::move(pinDescriptor)), isVertical(isVertical) { this->setObjectName("target-pin-body"); if (isVertical) { @@ -58,7 +59,7 @@ namespace Bloom::InsightTargetWidgets::Qfp return this->bodyColor; } - void setBodyColor(QColor color) { + void setBodyColor(const QColor& color) { this->bodyColor = color; } diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinWidget.hpp index 5ae48ee1..8e7e7be9 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/PinWidget.hpp @@ -24,11 +24,8 @@ namespace Bloom::InsightTargetWidgets::Qfp bool isRightLayout = false; bool isTopLayout = false; - void setLabelColor(QString hexColor) { + void setLabelColor(const QString& hexColor) { auto style = QString("QLabel { color: " + hexColor + "; }"); - if (this->pinNumberLabel != nullptr) { -// this->pinNumberLabel->setStyleSheet(style); - } if (this->pinNameLabel != nullptr) { this->pinNameLabel->setStyleSheet(style); @@ -54,7 +51,7 @@ namespace Bloom::InsightTargetWidgets::Qfp const Targets::TargetVariant& targetVariant ); - virtual void updatePinState(const Targets::TargetPinState& pinState) override { + void updatePinState(const Targets::TargetPinState& pinState) override { TargetPinWidget::updatePinState(pinState); if (pinState.ioDirection.has_value()) { diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/QuadFlatPackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/QuadFlatPackageWidget.hpp index 79cce053..3b655e6a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/QuadFlatPackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/QFP/QuadFlatPackageWidget.hpp @@ -28,7 +28,7 @@ namespace Bloom::InsightTargetWidgets::Qfp BodyWidget* bodyWidget = nullptr; protected: - void paintEvent(QPaintEvent* event); + void paintEvent(QPaintEvent* event) override; void drawWidget(QPainter& painter); public: diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPackageWidget.hpp index 28eedfd2..106b2451 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPackageWidget.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -21,8 +22,8 @@ namespace Bloom::InsightTargetWidgets std::vector pinWidgets; public: - TargetPackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent): - QWidget(parent), targetVariant(targetVariant) {}; + TargetPackageWidget(Targets::TargetVariant targetVariant, QObject* insightWindowObj, QWidget* parent): + QWidget(parent), targetVariant(std::move(targetVariant)) {}; virtual void updatePinStates(std::map pinStatesByNumber) { for (auto& pinWidget : this->pinWidgets) { diff --git a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPinWidget.hpp index 5767ced9..23b573ee 100644 --- a/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/TargetPinWidget.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include "src/Targets/TargetVariant.hpp" #include "src/Targets/TargetPinDescriptor.hpp" @@ -19,9 +20,9 @@ namespace Bloom::InsightTargetWidgets public: TargetPinWidget( QWidget* parent, - const Targets::TargetPinDescriptor& pinDescriptor, - const Targets::TargetVariant& targetVariant - ): QWidget(parent), targetVariant(targetVariant), pinDescriptor(pinDescriptor) { + Targets::TargetPinDescriptor pinDescriptor, + Targets::TargetVariant targetVariant + ): QWidget(parent), targetVariant(std::move(targetVariant)), pinDescriptor(std::move(pinDescriptor)) { this->setDisabled(false); }; diff --git a/src/Logger/Logger.hpp b/src/Logger/Logger.hpp index 6929e74b..271be211 100644 --- a/src/Logger/Logger.hpp +++ b/src/Logger/Logger.hpp @@ -29,7 +29,7 @@ namespace Bloom LogEntry(std::string message, LogLevel logLevel): message(std::move(message)), logLevel(logLevel) { // Get thread name - std::array threadNameBuf; + std::array threadNameBuf = {}; if (pthread_getname_np(pthread_self(), threadNameBuf.data(), threadNameBuf.size()) == 0) { /*