|
@@ -1,4 +1,4 @@
|
|
|
-#include "DefaultVerticalNodeGeometry.hpp"
|
|
|
+#include "DefaultVerticalNodeGeometry.hpp"
|
|
|
|
|
|
#include "AbstractGraphModel.hpp"
|
|
|
#include "NodeData.hpp"
|
|
@@ -6,15 +6,16 @@
|
|
|
#include <QPoint>
|
|
|
#include <QRect>
|
|
|
#include <QWidget>
|
|
|
+#include <QDebug>
|
|
|
|
|
|
namespace QtNodes {
|
|
|
|
|
|
DefaultVerticalNodeGeometry::DefaultVerticalNodeGeometry(AbstractGraphModel &graphModel)
|
|
|
- : AbstractNodeGeometry(graphModel)
|
|
|
- , _portSize(20)
|
|
|
- , _portSpasing(10)
|
|
|
- , _fontMetrics(QFont())
|
|
|
- , _boldFontMetrics(QFont())
|
|
|
+ : AbstractNodeGeometry(graphModel),
|
|
|
+ _portSize(20),
|
|
|
+ _portSpasing(10),
|
|
|
+ _fontMetrics(QFont()),
|
|
|
+ _boldFontMetrics(QFont())
|
|
|
{
|
|
|
QFont f;
|
|
|
f.setBold(true);
|
|
@@ -30,12 +31,14 @@ QSize DefaultVerticalNodeGeometry::size(NodeId const nodeId) const
|
|
|
|
|
|
void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
|
|
|
{
|
|
|
- unsigned int height = _portSpasing; // maxHorizontalPortsExtent(nodeId);
|
|
|
+ unsigned int height = _portSpasing; // maxHorizontalPortsExtent(nodeId);
|
|
|
|
|
|
if (auto w = _graphModel.nodeData<QWidget *>(nodeId, NodeRole::Widget)) {
|
|
|
height = std::max(height, static_cast<unsigned int>(w->height()));
|
|
|
}
|
|
|
|
|
|
+ height += 20;
|
|
|
+
|
|
|
QRectF const capRect = captionRect(nodeId);
|
|
|
|
|
|
height += capRect.height();
|
|
@@ -43,7 +46,7 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
|
|
|
height += _portSpasing;
|
|
|
height += _portSpasing;
|
|
|
|
|
|
- PortCount nInPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::InPortCount);
|
|
|
+ PortCount nInPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::InPortCount);
|
|
|
PortCount nOutPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::OutPortCount);
|
|
|
|
|
|
// Adding double step (top and bottom) to reserve space for port captions.
|
|
@@ -51,16 +54,12 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
|
|
|
height += portCaptionsHeight(nodeId, PortType::In);
|
|
|
height += portCaptionsHeight(nodeId, PortType::Out);
|
|
|
|
|
|
- unsigned int inPortWidth = maxPortsTextAdvance(nodeId, PortType::In);
|
|
|
+ unsigned int inPortWidth = maxPortsTextAdvance(nodeId, PortType::In);
|
|
|
unsigned int outPortWidth = maxPortsTextAdvance(nodeId, PortType::Out);
|
|
|
|
|
|
- unsigned int totalInPortsWidth = nInPorts > 0
|
|
|
- ? inPortWidth * nInPorts + _portSpasing * (nInPorts - 1)
|
|
|
- : 0;
|
|
|
+ unsigned int totalInPortsWidth = nInPorts > 0 ? inPortWidth * nInPorts + _portSpasing * (nInPorts - 1) : 0;
|
|
|
|
|
|
- unsigned int totalOutPortsWidth = nOutPorts > 0 ? outPortWidth * nOutPorts
|
|
|
- + _portSpasing * (nOutPorts - 1)
|
|
|
- : 0;
|
|
|
+ unsigned int totalOutPortsWidth = nOutPorts > 0 ? outPortWidth * nOutPorts + _portSpasing * (nOutPorts - 1) : 0;
|
|
|
|
|
|
unsigned int width = std::max(totalInPortsWidth, totalOutPortsWidth);
|
|
|
|
|
@@ -78,8 +77,7 @@ void DefaultVerticalNodeGeometry::recomputeSize(NodeId const nodeId) const
|
|
|
_graphModel.setNodeData(nodeId, NodeRole::Size, size);
|
|
|
}
|
|
|
|
|
|
-QPointF DefaultVerticalNodeGeometry::portPosition(NodeId const nodeId,
|
|
|
- PortType const portType,
|
|
|
+QPointF DefaultVerticalNodeGeometry::portPosition(NodeId const nodeId, PortType const portType,
|
|
|
PortIndex const portIndex) const
|
|
|
{
|
|
|
QPointF result;
|
|
@@ -103,7 +101,7 @@ QPointF DefaultVerticalNodeGeometry::portPosition(NodeId const nodeId,
|
|
|
|
|
|
case PortType::Out: {
|
|
|
unsigned int outPortWidth = maxPortsTextAdvance(nodeId, PortType::Out) + _portSpasing;
|
|
|
- PortCount nOutPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::OutPortCount);
|
|
|
+ PortCount nOutPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::OutPortCount);
|
|
|
|
|
|
double x = (size.width() - (nOutPorts - 1) * outPortWidth) / 2.0 + portIndex * outPortWidth;
|
|
|
|
|
@@ -121,8 +119,7 @@ QPointF DefaultVerticalNodeGeometry::portPosition(NodeId const nodeId,
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-QPointF DefaultVerticalNodeGeometry::portTextPosition(NodeId const nodeId,
|
|
|
- PortType const portType,
|
|
|
+QPointF DefaultVerticalNodeGeometry::portTextPosition(NodeId const nodeId, PortType const portType,
|
|
|
PortIndex const portIndex) const
|
|
|
{
|
|
|
QPointF p = portPosition(nodeId, portType, portIndex);
|
|
@@ -155,6 +152,7 @@ QRectF DefaultVerticalNodeGeometry::captionRect(NodeId const nodeId) const
|
|
|
return QRect();
|
|
|
|
|
|
QString name = _graphModel.nodeData<QString>(nodeId, NodeRole::Caption);
|
|
|
+ qDebug() << __FUNCTION__ << __LINE__ << "----" << name << endl;
|
|
|
|
|
|
return _boldFontMetrics.boundingRect(name);
|
|
|
}
|
|
@@ -199,8 +197,7 @@ QRect DefaultVerticalNodeGeometry::resizeHandleRect(NodeId const nodeId) const
|
|
|
return QRect(size.width() - rectSize, size.height() - rectSize, rectSize, rectSize);
|
|
|
}
|
|
|
|
|
|
-QRectF DefaultVerticalNodeGeometry::portTextRect(NodeId const nodeId,
|
|
|
- PortType const portType,
|
|
|
+QRectF DefaultVerticalNodeGeometry::portTextRect(NodeId const nodeId, PortType const portType,
|
|
|
PortIndex const portIndex) const
|
|
|
{
|
|
|
QString s;
|
|
@@ -222,21 +219,18 @@ unsigned int DefaultVerticalNodeGeometry::maxHorizontalPortsExtent(NodeId const
|
|
|
PortCount nOutPorts = _graphModel.nodeData<PortCount>(nodeId, NodeRole::OutPortCount);
|
|
|
|
|
|
unsigned int maxNumOfEntries = std::max(nInPorts, nOutPorts);
|
|
|
- unsigned int step = _portSize + _portSpasing;
|
|
|
+ unsigned int step = _portSize + _portSpasing;
|
|
|
|
|
|
return step * maxNumOfEntries;
|
|
|
}
|
|
|
|
|
|
-unsigned int DefaultVerticalNodeGeometry::maxPortsTextAdvance(NodeId const nodeId,
|
|
|
- PortType const portType) const
|
|
|
+unsigned int DefaultVerticalNodeGeometry::maxPortsTextAdvance(NodeId const nodeId, PortType const portType) const
|
|
|
{
|
|
|
unsigned int width = 0;
|
|
|
|
|
|
- size_t const n = _graphModel
|
|
|
- .nodeData(nodeId,
|
|
|
- (portType == PortType::Out) ? NodeRole::OutPortCount
|
|
|
- : NodeRole::InPortCount)
|
|
|
- .toUInt();
|
|
|
+ size_t const n =
|
|
|
+ _graphModel.nodeData(nodeId, (portType == PortType::Out) ? NodeRole::OutPortCount : NodeRole::InPortCount)
|
|
|
+ .toUInt();
|
|
|
|
|
|
for (PortIndex portIndex = 0ul; portIndex < n; ++portIndex) {
|
|
|
QString name;
|
|
@@ -244,10 +238,7 @@ unsigned int DefaultVerticalNodeGeometry::maxPortsTextAdvance(NodeId const nodeI
|
|
|
if (_graphModel.portData<bool>(nodeId, portType, portIndex, PortRole::CaptionVisible)) {
|
|
|
name = _graphModel.portData<QString>(nodeId, portType, portIndex, PortRole::Caption);
|
|
|
} else {
|
|
|
- NodeDataType portData = _graphModel.portData<NodeDataType>(nodeId,
|
|
|
- portType,
|
|
|
- portIndex,
|
|
|
- PortRole::DataType);
|
|
|
+ NodeDataType portData = _graphModel.portData<NodeDataType>(nodeId, portType, portIndex, PortRole::DataType);
|
|
|
|
|
|
name = portData.name;
|
|
|
}
|
|
@@ -262,8 +253,7 @@ unsigned int DefaultVerticalNodeGeometry::maxPortsTextAdvance(NodeId const nodeI
|
|
|
return width;
|
|
|
}
|
|
|
|
|
|
-unsigned int DefaultVerticalNodeGeometry::portCaptionsHeight(NodeId const nodeId,
|
|
|
- PortType const portType) const
|
|
|
+unsigned int DefaultVerticalNodeGeometry::portCaptionsHeight(NodeId const nodeId, PortType const portType) const
|
|
|
{
|
|
|
unsigned int h = 0;
|
|
|
|
|
@@ -297,4 +287,4 @@ unsigned int DefaultVerticalNodeGeometry::portCaptionsHeight(NodeId const nodeId
|
|
|
return h;
|
|
|
}
|
|
|
|
|
|
-} // namespace QtNodes
|
|
|
+} // namespace QtNodes
|