-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialog.cpp
273 lines (223 loc) · 6.71 KB
/
dialog.cpp
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
* @licence app begin@
* Copyright (C) 2021 Alexander Wenzel
*
* This file is part of the DLT Multimeter project.
*
* \copyright This code is licensed under GPLv3.
*
* \author Alexander Wenzel <[email protected]>
*
* \file dialog.cpp
* @licence end@
*/
#include <QSerialPortInfo>
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QSettings>
#include "dialog.h"
#include "ui_dialog.h"
#include "settingsdialog.h"
#include "version.h"
Dialog::Dialog(bool autostart,QString configuration,QWidget *parent)
: QDialog(parent)
, ui(new Ui::Dialog)
, dltMiniServer(this)
, dltMultimeter(this)
{
ui->setupUi(this);
on_pushButtonDefaultSettings_clicked();
setWindowTitle(QString("DLTMultimeter %1").arg(DLT_MULTIMETER_VERSION));
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint);
ui->pushButtonStop->setDisabled(true);
connect(&dltMultimeter, SIGNAL(status(QString)), this, SLOT(statusMultimeter(QString)));
connect(&dltMiniServer, SIGNAL(status(QString)), this, SLOT(statusDlt(QString)));
connect(&dltMultimeter, SIGNAL(valueMultimeter(QString,QString)), this, SLOT(valueMultimeter(QString,QString)));
// load global settings from registry
QSettings settings;
QString filename = settings.value("autoload/filename").toString();
bool autoload = settings.value("autoload/checked").toBool();
bool autostartGlobal = settings.value("autostart/checked").toBool();
// autoload settings, when activated in global settings
if(autoload)
{
dltMultimeter.readSettings(filename);
dltMiniServer.readSettings(filename);
restoreSettings();
}
// autoload settings, when provided by command line
if(!configuration.isEmpty())
{
dltMultimeter.readSettings(configuration);
dltMiniServer.readSettings(configuration);
restoreSettings();
}
// autostart, when activated in global settings or by command line
if(autostartGlobal || autostart)
{
on_pushButtonStart_clicked();
}
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::restoreSettings()
{
}
void Dialog::updateSettings()
{
}
void Dialog::on_pushButtonStart_clicked()
{
updateSettings();
dltMultimeter.start();
dltMiniServer.start();
ui->pushButtonStart->setDisabled(true);
ui->pushButtonStop->setDisabled(false);
ui->pushButtonDefaultSettings->setDisabled(true);
ui->pushButtonLoadSettings->setDisabled(true);
ui->pushButtonSettings->setDisabled(true);
}
void Dialog::on_pushButtonStop_clicked()
{
dltMultimeter.stop();
dltMiniServer.stop();
ui->pushButtonStart->setDisabled(false);
ui->pushButtonStop->setDisabled(true);
ui->pushButtonDefaultSettings->setDisabled(false);
ui->pushButtonLoadSettings->setDisabled(false);
ui->pushButtonSettings->setDisabled(false);
}
void Dialog::statusMultimeter(QString text)
{
ui->lineEditStatusMultimeter->setText(text);
if(text == "" || text == "stopped")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::white);
ui->lineEditStatusMultimeter->setPalette(palette);
}
if(text == "reconnect")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::yellow);
ui->lineEditStatusMultimeter->setPalette(palette);
}
if(text == "started")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::green);
ui->lineEditStatusMultimeter->setPalette(palette);
}
if(text == "error")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::red);
ui->lineEditStatusMultimeter->setPalette(palette);
}
}
void Dialog::statusDlt(QString text)
{
ui->lineEditStatusDLT->setText(text);
if(text == "" || text == "stopped")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::white);
ui->lineEditStatusDLT->setPalette(palette);
}
if(text == "listening")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::yellow);
ui->lineEditStatusDLT->setPalette(palette);
}
if(text == "connected")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::green);
ui->lineEditStatusDLT->setPalette(palette);
}
if(text == "error")
{
QPalette palette;
palette.setColor(QPalette::Base,Qt::red);
ui->lineEditStatusDLT->setPalette(palette);
}
}
void Dialog::on_pushButtonSettings_clicked()
{
SettingsDialog dlg(this);
dlg.restoreSettings(&dltMultimeter, &dltMiniServer);
if(dlg.exec()==QDialog::Accepted)
{
dlg.backupSettings(&dltMultimeter, &dltMiniServer);
restoreSettings();
}
}
void Dialog::on_pushButtonDefaultSettings_clicked()
{
dltMultimeter.clearSettings();
dltMiniServer.clearSettings();
restoreSettings();
}
void Dialog::on_pushButtonLoadSettings_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Settings"), "", tr("DLTMultimeter Settings (*.xml);;All files (*.*)"));
if(fileName.isEmpty())
{
return;
}
dltMultimeter.readSettings(fileName);
dltMiniServer.readSettings(fileName);
restoreSettings();
}
void Dialog::on_pushButtonSaveSettings_clicked()
{
updateSettings();
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Settings"), "", tr("DLTMultimeter Settings (*.xml);;All files (*.*)"));
if(fileName.isEmpty())
{
return;
}
QFile file(fileName);
if (!file.open(QFile::WriteOnly | QFile::Text))
return;
QXmlStreamWriter xml(&file);
xml.setAutoFormatting(true);
//xml.writeStartDocument();
xml.writeStartElement("DLTMultimeterSettings");
dltMultimeter.writeSettings(xml);
dltMiniServer.writeSettings(xml);
xml.writeEndElement(); // DLTMultimeterSettings
//xml.writeEndDocument();
file.close();
}
void Dialog::on_pushButtonInfo_clicked()
{
QMessageBox msgBox(this);
msgBox.setWindowTitle("Info DLTMultimeter");
msgBox.setTextFormat(Qt::RichText);
QString text;
text += QString("Version: %1<br>").arg(DLT_MULTIMETER_VERSION);
text += "<br>";
text += "Information and Documentation can be found here:<br>";
text += "<br>";
text += "<a href='https://github.com/alexmucde/DLTMultimeter'>Github DLTMultimeter</a><br>";
text += "<br>";
text += "This SW is licensed under GPLv3.<br>";
text += "<br>";
text += "(C) 2021 Alexander Wenzel <[email protected]>";
msgBox.setText(text);
msgBox.setStandardButtons(QMessageBox::Ok);
msgBox.exec();
}
void Dialog::valueMultimeter(QString value,QString unit)
{
ui->lineEditUnit->setText(unit);
ui->lineEditValue->setText(value);
dltMiniServer.sendValue2(value,unit);
}