Skip to content

Commit cc81264

Browse files
g-abiliotatatupiGabrielnmds
authored
Adds node nickname functionality (#11)
* improves NodeValidationState struct * qt6 for linux-gcc * Adds node nickname functionality * Adjust label layout * improve caption and nickname dynamic * Add editable nickname label * add correct caption dynamic, as well as labelEdit max size * fix alignment issues between nickname and node caption * revert workflows change * fix segfault detected in dataflowgraphmodel tests * produces optional nickname structure and adds example * fix typo in spacing method and attribute * uniformizes icon files attributes * removes commented code * improves processing status icon resolution * solves situations where icons should not appear * adds docstring to each nodeprocessingstatus * adds possibility to change the node processing status icon style * moves all status logic to NodeStyle * removes unnecessary code * adds declaration of QPixmap --------- Co-authored-by: Taiguara Tupinambás <tatatupi@gmail.com> Co-authored-by: Gabrielnmds <gabrielnmds21@gmail.com>
1 parent dea439b commit cc81264

28 files changed

+638
-509
lines changed

examples/calculator/LongProcessingRandomNumber.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class RandomNumberModel : public MathOperationDataModel
1818
RandomNumberModel() {
1919
this->setNodeProcessingStatus(QtNodes::NodeProcessingStatus::Empty);
2020

21+
2122
QObject::connect(this, &NodeDelegateModel::computingStarted, this, [this]() {
2223
if (_number1.lock() && _number2.lock()) {
2324
this->setNodeProcessingStatus(

examples/calculator/NumberDisplayDataModel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
NumberDisplayDataModel::NumberDisplayDataModel()
66
: _label{nullptr}
7-
{
8-
this->setNodeProcessingStatus(QtNodes::NodeProcessingStatus::NoStatus);
9-
}
7+
{}
108

119
unsigned int NumberDisplayDataModel::nPorts(PortType portType) const
1210
{

examples/calculator/NumberSourceDataModel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
NumberSourceDataModel::NumberSourceDataModel()
1010
: _lineEdit{nullptr}
1111
, _number(std::make_shared<DecimalData>(0.0))
12-
{
13-
this->setNodeProcessingStatus(QtNodes::NodeProcessingStatus::NoStatus);
14-
}
12+
{}
1513

1614
QJsonObject NumberSourceDataModel::save() const
1715
{

examples/styles/models.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class MyDataModel : public NodeDelegateModel
3636

3737
QString name() const override { return QString("MyDataModel"); }
3838

39+
bool labelEditable() const override { return true; }
40+
3941
public:
4042
QJsonObject save() const override
4143
{

include/QtNodes/internal/AbstractNodeGeometry.hpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class NODE_EDITOR_PUBLIC AbstractNodeGeometry
3636
/// Port position in node's coordinate system.
3737
virtual QPointF portPosition(NodeId const nodeId,
3838
PortType const portType,
39-
PortIndex const index) const
40-
= 0;
39+
PortIndex const index) const = 0;
4140

4241
/// A convenience function using the `portPosition` and a given transformation.
4342
virtual QPointF portScenePosition(NodeId const nodeId,
@@ -48,8 +47,7 @@ class NODE_EDITOR_PUBLIC AbstractNodeGeometry
4847
/// Defines where to draw port label. The point corresponds to a font baseline.
4948
virtual QPointF portTextPosition(NodeId const nodeId,
5049
PortType const portType,
51-
PortIndex const portIndex) const
52-
= 0;
50+
PortIndex const portIndex) const = 0;
5351

5452
/**
5553
* Defines where to start drawing the caption. The point corresponds to a font
@@ -60,6 +58,15 @@ class NODE_EDITOR_PUBLIC AbstractNodeGeometry
6058
/// Caption rect is needed for estimating the total node size.
6159
virtual QRectF captionRect(NodeId const nodeId) const = 0;
6260

61+
/**
62+
* Defines where to start drawing the label. The point corresponds to a font
63+
* baseline.
64+
*/
65+
virtual QPointF labelPosition(NodeId const nodeId) const = 0;
66+
67+
/// Caption rect is needed for estimating the total node size.
68+
virtual QRectF labelRect(NodeId const nodeId) const = 0;
69+
6370
/// Position for an embedded widget. Return any value if you don't embed.
6471
virtual QPointF widgetPosition(NodeId const nodeId) const = 0;
6572

@@ -69,6 +76,8 @@ class NODE_EDITOR_PUBLIC AbstractNodeGeometry
6976

7077
virtual QRect resizeHandleRect(NodeId const nodeId) const = 0;
7178

79+
virtual int getPortSpacing() = 0;
80+
7281
protected:
7382
AbstractGraphModel &_graphModel;
7483
};

include/QtNodes/internal/DataFlowGraphModel.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <QJsonObject>
1212

1313
#include <memory>
14+
#include <unordered_map>
15+
#include <QString>
1416

1517
namespace QtNodes {
1618

@@ -137,6 +139,9 @@ private Q_SLOTS:
137139
std::unordered_set<ConnectionId> _connectivity;
138140

139141
mutable std::unordered_map<NodeId, NodeGeometryData> _nodeGeometryData;
142+
143+
std::unordered_map<NodeId, QString> _labels;
144+
std::unordered_map<NodeId, bool> _labelsVisible;
140145
};
141146

142147
} // namespace QtNodes

include/QtNodes/internal/DefaultHorizontalNodeGeometry.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,21 @@ class NODE_EDITOR_PUBLIC DefaultHorizontalNodeGeometry : public AbstractNodeGeom
2828
QPointF portTextPosition(NodeId const nodeId,
2929
PortType const portType,
3030
PortIndex const PortIndex) const override;
31+
3132
QPointF captionPosition(NodeId const nodeId) const override;
3233

3334
QRectF captionRect(NodeId const nodeId) const override;
3435

36+
QPointF labelPosition(const NodeId nodeId) const override;
37+
38+
QRectF labelRect(NodeId const nodeId) const override;
39+
3540
QPointF widgetPosition(NodeId const nodeId) const override;
3641

3742
QRect resizeHandleRect(NodeId const nodeId) const override;
3843

44+
int getPortSpacing() override { return _portSpacing; }
45+
3946
private:
4047
QRectF portTextRect(NodeId const nodeId,
4148
PortType const portType,
@@ -52,7 +59,7 @@ class NODE_EDITOR_PUBLIC DefaultHorizontalNodeGeometry : public AbstractNodeGeom
5259
// constness of the Node.
5360

5461
mutable unsigned int _portSize;
55-
unsigned int _portSpasing;
62+
unsigned int _portSpacing;
5663
mutable QFontMetrics _fontMetrics;
5764
mutable QFontMetrics _boldFontMetrics;
5865
};

include/QtNodes/internal/DefaultNodePainter.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class NODE_EDITOR_PUBLIC DefaultNodePainter : public AbstractNodePainter
2828

2929
void drawNodeCaption(QPainter *painter, NodeGraphicsObject &ngo) const;
3030

31+
void drawNodeLabel(QPainter *painter, NodeGraphicsObject &ngo) const;
32+
3133
void drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const;
3234

3335
void drawResizeRect(QPainter *painter, NodeGraphicsObject &ngo) const;

include/QtNodes/internal/DefaultVerticalNodeGeometry.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,16 @@ class NODE_EDITOR_PUBLIC DefaultVerticalNodeGeometry : public AbstractNodeGeomet
3333

3434
QRectF captionRect(NodeId const nodeId) const override;
3535

36+
QPointF labelPosition(const NodeId nodeId) const override;
37+
38+
QRectF labelRect(NodeId const nodeId) const override;
39+
3640
QPointF widgetPosition(NodeId const nodeId) const override;
3741

3842
QRect resizeHandleRect(NodeId const nodeId) const override;
3943

44+
int getPortSpacing() override { return _portSpacing; }
45+
4046
private:
4147
QRectF portTextRect(NodeId const nodeId,
4248
PortType const portType,
@@ -54,7 +60,7 @@ class NODE_EDITOR_PUBLIC DefaultVerticalNodeGeometry : public AbstractNodeGeomet
5460
// constness of the Node.
5561

5662
mutable unsigned int _portSize;
57-
unsigned int _portSpasing;
63+
unsigned int _portSpacing;
5864
mutable QFontMetrics _fontMetrics;
5965
mutable QFontMetrics _boldFontMetrics;
6066
};

include/QtNodes/internal/Definitions.hpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,27 @@ NODE_EDITOR_PUBLIC Q_NAMESPACE
1818
Q_NAMESPACE_EXPORT(NODE_EDITOR_PUBLIC)
1919
#endif
2020

21-
/**
21+
/**
2222
* Constants used for fetching QVariant data from GraphModel.
2323
*/
24-
enum class NodeRole {
25-
Type = 0, ///< Type of the current node, usually a string.
26-
Position = 1, ///< `QPointF` positon of the node on the scene.
27-
Size = 2, ///< `QSize` for resizable nodes.
28-
CaptionVisible = 3, ///< `bool` for caption visibility.
29-
Caption = 4, ///< `QString` for node caption.
30-
Style = 5, ///< Custom NodeStyle as QJsonDocument
31-
InternalData = 6, ///< Node-stecific user data as QJsonObject
32-
InPortCount = 7, ///< `unsigned int`
33-
OutPortCount = 9, ///< `unsigned int`
34-
Widget = 10, ///< Optional `QWidget*` or `nullptr`
35-
ValidationState = 11, ///< Enum NodeValidationState of the node
36-
ProcessingStatus = 12 ///< Enum NodeProcessingStatus of the node
37-
};
24+
enum class NodeRole {
25+
Type = 0, ///< Type of the current node, usually a string.
26+
Position = 1, ///< `QPointF` positon of the node on the scene.
27+
Size = 2, ///< `QSize` for resizable nodes.
28+
CaptionVisible = 3, ///< `bool` for caption visibility.
29+
Caption = 4, ///< `QString` for node caption.
30+
Style = 5, ///< Custom NodeStyle as QJsonDocument
31+
InternalData = 6, ///< Node-stecific user data as QJsonObject
32+
InPortCount = 7, ///< `unsigned int`
33+
OutPortCount = 9, ///< `unsigned int`
34+
Widget = 10, ///< Optional `QWidget*` or `nullptr`
35+
ValidationState = 11, ///< Enum NodeValidationState of the node
36+
LabelVisible = 12, ///< `bool` for label visibility.
37+
ProcessingStatus = 13, ///< Enum NodeProcessingStatus of the node
38+
Label = 14, ///< `QString` for node label.
39+
LabelEditable = 15, ///< `bool` to indicate label editing support.
40+
};
41+
3842
Q_ENUM_NS(NodeRole)
3943

4044
/**

0 commit comments

Comments
 (0)