-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsDialog.cpp
More file actions
92 lines (68 loc) · 2.08 KB
/
Copy pathSettingsDialog.cpp
File metadata and controls
92 lines (68 loc) · 2.08 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
#include "SettingsDialog.h"
#include "ui_SettingsDialog.h"
#include <memory>
#include <qdialog.h>
#include <qwidget.h>
#include "AppSettings.h"
#include <qregularexpression.h>
#include <qvalidator.h>
#include <qdialogbuttonbox.h>
#include <qpushbutton.h>
SettingsDialog::SettingsDialog(QWidget *parent)
: QDialog(parent),
ui(std::make_unique<Ui::SettingsDialog>())
{
ui->setupUi(this);
ui->buttonBox->button(QDialogButtonBox::Save)->setText("Сохранить");
ui->buttonBox->button(QDialogButtonBox::Cancel)->setText("Отмена");
ui->buttonBox->button(QDialogButtonBox::Reset)->setText("Сброс");
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::reject);
connect(ui->buttonBox->button(QDialogButtonBox::Reset), &QPushButton::clicked,
this, &SettingsDialog::reload);
QRegularExpression rx("\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}("
"?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\b");
QValidator* valip = new QRegularExpressionValidator(rx, this);
ui->IpAddress->setValidator(valip);
ui->IpAddressReserve->setValidator(valip);
load();
}
SettingsDialog::~SettingsDialog() = default;
void SettingsDialog::accept()
{
store();
emit signal_settingsChanged();
QDialog::accept();
}
void SettingsDialog::reject()
{
QDialog::reject();
}
void SettingsDialog::load()
{
auto& s = AppSettings::instance();
s.load();
ui->IpAddress->setText(s.IpAddress);
ui->TcpPort->setValue(s.TcpPort);
ui->IpAddressReserve->setText(s.IpAddressReserve);
ui->TcpPortReserve->setValue(s.TcpPortReserve);
ui->CA->setValue(s.CA);
ui->OA->setValue(s.OA);
ui->GIperiod->setValue(s.GIperiod);
}
void SettingsDialog::store()
{
auto& s = AppSettings::instance();
s.IpAddress = ui->IpAddress->text();
s.TcpPort = ui->TcpPort->value();
s.IpAddressReserve = ui->IpAddressReserve->text();
s.TcpPortReserve = ui->TcpPortReserve->value();
s.CA = ui->CA->value();
s.OA = ui->OA->value();
s.GIperiod = ui->GIperiod->value();
s.store();
}
void SettingsDialog::reload()
{
load();
}