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
6 changes: 5 additions & 1 deletion src/BasicGraphicsScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,11 @@ void BasicGraphicsScene::setOrientation(Qt::Orientation const orientation)
break;
}

onModelReset();
// Only the geometry changes. Keep the graphics objects, so that the embedded widgets,
// the groups and the selection stay as they are.
for (NodeId const nodeId : _graphModel.allNodeIds()) {
onNodeUpdated(nodeId);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ add_executable(test_nodes
src/TestZoomFeatures.cpp
src/TestLoopDetection.cpp
src/TestEmbeddedWidgetKeys.cpp
src/TestOrientationWidgets.cpp
src/TestViewDragMode.cpp
include/ApplicationSetup.hpp
include/TestGraphModel.hpp
Expand Down
3 changes: 1 addition & 2 deletions test/src/TestNodeGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,7 @@ TEST_CASE("A model reset with a group does not leave dangling group items", "[no
scene->nodeGraphicsObject(b)};
REQUIRE(scene->createGroup(nodes, QStringLiteral("Reset")).lock());

// Changing the orientation resets the model view of the scene.
scene->setOrientation(Qt::Vertical);
Q_EMIT model.modelReset();

CHECK(scene->groups().empty());

Expand Down
98 changes: 98 additions & 0 deletions test/src/TestOrientationWidgets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#include "ApplicationSetup.hpp"
#include "UITestHelper.hpp"

#include <QtNodes/BasicGraphicsScene>
#include <QtNodes/DataFlowGraphModel>
#include <QtNodes/DataFlowGraphicsScene>
#include <QtNodes/GraphicsView>
#include <QtNodes/NodeDelegateModel>
#include <QtNodes/NodeDelegateModelRegistry>

#include <catch2/catch.hpp>

#include <QLineEdit>
#include <QPointer>

#include <memory>

using namespace QtNodes;

namespace {

class EditModel : public NodeDelegateModel
{
public:
EditModel()
: _edit(new QLineEdit(QStringLiteral("abc")))
{}
~EditModel() override { delete _edit; }

QString name() const override { return QStringLiteral("EditModel"); }
QString caption() const override { return QStringLiteral("Edit"); }
unsigned int nPorts(PortType) const override { return 0; }
NodeDataType dataType(PortType, PortIndex) const override { return {}; }
void setInData(std::shared_ptr<NodeData>, PortIndex) override {}
std::shared_ptr<NodeData> outData(PortIndex) override { return nullptr; }
QWidget *embeddedWidget() override { return _edit; }

private:
QPointer<QLineEdit> _edit;
};

} // namespace

TEST_CASE("The embedded widget survives a change of the scene orientation", "[ui][orientation]")
{
auto app = applicationSetup();

auto registry = std::make_shared<NodeDelegateModelRegistry>();
registry->registerModel<EditModel>();
DataFlowGraphModel model(registry);
DataFlowGraphicsScene scene(model);
GraphicsView view(&scene);
view.show();
REQUIRE(QTest::qWaitForWindowExposed(&view));

NodeId const id = model.addNode(QStringLiteral("EditModel"));
UITestHelper::waitForUI();

auto *model0 = model.delegateModel<EditModel>(id);
QWidget *edit = model0->embeddedWidget();
REQUIRE(edit != nullptr);
static_cast<QLineEdit *>(edit)->setText(QStringLiteral("typed"));

scene.setOrientation(Qt::Vertical);
UITestHelper::waitForUI();

QWidget *after = model0->embeddedWidget();
REQUIRE(after != nullptr);
CHECK(static_cast<QLineEdit *>(after)->text() == QStringLiteral("typed"));
CHECK(after->graphicsProxyWidget() != nullptr);
}

TEST_CASE("A change of the scene orientation keeps the groups and the selected nodes",
"[ui][orientation]")
{
auto app = applicationSetup();

auto registry = std::make_shared<NodeDelegateModelRegistry>();
registry->registerModel<EditModel>();
DataFlowGraphModel model(registry);
DataFlowGraphicsScene scene(model);
scene.setGroupingEnabled(true);

NodeId const a = model.addNode(QStringLiteral("EditModel"));
NodeId const b = model.addNode(QStringLiteral("EditModel"));
std::vector<NodeGraphicsObject *> nodes{scene.nodeGraphicsObject(a),
scene.nodeGraphicsObject(b)};
REQUIRE(scene.createGroup(nodes, QStringLiteral("Pair")).lock());
NodeId const c = model.addNode(QStringLiteral("EditModel"));
scene.nodeGraphicsObject(c)->setSelected(true);
REQUIRE(scene.nodeGraphicsObject(c)->isSelected());

scene.setOrientation(Qt::Vertical);

CHECK(scene.groups().size() == 1);
CHECK(scene.nodeGraphicsObject(a) == nodes[0]);
CHECK(scene.nodeGraphicsObject(c)->isSelected());
}
Loading