Skip to content

Commit 163ed49

Browse files
g-abiliotatatupiGabrielnmds
authored
Adds node nickname functionality (#506)
* 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 * solves conflict * 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 * solve conflicts * pull new node_processing_status and solve conflicts * solve minor errors * remove unnecessary changes * remove unnecessary changes * Revert "remove unnecessary changes" This reverts commit 9a7740a. * remove unnecessary changes * increase safety in reading and serialization * solve build error --------- Co-authored-by: Taiguara Tupinambás <tatatupi@gmail.com> Co-authored-by: Gabrielnmds <gabrielnmds21@gmail.com>
1 parent 35b11b6 commit 163ed49

17 files changed

+393
-74
lines changed

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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#pragma once
22

3-
#include <QIcon>
4-
#include <QtGui/QPainter>
5-
63
#include "AbstractNodePainter.hpp"
74
#include "Definitions.hpp"
5+
#include <QIcon>
6+
#include <QtGui/QPainter>
87

98
namespace QtNodes {
109

@@ -28,6 +27,8 @@ class NODE_EDITOR_PUBLIC DefaultNodePainter : public AbstractNodePainter
2827

2928
void drawNodeCaption(QPainter *painter, NodeGraphicsObject &ngo) const;
3029

30+
void drawNodeLabel(QPainter *painter, NodeGraphicsObject &ngo) const;
31+
3132
void drawEntryLabels(QPainter *painter, NodeGraphicsObject &ngo) const;
3233

3334
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: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,24 @@ Q_NAMESPACE_EXPORT(NODE_EDITOR_PUBLIC)
1919
#endif
2020

2121
/**
22-
* Constants used for fetching QVariant data from GraphModel.
23-
*/
22+
* Constants used for fetching QVariant data from GraphModel.
23+
*/
2424
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
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.
3740
};
3841
Q_ENUM_NS(NodeRole)
3942

include/QtNodes/internal/GraphicsView.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
#include <QtWidgets/QGraphicsView>
44

5+
#include "Definitions.hpp"
56
#include "Export.hpp"
67

8+
class QLineEdit;
9+
710
namespace QtNodes {
811

912
class BasicGraphicsScene;
@@ -98,5 +101,8 @@ public Q_SLOTS:
98101

99102
QPointF _clickPos;
100103
ScaleRange _scaleRange;
104+
105+
QLineEdit *_labelEdit = nullptr;
106+
NodeId _editingNodeId = InvalidNodeId;
101107
};
102108
} // namespace QtNodes

include/QtNodes/internal/NodeDelegateModel.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
#pragma once
22

3-
#include <memory>
4-
5-
#include <QMetaType>
6-
#include <QPixmap>
7-
#include <QtGui/QColor>
8-
#include <QtWidgets/QWidget>
9-
103
#include "Definitions.hpp"
114
#include "Export.hpp"
125
#include "NodeData.hpp"
136
#include "NodeStyle.hpp"
147
#include "Serializable.hpp"
158
#include <QtGui/QColor>
9+
#include <QtWidgets/QWidget>
1610

1711
namespace QtNodes {
1812

@@ -81,6 +75,15 @@ class NODE_EDITOR_PUBLIC NodeDelegateModel
8175
/// It is possible to hide port caption in GUI
8276
virtual bool portCaptionVisible(PortType, PortIndex) const { return false; }
8377

78+
/// Nicknames can be assigned to nodes and shown in GUI
79+
virtual QString label() const { return QString(); }
80+
81+
/// It is possible to hide the nickname in GUI
82+
virtual bool labelVisible() const { return true; }
83+
84+
/// Controls whether the label can be edited or not
85+
virtual bool labelEditable() const { return false; }
86+
8487
/// Validation State will default to Valid, but you can manipulate it by overriding in an inherited class
8588
virtual NodeValidationState validationState() const { return _nodeValidationState; }
8689

include/QtNodes/internal/UndoCommands.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#include "Definitions.hpp"
44
#include "Export.hpp"
55

6+
#include <QUndoCommand>
67
#include <QtCore/QJsonObject>
78
#include <QtCore/QPointF>
8-
#include <QUndoCommand>
99

1010
#include <unordered_set>
1111

0 commit comments

Comments
 (0)