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
3 changes: 2 additions & 1 deletion src/DefaultHorizontalNodeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ QPointF DefaultHorizontalNodeGeometry::widgetPosition(NodeId const nodeId) const
{
QSize size = _graphModel.nodeData<QSize>(nodeId, NodeRole::Size);

unsigned int captionHeight = captionRect(nodeId).height();
// Signed, because the subtraction below can be negative. An unsigned value would wrap.
int captionHeight = captionRect(nodeId).height();
if (_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible))
captionHeight += labelRect(nodeId).height() + _portSpacing / 2;

Expand Down
3 changes: 2 additions & 1 deletion src/DefaultVerticalNodeGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ QPointF DefaultVerticalNodeGeometry::widgetPosition(NodeId const nodeId) const
{
QSize size = _graphModel.nodeData<QSize>(nodeId, NodeRole::Size);

unsigned int captionHeight = captionRect(nodeId).height();
// Signed, because the subtraction below can be negative. An unsigned value would wrap.
int captionHeight = captionRect(nodeId).height();
if (_graphModel.nodeData<bool>(nodeId, NodeRole::LabelVisible))
captionHeight += labelRect(nodeId).height() + _portSpacing / 2;

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/TestWidgetPosition.cpp
src/TestOrientationWidgets.cpp
src/TestViewDragMode.cpp
include/ApplicationSetup.hpp
Expand Down
71 changes: 71 additions & 0 deletions test/src/TestWidgetPosition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#include "ApplicationSetup.hpp"
#include "UITestHelper.hpp"

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

#include <catch2/catch.hpp>

#include <QPointer>
#include <QWidget>

#include <memory>

using namespace QtNodes;

namespace {

class BoxModel : public NodeDelegateModel
{
public:
BoxModel()
: _box(new QWidget())
{
_box->setFixedSize(60, 40);
}
~BoxModel() override { delete _box; }

QString name() const override { return QStringLiteral("BoxModel"); }
QString caption() const override { return QStringLiteral("Box"); }
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 _box; }

private:
QPointer<QWidget> _box;
};

} // namespace

TEST_CASE("A widget taller than its node is not placed far below the node",
"[ui][widget-position]")
{
auto app = applicationSetup();

auto registry = std::make_shared<NodeDelegateModelRegistry>();
registry->registerModel<BoxModel>();
DataFlowGraphModel model(registry);
DataFlowGraphicsScene scene(model);

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

QWidget *box = model.delegateModel<BoxModel>(id)->embeddedWidget();
REQUIRE(box != nullptr);

for (Qt::Orientation orientation : {Qt::Horizontal, Qt::Vertical}) {
scene.setOrientation(orientation);

// The widget grows and the node is not recomputed yet.
box->setFixedHeight(box->height() + 400);

QPointF const pos = scene.nodeGeometry().widgetPosition(id);
CAPTURE(orientation, pos.y());
CHECK(std::abs(pos.y()) < 1000.0);
}
}
Loading