diff --git a/examples/calculator/DivisionModel.hpp b/examples/calculator/DivisionModel.hpp index b059662..c51a5bc 100644 --- a/examples/calculator/DivisionModel.hpp +++ b/examples/calculator/DivisionModel.hpp @@ -22,7 +22,32 @@ public: QString caption() const override { return QString("Division"); } + + virtual bool + portCaptionVisible(PortType portType, PortIndex portIndex) const override + { return true; } + virtual QString + portCaption(PortType portType, PortIndex portIndex) const override + { + switch (portType) + { + case PortType::In: + if (portIndex == 0) + return QString("Dividend"); + else if (portIndex == 1) + return QString("Divisor"); + break; + + case PortType::Out: + return QString("Result"); + + default: + break; + } + return QString(""); + } + QString name() const override { return QString("Division"); } diff --git a/examples/calculator/SubtractionModel.hpp b/examples/calculator/SubtractionModel.hpp index 745bbcc..e5a1b49 100644 --- a/examples/calculator/SubtractionModel.hpp +++ b/examples/calculator/SubtractionModel.hpp @@ -24,6 +24,31 @@ public: caption() const override { return QString("Subtraction"); } + virtual bool + portCaptionVisible(PortType portType, PortIndex portIndex) const override + { return true; } + + virtual QString + portCaption(PortType portType, PortIndex portIndex) const override + { + switch (portType) + { + case PortType::In: + if (portIndex == 0) + return QString("Minuend"); + else if (portIndex == 1) + return QString("Subtrahend"); + break; + + case PortType::Out: + return QString("Result"); + + default: + break; + } + return QString(""); + } + QString name() const override { return QString("Subtraction"); } diff --git a/src/NodeDataModel.hpp b/src/NodeDataModel.hpp index 68750de..82ae8f3 100644 --- a/src/NodeDataModel.hpp +++ b/src/NodeDataModel.hpp @@ -29,6 +29,14 @@ public: virtual bool captionVisible() const { return true; } + /// Port caption is used in GUI to label individual ports + virtual QString + portCaption(PortType portType, PortIndex portIndex) const { return QString(""); } + + /// It is possible to hide port caption in GUI + virtual bool + portCaptionVisible(PortType portType, PortIndex portIndex) const { return false; } + /// Name makes this model unique virtual QString name() const = 0; diff --git a/src/NodeGeometry.cpp b/src/NodeGeometry.cpp index 748a283..0d9a516 100644 --- a/src/NodeGeometry.cpp +++ b/src/NodeGeometry.cpp @@ -256,7 +256,13 @@ portWidth(PortType portType) const for (auto i = 0ul; i < _dataModel->nPorts(portType); ++i) { - auto const &name = _dataModel->dataType(PortType::In, i).name; + QString name; + + if (_dataModel->portCaptionVisible(portType, i)) + name = _dataModel->portCaption(portType, i); + else + name = _dataModel->dataType(portType, i).name; + width = std::max(unsigned(_fontMetrics.width(name)), width); } diff --git a/src/NodePainter.cpp b/src/NodePainter.cpp index d74af05..534709f 100644 --- a/src/NodePainter.cpp +++ b/src/NodePainter.cpp @@ -271,7 +271,12 @@ drawEntryLabels(QPainter * painter, else painter->setPen(nodeStyle.FontColor); - QString s = model->dataType(portType, i).name; + QString s; + + if (model->portCaptionVisible(portType, i)) + s = model->portCaption(portType, i); + else + s = model->dataType(portType, i).name; auto rect = metrics.boundingRect(s);