Files

81 lines
1.4 KiB
C++
Raw Permalink Normal View History

2016-05-31 23:22:03 +02:00
#pragma once
#include <QtCore/QObject>
#include <QtWidgets/QLabel>
#include "TextData.hpp"
#include <nodes/NodeDataModel>
#include <iostream>
2017-01-30 10:31:43 +01:00
using QtNodes::PortType;
using QtNodes::PortIndex;
using QtNodes::NodeData;
using QtNodes::NodeDataModel;
2016-05-31 23:22:03 +02:00
/// The model dictates the number of inputs and outputs for the Node.
/// In this example it has no logic.
class TextDisplayDataModel : public NodeDataModel
{
Q_OBJECT
public:
TextDisplayDataModel();
2016-11-22 22:01:28 +01:00
virtual
~TextDisplayDataModel() {}
2016-05-31 23:22:03 +02:00
2016-09-23 09:45:07 +02:00
public:
QString
caption() const override
{ return QString("Text Display"); }
2016-11-22 22:01:28 +01:00
bool
captionVisible() const override { return false; }
2016-09-23 09:45:07 +02:00
2016-11-22 22:01:28 +01:00
QString
name() const override
2016-09-23 09:45:07 +02:00
{ return QString("TextDisplayDataModel"); }
2016-11-22 08:21:59 -07:00
std::unique_ptr<NodeDataModel>
clone() const override
2016-11-22 22:01:28 +01:00
{ return std::make_unique<TextDisplayDataModel>(); }
2016-09-23 09:45:07 +02:00
2016-05-31 23:22:03 +02:00
public:
2016-11-22 22:01:28 +01:00
unsigned int
nPorts(PortType portType) const override;
2016-05-31 23:22:03 +02:00
2016-11-22 22:01:28 +01:00
NodeDataType
dataType(PortType portType, PortIndex portIndex) const override;
2016-05-31 23:22:03 +02:00
2016-11-22 22:01:28 +01:00
std::shared_ptr<NodeData>
outData(PortIndex port) override;
2016-11-22 22:01:28 +01:00
void
setInData(std::shared_ptr<NodeData> data, int) override
2016-05-31 23:22:03 +02:00
{
auto textData = std::dynamic_pointer_cast<TextData>(data);
if (textData)
{
_label->setText(textData->text());
}
else
{
_label->clear();
}
_label->adjustSize();
2016-05-31 23:22:03 +02:00
}
2016-11-22 22:01:28 +01:00
QWidget *
embeddedWidget() override { return _label; }
2016-05-31 23:22:03 +02:00
private:
QLabel * _label;
};