Skip to content

Commit 98a1260

Browse files
raymentpaceholder
authored andcommitted
Fixed non-emit of BasicGraphicsScene::nodeMoved.
BasicGraphicsScene::nodeMoved was not being emitted anywhere. Now it is called each time the mouse is released from a node and the dragging behaviour is stopped. In the case that Q_EMIT is to be called directly within BasicGraphicsScene::onNodePositionUpdated, the signal occurs on every frame update which may be too often. As such, mouse release was chosen for the emitter. Signed-off-by: Finn Rayment <finn@rayment.fr>
1 parent 0a3a931 commit 98a1260

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

include/QtNodes/internal/BasicGraphicsScene.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public Q_SLOTS:
147147

148148
void onNodeUpdated(NodeId const nodeId);
149149

150+
void onNodeClicked(NodeId const nodeId);
151+
150152
void onModelReset();
151153

152154
private:
@@ -166,6 +168,8 @@ public Q_SLOTS:
166168

167169
std::unique_ptr<AbstractNodePainter> _nodePainter;
168170

171+
bool _nodeDrag;
172+
169173
QUndoStack *_undoStack;
170174

171175
Qt::Orientation _orientation;

src/BasicGraphicsScene.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ BasicGraphicsScene::BasicGraphicsScene(AbstractGraphModel &graphModel, QObject *
3636
, _graphModel(graphModel)
3737
, _nodeGeometry(std::make_unique<DefaultHorizontalNodeGeometry>(_graphModel))
3838
, _nodePainter(std::make_unique<DefaultNodePainter>())
39+
, _nodeDrag(false)
3940
, _undoStack(new QUndoStack(this))
4041
, _orientation(Qt::Horizontal)
4142
{
@@ -71,6 +72,8 @@ BasicGraphicsScene::BasicGraphicsScene(AbstractGraphModel &graphModel, QObject *
7172
this,
7273
&BasicGraphicsScene::onNodeUpdated);
7374

75+
connect(this, &BasicGraphicsScene::nodeClicked, this, &BasicGraphicsScene::onNodeClicked);
76+
7477
connect(&_graphModel, &AbstractGraphModel::modelReset, this, &BasicGraphicsScene::onModelReset);
7578

7679
traverseGraphAndPopulateGraphicsObjects();
@@ -257,6 +260,7 @@ void BasicGraphicsScene::onNodePositionUpdated(NodeId const nodeId)
257260
if (node) {
258261
node->setPos(_graphModel.nodeData(nodeId, NodeRole::Position).value<QPointF>());
259262
node->update();
263+
_nodeDrag = true;
260264
}
261265
}
262266

@@ -274,6 +278,13 @@ void BasicGraphicsScene::onNodeUpdated(NodeId const nodeId)
274278
}
275279
}
276280

281+
void BasicGraphicsScene::onNodeClicked(NodeId const nodeId)
282+
{
283+
if (_nodeDrag)
284+
Q_EMIT nodeMoved(nodeId, _graphModel.nodeData(nodeId, NodeRole::Position).value<QPointF>());
285+
_nodeDrag = false;
286+
}
287+
277288
void BasicGraphicsScene::onModelReset()
278289
{
279290
_connectionGraphicsObjects.clear();

src/DataFlowGraphModel.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ DataFlowGraphModel::DataFlowGraphModel(std::shared_ptr<NodeDelegateModelRegistry
1515
std::unordered_set<NodeId> DataFlowGraphModel::allNodeIds() const
1616
{
1717
std::unordered_set<NodeId> nodeIds;
18-
for_each(_models.begin(), _models.end(), [&nodeIds](auto const &p) {
19-
nodeIds.insert(p.first);
20-
});
18+
for_each(_models.begin(), _models.end(), [&nodeIds](auto const &p) { nodeIds.insert(p.first); });
2119

2220
return nodeIds;
2321
}

src/DefaultHorizontalNodeGeometry.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ void DefaultHorizontalNodeGeometry::recomputeSize(NodeId const nodeId) const
5252
width += w->width();
5353
}
5454

55-
width = std::max(width,
56-
static_cast<unsigned int>(capRect.width()) + 2 * _portSpasing);
55+
width = std::max(width, static_cast<unsigned int>(capRect.width()) + 2 * _portSpasing);
5756

5857
QSize size(width, height);
5958

src/DefaultVerticalNodeGeometry.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
5454
unsigned int inPortWidth = maxPortsTextAdvance(nodeId, PortType::In);
5555
unsigned int outPortWidth = maxPortsTextAdvance(nodeId, PortType::Out);
5656

57-
unsigned int totalInPortsWidth =
58-
nInPorts > 0 ? inPortWidth * nInPorts + _portSpasing * (nInPorts - 1) : 0;
57+
unsigned int totalInPortsWidth = nInPorts > 0
58+
? inPortWidth * nInPorts + _portSpasing * (nInPorts - 1)
59+
: 0;
5960

60-
unsigned int totalOutPortsWidth =
61-
nOutPorts > 0 ? outPortWidth * nOutPorts + _portSpasing * (nOutPorts - 1) : 0;
61+
unsigned int totalOutPortsWidth = nOutPorts > 0 ? outPortWidth * nOutPorts
62+
+ _portSpasing * (nOutPorts - 1)
63+
: 0;
6264

6365
unsigned int width = std::max(totalInPortsWidth, totalOutPortsWidth);
6466

0 commit comments

Comments
 (0)