loom
1#include "TextSourceDataModel.hpp"
2
3#include <QtWidgets/QLineEdit>
4
5TextSourceDataModel::TextSourceDataModel()
6: _lineEdit{nullptr}
7{
8//
9}
10
11unsigned int TextSourceDataModel::nPorts(PortType portType) const
12{
13unsigned int result = 1;
14
15switch (portType) {
16case PortType::In:
17result = 0;
18break;
19
20case PortType::Out:
21result = 1;
22
23default:
24break;
25}
26
27return result;
28}
29
30void TextSourceDataModel::onTextEdited(QString const &string)
31{
32Q_UNUSED(string);
33
34Q_EMIT dataUpdated(0);
35}
36
37NodeDataType TextSourceDataModel::dataType(PortType, PortIndex) const
38{
39return TextData().type();
40}
41
42std::shared_ptr<NodeData> TextSourceDataModel::outData(PortIndex const portIndex)
43{
44Q_UNUSED(portIndex);
45return std::make_shared<TextData>(_lineEdit->text());
46}
47
48QWidget *TextSourceDataModel::embeddedWidget()
49{
50if (!_lineEdit) {
51_lineEdit = new QLineEdit("Default Text"),
52
53connect(_lineEdit, &QLineEdit::textEdited, this, &TextSourceDataModel::onTextEdited);
54}
55
56return _lineEdit;
57}
58