-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.cpp
163 lines (144 loc) · 4.45 KB
/
interface.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
#include "interface.h"
#include "paramwindow.h"
#include "statewindow.h"
#include "controlwindow.h"
#include <QDebug>
TInterface::TInterface(QWidget *parent)
: QWidget(parent)
{
setFixedSize(150,120);
canControl = true;
paramWindow = nullptr;
stateWindow = nullptr;
controlWindow = nullptr;
paramWindow_btn = new QPushButton("Параметры",this);
paramWindow_btn->setGeometry(15,10,120,30);
connect(paramWindow_btn,SIGNAL(pressed()),this,SLOT(openParamWindow()));
stateWindow_btn = new QPushButton("Состояние",this);
stateWindow_btn->setGeometry(15,45,120,30);
connect(stateWindow_btn,SIGNAL(pressed()),this,SLOT(openStateWindow()));
controlWindow_btn = new QPushButton("Управление",this);
controlWindow_btn->setGeometry(15,80,120,30);
connect(controlWindow_btn,SIGNAL(pressed()),this,SLOT(openControlWindow()));
}
TInterface::~TInterface()
{
delete controlWindow_btn;
delete paramWindow_btn;
delete stateWindow_btn;
}
void TInterface::setControlState(const bool s)
{
canControl = s;
qDebug()<<"interface state"<<canControl;
if (paramWindow != nullptr)
paramWindow->setEnable(s);
if (controlWindow != nullptr)
controlWindow->setEnable(s);
}
void TInterface::setCurrentParams(const TParamData pd)
{
if (paramWindow != nullptr)
paramWindow->setCurrentParams(pd);
}
void TInterface::setCurrentState(const TStateData sd)
{
if (stateWindow != nullptr)
stateWindow->setCurrentState(sd);
}
void TInterface::closeEvent(QCloseEvent* event)
{
if (paramWindow != nullptr)
{
disconnect(paramWindow,SIGNAL(closing()),
this,SLOT(paramWindowClosed()));
paramWindow->close();
}
if (stateWindow != nullptr)
{
disconnect(stateWindow,SIGNAL(closing()),
this,SLOT(stateWindowClosed()));
stateWindow->close();
}
if (controlWindow != nullptr)
{
disconnect(controlWindow,SIGNAL(closing()),
this,SLOT(controlWindowClosed()));
controlWindow->close();
}
event->accept();
}
void TInterface::paramWindowClosed()
{
disconnect(paramWindow,SIGNAL(closing()),
this,SLOT(paramWindowClosed()));
disconnect(paramWindow,SIGNAL(sendModelParams(TParamData)),
this,SIGNAL(sendModelParams(TParamData)));
disconnect(paramWindow,SIGNAL(restoreParams()),
this,SLOT(restoreParams()));
paramWindow = nullptr;
}
void TInterface::stateWindowClosed()
{
disconnect(stateWindow,SIGNAL(closing()),
this,SLOT(stateWindowClosed()));
stateWindow = nullptr;
}
void TInterface::controlWindowClosed()
{
disconnect(controlWindow,SIGNAL(closing()),
this,SLOT(controlWindowClosed()));
disconnect(controlWindow,SIGNAL(clear()),
this,SIGNAL(clear()));
disconnect(controlWindow,SIGNAL(single()),
this,SIGNAL(single()));
disconnect(controlWindow,SIGNAL(mode(bool)),
this,SIGNAL(mode(bool)));
controlWindow = nullptr;
}
void TInterface::restoreParams()
{
emit paramRequest(PARAMREQUEST,nullptr);
}
void TInterface::openParamWindow()
{
if (paramWindow == nullptr)
{
paramWindow = new TParamWindow(canControl);
connect(paramWindow,SIGNAL(sendModelParams(TParamData)),
this,SIGNAL(sendModelParams(TParamData)));
connect(paramWindow,SIGNAL(closing()),
this,SLOT(paramWindowClosed()));
connect(paramWindow,SIGNAL(restoreParams()),
this,SLOT(restoreParams()));
paramWindow->show();
emit paramRequest(PARAMREQUEST,nullptr);
}
}
void TInterface::openStateWindow()
{
if (stateWindow == nullptr)
{
stateWindow = new TStateWindow();
connect(stateWindow,SIGNAL(closing()),
this,SLOT(stateWindowClosed()));
stateWindow->show();
emit stateRequest(STATEREQUEST,nullptr);
}
}
void TInterface::openControlWindow()
{
if (controlWindow == nullptr)
{
controlWindow = new TControlWindow(canControl);
connect(controlWindow,SIGNAL(closing()),
this,SLOT(controlWindowClosed()));
connect(controlWindow,SIGNAL(clear()),
this,SIGNAL(clear()));
connect(controlWindow,SIGNAL(single()),
this,SIGNAL(single()));
connect(controlWindow,SIGNAL(mode(bool)),
this,SIGNAL(mode(bool)));
controlWindow->show();
}
}