Skip to content

Commit 318f0b2

Browse files
committed
solve conflicts
2 parents 845d342 + 0813551 commit 318f0b2

32 files changed

Lines changed: 711 additions & 131 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ CMakeLists.txt.user
44
build*/
55
.vscode/
66

7+
qt-build
8+
79
tags

examples/calculator/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set(CALC_HEADER_FILES
1717

1818
add_executable(calculator
1919
${CALC_SOURCE_FILES}
20-
${CALC_HEAEDR_FILES}
20+
${CALC_HEADER_FILES}
2121
)
2222

2323
target_link_libraries(calculator QtNodes)
@@ -33,7 +33,7 @@ set(HEADLESS_CALC_SOURCE_FILES
3333

3434
add_executable(headless_calculator
3535
${HEADLESS_CALC_SOURCE_FILES}
36-
${CALC_HEAEDR_FILES}
36+
${CALC_HEADER_FILES}
3737
)
3838

3939
target_link_libraries(headless_calculator QtNodes)

examples/calculator/DivisionModel.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,27 @@ class DivisionModel : public MathOperationDataModel
5555
auto n1 = _number1.lock();
5656
auto n2 = _number2.lock();
5757

58+
QtNodes::NodeValidationState state;
5859
if (n2 && (n2->number() == 0.0)) {
59-
//modelValidationState = NodeValidationState::Error;
60-
//modelValidationError = QStringLiteral("Division by zero error");
60+
state._state = QtNodes::NodeValidationState::State::Error;
61+
state._stateMessage = QStringLiteral("Division by zero error");
62+
setValidationState(state);
6163
_result.reset();
64+
} else if ( n2 && (n2->number() < 1e-5)) {
65+
state._state = QtNodes::NodeValidationState::State::Warning;
66+
state._stateMessage = QStringLiteral("Very small divident. Result might overflow");
67+
setValidationState(state);
68+
if (n1) {
69+
_result = std::make_shared<DecimalData>(n1->number() / n2->number());
70+
} else {
71+
_result.reset();
72+
}
6273
} else if (n1 && n2) {
63-
//modelValidationState = NodeValidationState::Valid;
64-
//modelValidationError = QString();
74+
setValidationState(state);
6575
_result = std::make_shared<DecimalData>(n1->number() / n2->number());
6676
} else {
67-
//modelValidationState = NodeValidationState::Warning;
68-
//modelValidationError = QStringLiteral("Missing or incorrect inputs");
77+
QtNodes::NodeValidationState state;
78+
setValidationState(state);
6979
_result.reset();
7080
}
7181

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#pragma once
2+
3+
#include <QtNodes/NodeDelegateModel>
4+
#include <QTimer>
5+
#include <QtCore/QObject>
6+
#include <QtWidgets/QLabel>
7+
#include <QtCore/QRandomGenerator64>
8+
9+
#include "MathOperationDataModel.hpp"
10+
#include "DecimalData.hpp"
11+
12+
/// The model generates a random value in a long processing schema,
13+
/// as it should demonstrate the usage of the NodeProcessingStatus.
14+
/// The random number is generate in the [n1, n2] interval.
15+
class RandomNumberModel : public MathOperationDataModel
16+
{
17+
public:
18+
RandomNumberModel() {
19+
setFrozenMenu(true);
20+
21+
this->setNodeProcessingStatus(QtNodes::NodeProcessingStatus::Empty);
22+
23+
24+
QObject::connect(this, &NodeDelegateModel::computingStarted, this, [this]() {
25+
if (_number1.lock() && _number2.lock()) {
26+
this->setNodeProcessingStatus(
27+
QtNodes::NodeProcessingStatus::Processing);
28+
}
29+
30+
emit requestNodeUpdate();
31+
});
32+
QObject::connect(this, &NodeDelegateModel::computingFinished, this, [this]() {
33+
this->setNodeProcessingStatus(
34+
QtNodes::NodeProcessingStatus::Updated);
35+
36+
emit requestNodeUpdate();
37+
});
38+
}
39+
virtual ~RandomNumberModel() {}
40+
41+
public:
42+
QString caption() const override { return QStringLiteral("Random Number"); }
43+
44+
QString name() const override { return QStringLiteral("Random Number"); }
45+
46+
private:
47+
void compute() override
48+
{
49+
if (frozen())
50+
return;
51+
52+
Q_EMIT computingStarted();
53+
PortIndex const outPortIndex = 0;
54+
55+
auto n1 = _number1.lock();
56+
auto n2 = _number2.lock();
57+
58+
QTimer *timer = new QTimer(this);
59+
timer->start(1000);
60+
int secondsRemaining = 3;
61+
connect(timer, &QTimer::timeout, this, [=]() mutable {
62+
if (--secondsRemaining <= 0) {
63+
timer->stop();
64+
if (n1 && n2) {
65+
double a = n1->number();
66+
double b = n2->number();
67+
68+
if (a > b) {
69+
setNodeProcessingStatus(QtNodes::NodeProcessingStatus::Failed);
70+
71+
emit requestNodeUpdate();
72+
return;
73+
}
74+
75+
double upper = std::nextafter(b, std::numeric_limits<double>::max());
76+
double randomValue = QRandomGenerator::global()->generateDouble() * (upper - a) + a;
77+
78+
_result = std::make_shared<DecimalData>(randomValue);
79+
Q_EMIT computingFinished();
80+
} else {
81+
_result.reset();
82+
}
83+
84+
Q_EMIT dataUpdated(outPortIndex);
85+
}
86+
});
87+
}
88+
};

examples/calculator/RandomNumber.hpp

Lines changed: 0 additions & 55 deletions
This file was deleted.

examples/calculator/headless_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "AdditionModel.hpp"
22
#include "DivisionModel.hpp"
3+
#include "LongProcessingRandomNumber.hpp"
34
#include "MultiplicationModel.hpp"
45
#include "NumberDisplayDataModel.hpp"
56
#include "NumberSourceDataModel.hpp"
6-
#include "RandomNumber.hpp"
77
#include "SubtractionModel.hpp"
88

99
#include <QtNodes/DataFlowGraphModel>

examples/calculator/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515
#include "AdditionModel.hpp"
1616
#include "DivisionModel.hpp"
17+
#include "LongProcessingRandomNumber.hpp"
1718
#include "MultiplicationModel.hpp"
1819
#include "NumberDisplayDataModel.hpp"
1920
#include "NumberSourceDataModel.hpp"
20-
#include "RandomNumber.hpp"
2121
#include "SubtractionModel.hpp"
2222

2323
using QtNodes::ConnectionStyle;

include/QtNodes/UndoCommands

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "internal/UndoCommands.hpp"

include/QtNodes/internal/BasicGraphicsScene.hpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class NODE_EDITOR_PUBLIC BasicGraphicsScene : public QGraphicsScene
5757

5858
void setConnectionPainter(std::unique_ptr<AbstractConnectionPainter> newPainter);
5959

60+
void setNodeGeometry(std::unique_ptr<AbstractNodeGeometry> newGeom);
61+
6062
QUndoStack &undoStack();
6163

6264
public:
@@ -141,17 +143,17 @@ class NODE_EDITOR_PUBLIC BasicGraphicsScene : public QGraphicsScene
141143

142144
public Q_SLOTS:
143145
/// Slot called when the `connectionId` is erased form the AbstractGraphModel.
144-
void onConnectionDeleted(ConnectionId const connectionId);
146+
virtual void onConnectionDeleted(ConnectionId const connectionId);
145147

146148
/// Slot called when the `connectionId` is created in the AbstractGraphModel.
147-
void onConnectionCreated(ConnectionId const connectionId);
148-
149-
void onNodeDeleted(NodeId const nodeId);
150-
void onNodeCreated(NodeId const nodeId);
151-
void onNodePositionUpdated(NodeId const nodeId);
152-
void onNodeUpdated(NodeId const nodeId);
153-
void onNodeClicked(NodeId const nodeId);
154-
void onModelReset();
149+
virtual void onConnectionCreated(ConnectionId const connectionId);
150+
151+
virtual void onNodeDeleted(NodeId const nodeId);
152+
virtual void onNodeCreated(NodeId const nodeId);
153+
virtual void onNodePositionUpdated(NodeId const nodeId);
154+
virtual void onNodeUpdated(NodeId const nodeId);
155+
virtual void onNodeClicked(NodeId const nodeId);
156+
virtual void onModelReset();
155157

156158
private:
157159
AbstractGraphModel &_graphModel;

include/QtNodes/internal/DefaultNodePainter.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <QIcon>
34
#include <QtGui/QPainter>
45

56
#include "AbstractNodePainter.hpp"
@@ -30,5 +31,12 @@ class NODE_EDITOR_PUBLIC DefaultNodePainter : public AbstractNodePainter
3031
void drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const;
3132

3233
void drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const;
34+
35+
void drawProcessingIndicator(QPainter *painter, NodeGraphicsObject &ngo) const;
36+
37+
void drawValidationIcon(QPainter *painter, NodeGraphicsObject &ngo) const;
38+
39+
private:
40+
QIcon _toolTipIcon{"://info-tooltip.svg"};
3341
};
3442
} // namespace QtNodes

0 commit comments

Comments
 (0)