Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions examples/calculator/LongProcessingRandomNumber.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <QtNodes/NodeDelegateModel>
#include <QtNodes/BasicGraphicsScene>
#include <QTimer>
#include <QtCore/QObject>
#include <QtWidgets/QLabel>
Expand All @@ -18,20 +17,17 @@ class RandomNumberModel : public MathOperationDataModel
public:
RandomNumberModel() {
QObject::connect(this, &NodeDelegateModel::computingStarted, this, [this]() {
//auto n1 = _number1.lock()->number();
//auto n2 = _number2.lock()->number();

//if (n1 > n2) {
// this->setNodeProcessingStatus(
// NodeDelegateModel::NodeProcessingStatus::Status::Failed);
//} else {
this->setNodeProcessingStatus(
this->setNodeProcessingStatus(
NodeDelegateModel::NodeProcessingStatus::Status::Processing);
//}

emit requestNodeUpdate();

});
QObject::connect(this, &NodeDelegateModel::computingFinished, this, [this]() {
this->setNodeProcessingStatus(
NodeDelegateModel::NodeProcessingStatus::Status::Updated);

emit requestNodeUpdate();
});
}
virtual ~RandomNumberModel() {}
Expand Down Expand Up @@ -60,8 +56,11 @@ class RandomNumberModel : public MathOperationDataModel
double a = n1->number();
double b = n2->number();

if (a > b)
std::swap(a, b);
if (a > b) {
this->setNodeProcessingStatus(NodeDelegateModel::NodeProcessingStatus::Status::Failed);
emit requestNodeUpdate();
return;
}

double upper = std::nextafter(b, std::numeric_limits<double>::max());
double randomValue = QRandomGenerator::global()->generateDouble() * (upper - a) + a;
Expand Down
15 changes: 0 additions & 15 deletions examples/calculator/MathOperationDataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,5 @@ void MathOperationDataModel::setInData(std::shared_ptr<NodeData> data, PortIndex
_number2 = numberData;
}

/*
Q_EMIT computingStarted();

QTimer *timer = new QTimer(this);
timer->start(1000);
int secondsRemaining = 10;
connect(timer, &QTimer::timeout, this, [=]() mutable {
if (--secondsRemaining <= 0) {
timer->stop();
compute();
Q_EMIT computingFinished();
}
});
*/

compute();
}
8 changes: 8 additions & 0 deletions include/QtNodes/internal/NodeDelegateModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ public Q_SLOTS:

void embeddedWidgetSizeUpdated();

/// Request an update of the node's UI.
/**
* Emit this signal whenever some internal state change requires
* the node to be repainted. The containing graph model will
* propagate the update to the scene.
*/
void requestNodeUpdate();

/// Call this function before deleting the data associated with ports.
/**
* The function notifies the Graph Model and makes it remove and recompute the
Expand Down
7 changes: 7 additions & 0 deletions src/DataFlowGraphModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ NodeId DataFlowGraphModel::addNode(QString const nodeType)
this,
&DataFlowGraphModel::portsInserted);

connect(model.get(), &NodeDelegateModel::requestNodeUpdate, this, [newId, this]() {
Q_EMIT nodeUpdated(newId);
});

_models[newId] = std::move(model);

Q_EMIT nodeCreated(newId);
Expand Down Expand Up @@ -528,6 +532,9 @@ void DataFlowGraphModel::loadNode(QJsonObject const &nodeJson)
&NodeDelegateModel::portsInserted,
this,
&DataFlowGraphModel::portsInserted);
connect(model.get(), &NodeDelegateModel::requestNodeUpdate, this, [restoredNodeId, this]() {
Q_EMIT nodeUpdated(restoredNodeId);
});

_models[restoredNodeId] = std::move(model);

Expand Down
Loading