Removed tight coupling of target pin widgets with Insight window - moved target pin state toggling into an InsightWorker task.
This commit is contained in:
@@ -48,7 +48,7 @@ DualInlinePackageWidget::DualInlinePackageWidget(
|
||||
assert(insightWindow != nullptr);
|
||||
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto pinWidget = new PinWidget(this, targetPinDescriptor, targetVariant);
|
||||
auto pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
|
||||
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
|
||||
@@ -56,8 +56,6 @@ DualInlinePackageWidget::DualInlinePackageWidget(
|
||||
} else {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignRight);
|
||||
}
|
||||
|
||||
connect(pinWidget, &TargetPinWidget::toggleIoState, insightWindow, &InsightWindow::togglePinIoState);
|
||||
}
|
||||
|
||||
this->layout->addLayout(this->topPinLayout);
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinWidget::PinWidget(QWidget* parent, const TargetPinDescriptor& pinDescriptor, const TargetVariant& targetVariant):
|
||||
TargetPinWidget(parent, pinDescriptor, targetVariant) {
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
|
||||
@@ -34,9 +34,10 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
+ (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT);
|
||||
|
||||
PinWidget(
|
||||
QWidget* parent,
|
||||
const Targets::TargetPinDescriptor& pinDescriptor,
|
||||
const Targets::TargetVariant& targetVariant
|
||||
const Targets::TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
);
|
||||
|
||||
void updatePinState(const Targets::TargetPinState& pinState) override {
|
||||
|
||||
@@ -11,8 +11,12 @@
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinWidget::PinWidget(QWidget* parent, const TargetPinDescriptor& pinDescriptor, const TargetVariant& targetVariant):
|
||||
TargetPinWidget(parent, pinDescriptor, targetVariant) {
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
|
||||
@@ -42,9 +42,10 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
static const int MAXIMUM_VERTICAL_WIDTH = PinBodyWidget::WIDTH;
|
||||
|
||||
PinWidget(
|
||||
QWidget* parent,
|
||||
const Targets::TargetPinDescriptor& pinDescriptor,
|
||||
const Targets::TargetVariant& targetVariant
|
||||
const Targets::TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
);
|
||||
|
||||
void updatePinState(const Targets::TargetPinState& pinState) override;
|
||||
|
||||
@@ -61,7 +61,7 @@ QuadFlatPackageWidget::QuadFlatPackageWidget(
|
||||
|
||||
auto pinCountPerLayout = (targetVariant.pinDescriptorsByNumber.size() / 4);
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto pinWidget = new PinWidget(this, targetPinDescriptor, targetVariant);
|
||||
auto pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
|
||||
if (targetPinNumber <= pinCountPerLayout) {
|
||||
@@ -76,8 +76,6 @@ QuadFlatPackageWidget::QuadFlatPackageWidget(
|
||||
} else if (targetPinNumber > (pinCountPerLayout * 3) && targetPinNumber <= (pinCountPerLayout * 4)) {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignBottom);
|
||||
}
|
||||
|
||||
connect(pinWidget, &TargetPinWidget::toggleIoState, insightWindow, &InsightWindow::togglePinIoState);
|
||||
}
|
||||
|
||||
this->bodyWidget = new BodyWidget(this);
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "TargetPinWidget.hpp"
|
||||
|
||||
#include "src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp"
|
||||
|
||||
using namespace Bloom;
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
|
||||
using Bloom::Targets::TargetVariant;
|
||||
using Bloom::Targets::TargetPinDescriptor;
|
||||
using Bloom::Targets::TargetPinType;
|
||||
using Bloom::Targets::TargetPinState;
|
||||
|
||||
TargetPinWidget::TargetPinWidget(
|
||||
Targets::TargetPinDescriptor pinDescriptor,
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): QWidget(parent),
|
||||
insightWorker(insightWorker),
|
||||
targetVariant(std::move(targetVariant)),
|
||||
pinDescriptor(std::move(pinDescriptor)) {
|
||||
if (this->pinDescriptor.type == TargetPinType::UNKNOWN) {
|
||||
this->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TargetPinWidget::onWidgetBodyClicked() {
|
||||
// Currently, we only allow users to toggle the IO state of output pins
|
||||
if (this->pinState.has_value()
|
||||
&& this->pinState.value().ioDirection == TargetPinState::IoDirection::OUTPUT
|
||||
) {
|
||||
this->setDisabled(true);
|
||||
|
||||
auto pinState = this->pinState.value();
|
||||
pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) ?
|
||||
TargetPinState::IoState::LOW : TargetPinState::IoState::HIGH;
|
||||
|
||||
auto setPinStateTask = new SetTargetPinState(this->pinDescriptor, pinState);
|
||||
this->connect(setPinStateTask, &InsightWorkerTask::completed, this, [this, pinState] {
|
||||
this->updatePinState(pinState);
|
||||
this->setDisabled(false);
|
||||
});
|
||||
|
||||
this->connect(setPinStateTask, &InsightWorkerTask::failed, this, [this] {
|
||||
this->setDisabled(false);
|
||||
});
|
||||
|
||||
this->insightWorker.queueTask(setPinStateTask);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QWidget>
|
||||
#include <utility>
|
||||
|
||||
#include "src/Insight/InsightWorker/InsightWorker.hpp"
|
||||
#include "src/Targets/TargetVariant.hpp"
|
||||
#include "src/Targets/TargetPinDescriptor.hpp"
|
||||
|
||||
@@ -12,6 +13,8 @@ namespace Bloom::Widgets::InsightTargetWidgets
|
||||
{
|
||||
Q_OBJECT
|
||||
protected:
|
||||
InsightWorker& insightWorker;
|
||||
|
||||
Targets::TargetVariant targetVariant;
|
||||
Targets::TargetPinDescriptor pinDescriptor;
|
||||
std::optional<Targets::TargetPinState> pinState;
|
||||
@@ -19,25 +22,16 @@ namespace Bloom::Widgets::InsightTargetWidgets
|
||||
|
||||
public:
|
||||
TargetPinWidget(
|
||||
QWidget* parent,
|
||||
Targets::TargetPinDescriptor pinDescriptor,
|
||||
Targets::TargetVariant targetVariant
|
||||
): QWidget(parent), targetVariant(std::move(targetVariant)), pinDescriptor(std::move(pinDescriptor)) {
|
||||
this->setDisabled(false);
|
||||
};
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
);
|
||||
|
||||
int getPinNumber() const {
|
||||
return this->pinDescriptor.number;
|
||||
}
|
||||
|
||||
const Targets::TargetPinDescriptor& getPinDescriptor() const {
|
||||
return this->pinDescriptor;
|
||||
}
|
||||
|
||||
std::optional<Targets::TargetPinState> getPinState() const {
|
||||
return this->pinState;
|
||||
}
|
||||
|
||||
virtual void updatePinState(const Targets::TargetPinState& pinState) {
|
||||
this->pinStateChanged = !this->pinState.has_value()
|
||||
|| this->pinState->ioState != pinState.ioState
|
||||
@@ -46,21 +40,7 @@ namespace Bloom::Widgets::InsightTargetWidgets
|
||||
this->pinState = pinState;
|
||||
}
|
||||
|
||||
void setDisabled(bool disabled) {
|
||||
if (pinDescriptor.type != Targets::TargetPinType::UNKNOWN) {
|
||||
QWidget::setDisabled(disabled);
|
||||
|
||||
} else {
|
||||
QWidget::setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public slots:
|
||||
void onWidgetBodyClicked() {
|
||||
emit this->toggleIoState(this);
|
||||
}
|
||||
|
||||
signals:
|
||||
void toggleIoState(TargetPinWidget* pinWidget);
|
||||
virtual void onWidgetBodyClicked();
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user