Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/UndoCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
33 changes: 33 additions & 0 deletions test/src/TestBasicGraphicsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <catch2/catch.hpp>

#include <QGraphicsView>
#include <QMetaMethod>
#include <QUndoStack>

using QtNodes::BasicGraphicsScene;
Expand Down Expand Up @@ -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);
}
19 changes: 19 additions & 0 deletions test/src/TestSerializedItemCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Loading