Skip to content

Commit e828567

Browse files
committed
solve conflicts
2 parents 8d6c26b + cc81264 commit e828567

15 files changed

Lines changed: 399 additions & 105 deletions

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

@@ -139,6 +141,9 @@ private Q_SLOTS:
139141
std::unordered_set<ConnectionId> _connectivity;
140142

141143
mutable std::unordered_map<NodeId, NodeGeometryData> _nodeGeometryData;
144+
145+
std::unordered_map<NodeId, QString> _labels;
146+
std::unordered_map<NodeId, bool> _labelsVisible;
142147
};
143148

144149
} // 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
/**

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;
@@ -97,5 +100,8 @@ public Q_SLOTS:
97100

98101
QPointF _clickPos;
99102
ScaleRange _scaleRange;
103+
104+
QLineEdit *_labelEdit = nullptr;
105+
NodeId _editingNodeId = InvalidNodeId;
100106
};
101107
} // namespace QtNodes

include/QtNodes/internal/NodeDelegateModel.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
#include <QMetaType>
66
#include <QPixmap>
7-
#include <QtGui/QColor>
87
#include <QtWidgets/QWidget>
98

109
#include "Definitions.hpp"
1110
#include "Export.hpp"
1211
#include "NodeData.hpp"
1312
#include "NodeStyle.hpp"
1413
#include "Serializable.hpp"
14+
#include <QtGui/QColor>
1515

1616
namespace QtNodes {
1717

@@ -83,6 +83,15 @@ class NODE_EDITOR_PUBLIC NodeDelegateModel
8383
/// Validation State will default to Valid, but you can manipulate it by overriding in an inherited class
8484
virtual NodeValidationState validationState() const { return _nodeValidationState; }
8585

86+
/// Nicknames can be assigned to nodes and shown in GUI
87+
virtual QString label() const { return QString(); }
88+
89+
/// It is possible to hide the nickname in GUI
90+
virtual bool labelVisible() const { return true; }
91+
92+
/// Controls whether the label can be edited or not
93+
virtual bool labelEditable() const { return false; }
94+
8695
/// Returns the curent processing status
8796
virtual NodeProcessingStatus processingStatus() const { return _processingStatus; }
8897

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)