VisionFlowPro/NodeEditorPro/examples/calculator/NumberDisplayDataModel.cpp

103 lines
1.5 KiB
C++
Raw Normal View History

2023-02-28 14:50:28 +08:00
#include "NumberDisplayDataModel.hpp"
#include "DecimalData.hpp"
#include <QtWidgets/QLabel>
NumberDisplayDataModel::
NumberDisplayDataModel()
: _label{nullptr}
{
}
unsigned int
NumberDisplayDataModel::
nPorts(PortType portType) const
{
unsigned int result = 1;
switch (portType)
{
case PortType::In:
result = 1;
break;
case PortType::Out:
result = 0;
default:
break;
}
return result;
}
NodeDataType
NumberDisplayDataModel::
dataType(PortType, PortIndex) const
{
return DecimalData().type();
}
std::shared_ptr<NodeData>
NumberDisplayDataModel::
outData(PortIndex)
{
std::shared_ptr<NodeData> ptr;
return ptr;
}
void
NumberDisplayDataModel::
setInData(std::shared_ptr<NodeData> data, int)
{
auto numberData = std::dynamic_pointer_cast<DecimalData>(data);
if (numberData)
{
modelValidationState = NodeValidationState::Valid;
modelValidationError = QString();
_label->setText(numberData->numberAsText());
}
else
{
modelValidationState = NodeValidationState::Warning;
modelValidationError = QStringLiteral("Missing or incorrect inputs");
_label->clear();
}
_label->adjustSize();
}
QWidget*
NumberDisplayDataModel::
embeddedWidget()
{
if (!_label)
{
_label = new QLabel();
_label->setMargin(3);
}
return _label;
}
NodeValidationState
NumberDisplayDataModel::
validationState() const
{
return modelValidationState;
}
QString
NumberDisplayDataModel::
validationMessage() const
{
return modelValidationError;
}