loom
71 строка · 1.3 Кб
1#include "NumberDisplayDataModel.hpp"
2
3#include <QtWidgets/QLabel>
4
5NumberDisplayDataModel::NumberDisplayDataModel()
6: _label{nullptr}
7{}
8
9unsigned int NumberDisplayDataModel::nPorts(PortType portType) const
10{
11unsigned int result = 1;
12
13switch (portType) {
14case PortType::In:
15result = 1;
16break;
17
18case PortType::Out:
19result = 0;
20
21default:
22break;
23}
24
25return result;
26}
27
28NodeDataType NumberDisplayDataModel::dataType(PortType, PortIndex) const
29{
30return DecimalData().type();
31}
32
33std::shared_ptr<NodeData> NumberDisplayDataModel::outData(PortIndex)
34{
35std::shared_ptr<NodeData> ptr;
36return ptr;
37}
38
39void NumberDisplayDataModel::setInData(std::shared_ptr<NodeData> data, PortIndex )
40{
41_numberData = std::dynamic_pointer_cast<DecimalData>(data);
42
43if (!_label)
44return;
45
46if (_numberData) {
47_label->setText(_numberData->numberAsText());
48} else {
49_label->clear();
50}
51
52_label->adjustSize();
53}
54
55QWidget *NumberDisplayDataModel::embeddedWidget()
56{
57if (!_label) {
58_label = new QLabel();
59_label->setMargin(3);
60}
61
62return _label;
63}
64
65double NumberDisplayDataModel::number() const
66{
67if (_numberData)
68return _numberData->number();
69
70return 0.0;
71}
72