Improved containment of target package widget functionality - it's now less tightly coupled.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include "DualInlinePackageWidget.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
@@ -6,7 +8,6 @@
|
||||
#include <QFile>
|
||||
|
||||
#include "../../../InsightWindow.hpp"
|
||||
#include "DualInlinePackageWidget.hpp"
|
||||
#include "src/Logger/Logger.hpp"
|
||||
#include "src/Exceptions/Exception.hpp"
|
||||
#include "src/Helpers/Paths.hpp"
|
||||
@@ -21,8 +22,9 @@ using Bloom::Targets::TargetVariant;
|
||||
DualInlinePackageWidget::DualInlinePackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
QObject* insightWindowObj,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWindowObj, parent) {
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
Paths::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss"
|
||||
|
||||
@@ -30,6 +30,11 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
void drawWidget(QPainter& painter);
|
||||
|
||||
public:
|
||||
DualInlinePackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent);
|
||||
DualInlinePackageWidget(
|
||||
const Targets::TargetVariant& targetVariant,
|
||||
QObject* insightWindowObj,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include "QuadFlatPackageWidget.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
@@ -6,7 +8,6 @@
|
||||
#include <QFile>
|
||||
|
||||
#include "../../../InsightWindow.hpp"
|
||||
#include "QuadFlatPackageWidget.hpp"
|
||||
#include "src/Helpers/Paths.hpp"
|
||||
#include "PinWidget.hpp"
|
||||
#include "BodyWidget.hpp"
|
||||
@@ -17,8 +18,9 @@ using namespace Bloom::Targets;
|
||||
QuadFlatPackageWidget::QuadFlatPackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
QObject* insightWindowObj,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWindowObj, parent) {
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0);
|
||||
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
void drawWidget(QPainter& painter);
|
||||
|
||||
public:
|
||||
QuadFlatPackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent);
|
||||
QuadFlatPackageWidget(
|
||||
const Targets::TargetVariant& targetVariant,
|
||||
QObject* insightWindowObj,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#include "TargetPackageWidget.hpp"
|
||||
|
||||
#include <QEvent>
|
||||
|
||||
#include "src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp"
|
||||
|
||||
using namespace Bloom;
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
|
||||
using Bloom::Targets::TargetState;
|
||||
|
||||
TargetPackageWidget::TargetPackageWidget(
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): QWidget(parent), targetVariant(std::move(targetVariant)), insightWorker(insightWorker) {
|
||||
this->connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetStateUpdated,
|
||||
this,
|
||||
&TargetPackageWidget::onTargetStateChanged
|
||||
);
|
||||
|
||||
this->connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetPinStatesUpdated,
|
||||
this,
|
||||
[this] (int variantId, const Targets::TargetPinStateMappingType& pinStatesByNumber) {
|
||||
if (variantId == this->targetVariant.id) {
|
||||
this->updatePinStates(pinStatesByNumber);
|
||||
|
||||
if (this->targetState == TargetState::STOPPED && !this->isEnabled()) {
|
||||
this->setDisabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
this->setDisabled(true);
|
||||
}
|
||||
|
||||
void TargetPackageWidget::refreshPinStates(std::optional<std::function<void(void)>> callback) {
|
||||
auto refreshTask = new RefreshTargetPinStates(this->targetVariant.id);
|
||||
this->connect(
|
||||
refreshTask,
|
||||
&RefreshTargetPinStates::targetPinStatesRetrieved,
|
||||
this,
|
||||
&TargetPackageWidget::updatePinStates
|
||||
);
|
||||
|
||||
if (callback.has_value()) {
|
||||
this->connect(
|
||||
refreshTask,
|
||||
&InsightWorkerTask::completed,
|
||||
this,
|
||||
callback.value()
|
||||
);
|
||||
}
|
||||
|
||||
this->insightWorker.queueTask(refreshTask);
|
||||
}
|
||||
|
||||
void TargetPackageWidget::updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber) {
|
||||
for (auto& pinWidget : this->pinWidgets) {
|
||||
auto pinNumber = pinWidget->getPinNumber();
|
||||
if (pinStatesByNumber.contains(pinNumber)) {
|
||||
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber));
|
||||
}
|
||||
}
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void TargetPackageWidget::onTargetStateChanged(TargetState newState) {
|
||||
this->targetState = newState;
|
||||
|
||||
if (newState == TargetState::RUNNING) {
|
||||
this->setDisabled(true);
|
||||
|
||||
} else if (newState == TargetState::STOPPED) {
|
||||
this->refreshPinStates([this] {
|
||||
if (this->targetState == TargetState::STOPPED) {
|
||||
this->setDisabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||
|
||||
#include "TargetPinWidget.hpp"
|
||||
#include "src/Targets/TargetVariant.hpp"
|
||||
#include "src/Targets/TargetDescriptor.hpp"
|
||||
@@ -19,19 +21,17 @@ namespace Bloom::Widgets::InsightTargetWidgets
|
||||
Q_OBJECT
|
||||
protected:
|
||||
Targets::TargetVariant targetVariant;
|
||||
InsightWorker& insightWorker;
|
||||
std::vector<TargetPinWidget*> pinWidgets;
|
||||
|
||||
public:
|
||||
TargetPackageWidget(Targets::TargetVariant targetVariant, QObject* insightWindowObj, QWidget* parent):
|
||||
QWidget(parent), targetVariant(std::move(targetVariant)) {};
|
||||
Targets::TargetState targetState = Targets::TargetState::UNKNOWN;
|
||||
|
||||
virtual void updatePinStates(std::map<int, Targets::TargetPinState> pinStatesByNumber) {
|
||||
for (auto& pinWidget : this->pinWidgets) {
|
||||
auto pinNumber = pinWidget->getPinNumber();
|
||||
if (pinStatesByNumber.contains(pinNumber)) {
|
||||
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber));
|
||||
}
|
||||
}
|
||||
}
|
||||
protected slots:
|
||||
virtual void updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber);
|
||||
void onTargetStateChanged(Targets::TargetState newState);
|
||||
|
||||
public:
|
||||
TargetPackageWidget(Targets::TargetVariant targetVariant, InsightWorker& insightWorker, QWidget* parent);
|
||||
virtual void refreshPinStates(std::optional<std::function<void(void)>> callback = std::nullopt);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user