Files
nodeeditor/examples/calculator/MathOperationDataModel.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

70 lines
977 B
C++

#include "MathOperationDataModel.hpp"
#include "NumberData.hpp"
unsigned int
MathOperationDataModel::
nPorts(PortType portType) const
{
unsigned int result;
if (portType == PortType::In)
result = 2;
else
result = 1;
return result;
}
NodeDataType
MathOperationDataModel::
dataType(PortType, PortIndex) const
{
return NumberData().type();
}
std::shared_ptr<NodeData>
MathOperationDataModel::
outData(PortIndex)
{
return std::static_pointer_cast<NodeData>(_result);
}
void
MathOperationDataModel::
setInData(std::shared_ptr<NodeData> data, PortIndex portIndex)
{
auto numberData =
std::dynamic_pointer_cast<NumberData>(data);
if (portIndex == 0)
{
_number1 = numberData;
}
else
{
_number2 = numberData;
}
compute();
}
NodeValidationState
MathOperationDataModel::
validationState() const
{
return modelValidationState;
}
QString
MathOperationDataModel::
validationMessage() const
{
return modelValidationError;
}