-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream.cpp
More file actions
176 lines (149 loc) · 3.89 KB
/
stream.cpp
File metadata and controls
176 lines (149 loc) · 3.89 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "axis.h"
#include "axisarea.h"
#include "datasource.h"
#include "plotarea.h"
#include "stream.h"
#include "utils.h"
#include <QtGlobal>
#include <QByteArray>
#include <QColor>
#include <QString>
#include <QUuid>
Stream::Stream(QObject* parent): QObject(parent), uuid(), source(nullptr)
{
this->init();
}
Stream::Stream(const QString& u, DataSource* dataSource, QObject* parent):
QObject(parent), uuid(u), source(dataSource)
{
this->init();
this->sourceset = true;
}
Stream::Stream(const QUuid& u, DataSource* dataSource, QObject* parent):
QObject(parent), uuid(u), source(dataSource)
{
this->init();
this->sourceset = true;
}
void Stream::init()
{
this->timeOffset = 0;
this->color.red = 0.0f;
this->color.green = 0.0f;
this->color.blue = 1.0f;
this->sourceset = false;
this->dataDensity = false;
this->selected = false;
this->alwaysConnect = false;
this->axis = nullptr;
this->plotarea = nullptr;
}
bool Stream::toDrawable(struct drawable& d) const
{
if (this->axis == nullptr)
{
return false;
}
d.data = this->data;
d.timeOffset = this->timeOffset;
this->axis->getDomain(&d.ymin, &d.ymax);
d.color = this->color;
d.dataDensity = this->dataDensity;
d.selected = this->selected;
d.alwaysConnect = this->alwaysConnect;
return true;
}
bool Stream::getSelected() const {
return this->selected;
}
void Stream::setSelected(bool isSelected) {
bool changed = (this->selected != isSelected);
this->selected = isSelected;
if (changed && this->plotarea != nullptr) {
this->plotarea->update();
emit this->selectedChanged();
}
}
bool Stream::getAlwaysConnect() const {
return this->alwaysConnect;
}
void Stream::setAlwaysConnect(bool shouldAlwaysConnect) {
bool changed = (this->alwaysConnect != shouldAlwaysConnect);
this->alwaysConnect = shouldAlwaysConnect;
if (changed && this->plotarea != nullptr) {
this->plotarea->update();
emit this->alwaysConnectChanged();
}
}
bool Stream::setColor(float red, float green, float blue)
{
if (red < 0.0f || red > 1.0f || green < 0.0f || green > 1.0f ||
blue < 0.0f || blue > 1.0f)
{
return false;
}
this->color.red = red;
this->color.green = green;
this->color.blue = blue;
if (this->axis != nullptr)
{
for (auto j = this->axis->axisareas.begin(); j != this->axis->axisareas.end(); j++)
{
YAxisArea* axisarea = *j;
if (axisarea->plotarea != nullptr)
{
axisarea->plotarea->update();
}
}
}
emit this->colorChanged();
return true;
}
bool Stream::setColor(QColor color)
{
return this->setColor((float) color.redF(), (float) color.greenF(),
(float) color.blueF());
}
QColor Stream::getColor()
{
return QColor(qRound(this->color.red * 255), qRound(this->color.green * 255), qRound(this->color.blue * 255));
}
void Stream::setTimeOffset(int64_t offset)
{
this->timeOffset = offset;
emit this->timeOffsetChanged();
}
void Stream::setTimeOffset(QList<qreal> offset)
{
this->setTimeOffset(joinTime((int64_t) offset.value(0), (int64_t) offset.value(1)));
}
QList<qreal> Stream::getTimeOffset()
{
int64_t millis;
int64_t nanos;
splitTime(this->timeOffset, &millis, &nanos);
QList<qreal> offset;
offset.append((qreal) millis);
offset.append((qreal) nanos);
return offset;
}
void Stream::setDataSource(DataSource* source)
{
this->sourceset = true;
this->source = source;
emit this->dataSourceChanged();
}
DataSource* Stream::getDataSource()
{
return this->source;
}
void Stream::setUUID(QString uuidstr)
{
this->uuid = QUuid(uuidstr);
emit this->dataSourceChanged();
}
QString Stream::getUUID()
{
QString uuidstr = this->uuid.toString();
return uuidstr.mid(1, uuidstr.size() - 2);
}