-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathTextSourceModel.hpp
More file actions
69 lines (54 loc) · 1.55 KB
/
TextSourceModel.hpp
File metadata and controls
69 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include <QtNodes/NodeDelegateModel>
#include <QtCore/QObject>
#include <QtWidgets/QLineEdit>
#include "TextData.hpp"
using QtNodes::NodeData;
using QtNodes::NodeDataType;
using QtNodes::NodeDelegateModel;
using QtNodes::PortIndex;
using QtNodes::PortType;
/// A simple text source node with an embedded line edit
class TextSourceModel : public NodeDelegateModel
{
Q_OBJECT
public:
TextSourceModel()
: _lineEdit(nullptr)
{}
QString caption() const override { return QStringLiteral("Text Source"); }
QString name() const override { return QStringLiteral("TextSource"); }
unsigned int nPorts(PortType portType) const override
{
if (portType == PortType::Out)
return 1;
return 0;
}
NodeDataType dataType(PortType, PortIndex) const override
{
return TextData{}.type();
}
std::shared_ptr<NodeData> outData(PortIndex) override
{
return _data;
}
void setInData(std::shared_ptr<NodeData>, PortIndex) override {}
QWidget *embeddedWidget() override
{
if (!_lineEdit) {
_lineEdit = new QLineEdit();
_lineEdit->setPlaceholderText("Enter text...");
connect(_lineEdit, &QLineEdit::textChanged, this, &TextSourceModel::onTextChanged);
}
return _lineEdit;
}
private Q_SLOTS:
void onTextChanged(QString const &text)
{
_data = std::make_shared<TextData>(text);
Q_EMIT dataUpdated(0);
}
private:
std::shared_ptr<TextData> _data;
QLineEdit *_lineEdit;
};