-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSensorView.cpp
More file actions
233 lines (206 loc) · 7.61 KB
/
SensorView.cpp
File metadata and controls
233 lines (206 loc) · 7.61 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include "SensorView.h"
#include "SensorsViewerManager.h"
SensorView::SensorView(QWidget *parent) : QWidget(parent), mainContainer(new QFrame())
{
}
SensorView::~SensorView()
{
delete scrollArea;
delete scrollContent;
delete scrollLayout;
delete mainContainer;
delete findInput;
}
QFrame *SensorView::addSensorsView()
{
mainContainer->setMinimumSize(650, 500);
mainContainer->setFrameShape(QFrame::StyledPanel);
mainContainer->setFrameShadow(QFrame::Plain);
mainContainer->setFrameStyle(QFrame::NoFrame);
mainContainer->setStyleSheet("background-color: #f5f5f5;");
scrollArea = new QScrollArea(mainContainer);
scrollArea->setWidgetResizable(true);
scrollContent = new QWidget(scrollArea);
scrollLayout = new QVBoxLayout(scrollContent);
scrollLayout->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
scrollContent->setLayout(scrollLayout);
scrollArea->setWidget(scrollContent);
scrollArea->setStyleSheet("background-color: #f5f5f5;");
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
QVBoxLayout *Layout = new QVBoxLayout(mainContainer);
QVBoxLayout *Layout2 = new QVBoxLayout();
findInput = new QLineEdit();
findInput->setPlaceholderText("Find sensor...");
findInput->setStyleSheet(Style::getLineEditStyle());
QPushButton *findButton = new QPushButton("Find", mainContainer);
connect(findButton, SIGNAL(clicked()), this, SLOT(findSensors()));
findButton->setStyleSheet(Style::getButton());
findButton->setMinimumSize(0, 20);
Layout2->addWidget(findInput);
Layout2->addWidget(findButton);
Layout->addLayout(Layout2);
Layout->addWidget(scrollArea);
return mainContainer;
}
void SensorView::cleanScrollView()
{
if (scrollLayout)
{
while (QLayoutItem *item = scrollLayout->takeAt(0))
{
QWidget *widget = item->widget();
if (widget)
{
delete widget;
}
delete item;
}
}
}
void SensorView::createSensorPerView(Sensor *sensor, const std::string &tipo, const QPixmap &pixmap, const unsigned int &index)
{
QFrame *frame = new QFrame(mainContainer);
frame->setMinimumSize(600, 200);
frame->setFrameShape(QFrame::StyledPanel);
frame->setFrameShadow(QFrame::Plain);
QVBoxLayout *verticalLayout = new QVBoxLayout(frame);
QHBoxLayout *optionsLayer = new QHBoxLayout();
QPushButton *eliminate = new QPushButton("Eliminate");
eliminate->setStyleSheet(Style::getButton());
eliminate->setMinimumSize(0, 20);
QPushButton *modify = new QPushButton("Modify");
modify->setStyleSheet(Style::getButton());
modify->setMinimumSize(0, 20);
connect(eliminate, &QPushButton::clicked, this, [=](){manager->deleteSensor(frame, index); });
connect(modify, &QPushButton::clicked, this, [=]()
{
manager->getModifyView()->setSensorRef(index);
manager->showModifySensorView(sensor->getName(), sensor->getModel(), sensor->getDescription()); });
optionsLayer->addWidget(eliminate);
optionsLayer->addWidget(modify);
QHBoxLayout *horizontalLayout = new QHBoxLayout();
horizontalLayout->setAlignment(Qt::AlignHCenter);
QLabel *imm = new QLabel("Immagine");
imm->setGeometry(QRect(7, 5, 401, 141));
if (tipo == "Gas Sensor" || tipo == "Temperature Sensor" || tipo == "Movement Sensor")
{
imm->setPixmap(pixmap);
}
QVBoxLayout *data = new QVBoxLayout();
QHBoxLayout *data2 = new QHBoxLayout();
QString nome = QString::fromStdString(tipo + "-" + sensor->getName() + "/" + sensor->getModel() + '\n' + sensor->getDescription());
QLabel *label_2 = new QLabel(QString::fromStdString(tipo));
label_2->setStyleSheet("color: #333333;");
QLabel *label_3 = new QLabel(QString::fromStdString(sensor->getName()));
label_3->setStyleSheet("color: #333333;");
QLabel *label_4 = new QLabel(QString::fromStdString(sensor->getModel()));
label_4->setStyleSheet("color: #333333;");
QLabel *label_5 = new QLabel(QString::fromStdString(sensor->getDescription()));
label_5->setStyleSheet("color: #333333;");
data->addWidget(label_2);
data2->addWidget(label_3);
data2->addWidget(label_4);
data->addLayout(data2);
data->addWidget(label_5);
label_2->setWordWrap(true);
label_2->setGeometry(QRect(7, 5, 401, 141));
horizontalLayout->addWidget(imm);
horizontalLayout->addSpacerItem(new QSpacerItem(140, 0, QSizePolicy::Fixed, QSizePolicy::Minimum));
horizontalLayout->addLayout(data);
horizontalLayout->setAlignment(Qt::AlignHCenter);
verticalLayout->addLayout(horizontalLayout);
QPushButton *graph = new QPushButton("Graph View");
graph->setStyleSheet(Style::getButton());
graph->setMinimumSize(0, 20);
connect(graph, &QPushButton::clicked, this, [=]()
{ manager->showGraphSensorView(sensor, index, view); });
verticalLayout->addWidget(graph);
scrollLayout->addWidget(frame);
verticalLayout->addLayout(optionsLayer, Qt::AlignTop | Qt::AlignLeft);
}
void SensorView::addSensorToView(const std::vector<Sensor *> &sensors)
{
cleanScrollView();
QPixmap pixmap;
unsigned int index = 0;
for (auto sensor : sensors)
{
std::string tipo;
if (view == "Gas Sensor" && dynamic_cast<GasSensor *>(sensor))
{
tipo = "Gas Sensor";
pixmap.load(":/assets/Gas.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
else if (view == "Movement Sensor" && dynamic_cast<MovSens *>(sensor))
{
tipo = "Movement Sensor";
pixmap.load(":/assets/Mov.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
else if (view == "Temperature Sensor" && dynamic_cast<TempSensor *>(sensor))
{
tipo = "Temperature Sensor";
pixmap.load(":/assets/Temp.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
else if (view == "")
{
if (dynamic_cast<TempSensor *>(sensor))
{
tipo = "Temperature Sensor";
pixmap.load(":/assets/Temp.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
else if (dynamic_cast<GasSensor *>(sensor))
{
tipo = "Gas Sensor";
pixmap.load(":/assets/Gas.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
else
{
tipo = "Movement Sensor";
pixmap.load(":/assets/Mov.png");
createSensorPerView(sensor, tipo, pixmap, index);
}
}
index += 1;
}
}
void SensorView::setManager(SensorsViewerManager *manager)
{
this->manager = manager;
}
void SensorView::setView(const std::string &view)
{
this->view = view;
}
void SensorView::findSensors() const
{
for (QObject *sensor : scrollContent->children())
{
if (QFrame *frameSensor = qobject_cast<QFrame *>(sensor))
{
QString datas;
for (QObject *wid : sensor->children())
{
if (QLabel *label = qobject_cast<QLabel *>(wid))
{
if (label->text().toStdString() != "IMMAGINE")
{
datas += label->text();
}
}
}
if (datas.toStdString().find(findInput->text().toStdString()) != std::string::npos)
{
frameSensor->setVisible(true);
}
else
{
frameSensor->hide();
}
}
}
}