From 5eea0c0b9c3eec7aa0925c1d0385e4b0aa53d4a0 Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 25 Sep 2021 20:14:57 +0100 Subject: [PATCH] Bloom Inisght error dialogue --- .../Widgets/ErrorDialogue/ErrorDialogue.cpp | 58 ++++++++++++ .../Widgets/ErrorDialogue/ErrorDialogue.hpp | 19 ++++ .../Widgets/ErrorDialogue/Images/icon.svg | 89 +++++++++++++++++++ .../Stylesheets/ErrorDialogue.qss | 15 ++++ .../ErrorDialogue/UiFiles/ErrorDialogue.ui | 69 ++++++++++++++ .../TargetRegisterInspectorWindow.cpp | 16 +++- src/resources.qrc | 3 + 7 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss create mode 100644 src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp new file mode 100644 index 00000000..e9d360f4 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.cpp @@ -0,0 +1,58 @@ +#include "ErrorDialogue.hpp" + +#include +#include + +#include "src/Helpers/Paths.hpp" +#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp" +#include "src/Exceptions/Exception.hpp" + +using namespace Bloom::Widgets; + +using Bloom::Exceptions::Exception; + +ErrorDialogue::ErrorDialogue( + const QString& windowTitle, + const QString& errorMessage, + QWidget* parent +): QDialog(parent) { + this->setObjectName("error-dialogue"); + this->setAttribute(Qt::WA_DeleteOnClose, true); + this->setWindowTitle(windowTitle); + this->setFixedSize(500, 180); + + auto dialogueUiFile = QFile( + QString::fromStdString(Paths::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui" + ) + ); + + auto dialogueStylesheet = QFile( + QString::fromStdString(Paths::compiledResourcesPath() + + "/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss" + ) + ); + + if (!dialogueUiFile.open(QFile::ReadOnly)) { + throw Exception("Failed to open ErrorDialogue UI file"); + } + + if (!dialogueStylesheet.open(QFile::ReadOnly)) { + throw Exception("Failed to open ErrorDialogue stylesheet file"); + } + + this->setStyleSheet(dialogueStylesheet.readAll()); + + auto uiLoader = UiLoader(this); + this->container = uiLoader.load(&dialogueUiFile, this); + + this->container->setFixedSize(this->size()); + this->container->setContentsMargins(15, 15, 15, 15); + + this->errorMessageLabel = this->container->findChild("error-message-label"); + this->okButton = this->container->findChild("ok-btn"); + + this->errorMessageLabel->setText(errorMessage); + + this->connect(this->okButton, &QPushButton::clicked, this, &QDialog::close); +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp new file mode 100644 index 00000000..1cf018e2 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include + +namespace Bloom::Widgets +{ + class Q_WIDGETS_EXPORT ErrorDialogue: public QDialog + { + Q_OBJECT + QWidget* container = nullptr; + QLabel* errorMessageLabel = nullptr; + QPushButton* okButton = nullptr; + + public: + ErrorDialogue(const QString& windowTitle, const QString& errorMessage, QWidget* parent); + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg new file mode 100644 index 00000000..e730a6bb --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg @@ -0,0 +1,89 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss new file mode 100644 index 00000000..031a7037 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss @@ -0,0 +1,15 @@ +* { + color: #afb1b3; + font-family: 'Ubuntu', sans-serif; + font-size: 14px; +} + +#error-dialogue { + background-color: #373835; +} + +QPushButton { + background-color: #373937; + border: 1px solid #484A49; + padding: 3px 25px; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui new file mode 100644 index 00000000..735297bf --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui @@ -0,0 +1,69 @@ + + + + + + + + :/compiled/src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg + + + 64 + + + 74 + + + + + + + + 20 + + + + + + + + true + + + Qt::AlignHCenter + + + 65 + + + 480 + + + + + + + Qt::Vertical + + + + + + + 15 + + + + + 90 + + + OK + + + + + + + + diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp index 820006af..105621fb 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/TargetRegisterInspectorWindow.cpp @@ -7,7 +7,8 @@ #include #include -#include "../../UiLoader.hpp" +#include "src/Insight/UserInterfaces/InsightWindow/UiLoader.hpp" +#include "src/Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/ErrorDialogue.hpp" #include "src/Helpers/Paths.hpp" #include "src/Helpers/DateTime.hpp" @@ -17,8 +18,8 @@ #include "src/Insight/InsightWorker/Tasks/WriteTargetRegister.hpp" using namespace Bloom::Widgets; -using namespace Bloom::Exceptions; +using Bloom::Exceptions::Exception; using Bloom::Targets::TargetRegisterDescriptor; using Bloom::Targets::TargetRegisterDescriptors; using Bloom::Targets::TargetRegisterType; @@ -350,9 +351,16 @@ void TargetRegisterInspectorWindow::applyChanges() { this->registerHistoryWidget->selectCurrentItem(); }); - this->connect(writeRegisterTask, &InsightWorkerTask::failed, this, [this] { - // TODO: Let the user know the write failed. + this->connect(writeRegisterTask, &InsightWorkerTask::failed, this, [this] (QString errorMessage) { this->registerValueContainer->setDisabled(false); + auto errorDialogue = new ErrorDialogue( + "Error", + "Failed to update " + QString::fromStdString( + this->registerDescriptor.name.value_or("") + ).toUpper() + " register value - " + errorMessage, + this + ); + errorDialogue->show(); }); this->insightWorker.queueTask(writeRegisterTask); diff --git a/src/resources.qrc b/src/resources.qrc index 72c2130c..c6f0bffb 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -22,6 +22,7 @@ ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/UiFiles/TargetRegistersSidePane.ui ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/UiFiles/TargetRegisterInspectorWindow.ui ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/RegisterHistoryWidget/UiFiles/RegisterHistoryWidget.ui + ./Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/UiFiles/ErrorDialogue.ui ./Insight/UserInterfaces/InsightWindow/Stylesheets/InsightWindow.qss @@ -29,6 +30,7 @@ ./Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss ./Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/Stylesheets/TargetRegisterInspectorWindow.qss + ./Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Stylesheets/ErrorDialogue.qss ./Insight/UserInterfaces/InsightWindow/Images/BloomIcon.svg @@ -44,5 +46,6 @@ ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/target-registers-disabled.svg ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegistersPane/Images/search-registers.svg ./Insight/UserInterfaces/InsightWindow/Widgets/TargetRegisterInspector/Images/icon.svg + ./Insight/UserInterfaces/InsightWindow/Widgets/ErrorDialogue/Images/icon.svg