-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsdialog.cpp
101 lines (82 loc) · 2.72 KB
/
settingsdialog.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
/**
* @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 settingsdialog.cpp
* @licence end@
*/
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QSerialPortInfo>
#include <QSettings>
#include <QFileDialog>
SettingsDialog::SettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
QList<QSerialPortInfo> availablePorts = QSerialPortInfo::availablePorts();
ui->comboBoxSerialPort->clear();
for(int num = 0; num<availablePorts.length();num++)
{
ui->comboBoxSerialPort->addItem(availablePorts[num].portName());
}
/* load global settings */
QSettings settings;
QString filename = settings.value("autoload/filename").toString();
ui->lineEditAutoload->setText(filename);
bool autoload = settings.value("autoload/checked").toBool();
ui->groupBoxAutoload->setChecked(autoload);
bool autostart = settings.value("autostart/checked").toBool();
ui->checkBoxAutostart->setChecked(autostart);
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::on_pushButtonAutoload_clicked()
{
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Settings"), "", tr("DLTRelais Settings (*.xml);;All files (*.*)"));
if(fileName.isEmpty())
{
return;
}
ui->lineEditAutoload->setText(fileName);
QSettings settings;
settings.setValue("autoload/filename",fileName);
}
void SettingsDialog::restoreSettings(DLTMultimeter *dltMultimeter, DLTMiniServer *dltMiniServer)
{
/* DLTRelais */
ui->comboBoxSerialPort->setCurrentText(dltMultimeter->getInterface());
/* DLTMiniServer */
ui->lineEditPort->setText(QString("%1").arg(dltMiniServer->getPort()));
ui->lineEditApplicationId->setText(dltMiniServer->getApplicationId());
ui->lineEditContextId->setText(dltMiniServer->getContextId());
}
void SettingsDialog::backupSettings(DLTMultimeter *dltMultimeter, DLTMiniServer *dltMiniServer)
{
/* DLTRelais */
dltMultimeter->setInterface(ui->comboBoxSerialPort->currentText());
/* DLTMiniServer */
dltMiniServer->setPort(ui->lineEditPort->text().toUShort());
dltMiniServer->setApplicationId(ui->lineEditApplicationId->text());
dltMiniServer->setContextId(ui->lineEditContextId->text());
}
void SettingsDialog::on_checkBoxAutostart_clicked(bool checked)
{
QSettings settings;
settings.setValue("autostart/checked",checked);
}
void SettingsDialog::on_groupBoxAutoload_clicked(bool checked)
{
QSettings settings;
settings.setValue("autoload/checked",checked);
}