Files
nodeeditor/examples/calculator/NumberDisplayDataModel.cpp
T
David Bachrati 770a1aa9ec Implement runtime validation and error reporting (#46)
* Node validation and error display implemented

* Added option to iterate through nodes in the scene. (Useful to read out data from all the nodes, makes code generation based on the graphs easier.)

* Visual error fix for nodes that change size depending on input, plus minor styling and logic fixes in the example, based on the comments of @russelltg

* Validation extended to handle warnings, based on the idea of @russeltg ; Error display colors now come from the style system;  Additional bugfixes

* DefaultStyle.json identation fix

* FlowScene.cpp identation fix

* Travis build test fix
2017-01-25 11:34:03 +01:00

90 lines
1.3 KiB
C++

#include "NumberDisplayDataModel.hpp"
#include "NumberData.hpp"
NumberDisplayDataModel::
NumberDisplayDataModel()
: _label(new QLabel())
{
_label->setMargin(3);
}
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 NumberData().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<NumberData>(data);
if (numberData)
{
modelValidationState = NodeValidationState::Valid;
modelValidationError = QString("");
_label->setText(numberData->numberAsText());
}
else
{
modelValidationState = NodeValidationState::Warning;
modelValidationError = QString("Missing or incorrect inputs");
_label->clear();
}
_label->adjustSize();
}
NodeValidationState
NumberDisplayDataModel::
validationState() const
{
return modelValidationState;
}
QString
NumberDisplayDataModel::
validationMessage() const
{
return modelValidationError;
}