From ee05cd81c2f2479e195548bb2508faa35c4359a4 Mon Sep 17 00:00:00 2001 From: Dmitry Pinaev Date: Sun, 29 Nov 2026 22:11:08 +0100 Subject: [PATCH 1/2] Do nothing on paste when the clipboard has no mime data QClipboard::mimeData() can return a null pointer. The paste command used it without a check. Fixes #555 --- src/UndoCommands.cpp | 4 ++++ test/src/TestSerializedItemCommands.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/UndoCommands.cpp b/src/UndoCommands.cpp index dda9e853..6c32a92a 100644 --- a/src/UndoCommands.cpp +++ b/src/UndoCommands.cpp @@ -444,6 +444,10 @@ QJsonObject PasteCommand::takeSceneJsonFromClipboard() QClipboard const *clipboard = QApplication::clipboard(); QMimeData const *mimeData = clipboard->mimeData(); + // Qt returns no mime data on some platforms, for example after a clear. + if (!mimeData) + return QJsonObject(); + QJsonDocument json; if (mimeData->hasFormat("application/qt-nodes-graph")) { json = QJsonDocument::fromJson(mimeData->data("application/qt-nodes-graph")); diff --git a/test/src/TestSerializedItemCommands.cpp b/test/src/TestSerializedItemCommands.cpp index 6bd66101..2d38c9f3 100644 --- a/test/src/TestSerializedItemCommands.cpp +++ b/test/src/TestSerializedItemCommands.cpp @@ -619,3 +619,22 @@ TEST_CASE("Loading serialized items restores a group and a connection for ids ab NodeId const first = *otherModel.allNodeIds().begin(); CHECK(otherModel.allConnectionIds(first).size() == 1); } + +TEST_CASE("Paste does nothing when the clipboard has no mime data", "[core][clipboard]") +{ + auto app = applicationSetup(); + + RecordingGraphModel model; + BasicGraphicsScene scene(model); + + NodeId const a = addNodeAt(model, QPointF(0, 0)); + + // Some platforms, for example offscreen, return no mime data after a clear. + QApplication::clipboard()->clear(); + + scene.undoStack().push(new PasteCommand(&scene, QPointF(500, 500))); + + CHECK(model.allNodeIds().size() == 1); + CHECK(model.nodeExists(a)); + CHECK(scene.undoStack().count() == 0); +} From 9d089c76911915906d3b4d8655c6f749c6300683 Mon Sep 17 00:00:00 2001 From: Dmitry Pinaev Date: Sun, 29 Nov 2026 22:13:23 +0100 Subject: [PATCH 2/2] Test that a cleared scene no longer listens to the node lock state The connection of a node graphics object now has the object as its context, so it ends with the object. This test keeps it so. See #428. --- test/src/TestBasicGraphicsScene.cpp | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/src/TestBasicGraphicsScene.cpp b/test/src/TestBasicGraphicsScene.cpp index 99c548f8..8c48e722 100644 --- a/test/src/TestBasicGraphicsScene.cpp +++ b/test/src/TestBasicGraphicsScene.cpp @@ -6,6 +6,7 @@ #include #include +#include #include using QtNodes::BasicGraphicsScene; @@ -119,3 +120,35 @@ TEST_CASE("BasicGraphicsScene undo/redo support", "[graphics]") CHECK(undoStack.count() >= 0); } } + +namespace { + +/// Tells if anything listens to the signal for the lock state of a node. +class FlagsListenerModel : public TestGraphModel +{ +public: + bool hasFlagsListener() const + { + return isSignalConnected(QMetaMethod::fromSignal(&TestGraphModel::nodeFlagsUpdated)); + } +}; + +} // namespace + +TEST_CASE("A cleared scene no longer listens to the lock state of the model", + "[graphics][lifetime]") +{ + auto app = applicationSetup(); + FlagsListenerModel model; + BasicGraphicsScene scene(model); + + NodeId const id = model.addNode("TestNode"); + REQUIRE(model.hasFlagsListener()); + + scene.clearScene(); + REQUIRE_FALSE(model.nodeExists(id)); + + // The deleted node graphics object must not stay connected to the model. + CHECK_FALSE(model.hasFlagsListener()); + Q_EMIT model.nodeFlagsUpdated(id); +}