-
Notifications
You must be signed in to change notification settings - Fork 0
/
globalvarareaviewer.cpp
87 lines (73 loc) · 2.38 KB
/
globalvarareaviewer.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
#include "globalvarareaviewer.h"
#include "additionqt.h"
#include <QBoxLayout>
#include "globalvararea.h"
#include "vars/integervar.h"
#include "addvardialog.h"
#include "delvardialog.h"
#include "showvarsdialog.h"
#define BUTTON_WIDTH 73
#define BUTTON_HEIGHT 23
#define WIDGET_WIDTH 400
#define WIDGET_HEIGHT 70
GlobalVarAreaViewer::GlobalVarAreaViewer(QWidget *parent)
: QGroupBox(parent)
{
delVarButton = new QPushButton(this);
addVarButton = new QPushButton(this);
showVarsButton = new QPushButton(this);
addVarDialog = new AddVarDialog(this);
delVarDialog = new DelVarDialog(this);
showVarsDialog = new ShowVarsDialog(this);
varTitles = new QLabel(this);
//Interface set
QVBoxLayout *buttonLay = new QVBoxLayout;
regButton(addVarButton, "Add var", buttonLay);
regButton(delVarButton, "Del var", buttonLay);
regButton(showVarsButton, "Show vars", buttonLay);
//setFixedSize(WIDGET_WIDTH, WIDGET_HEIGHT);
QHBoxLayout *mainLay = new QHBoxLayout(this);
mainLay->addWidget(varTitles);
mainLay->addLayout(buttonLay);
setLayout(mainLay);
setBackgroundColor(this, QColor(255, 255, 255));
//connect signals/slots
connect(addVarButton, SIGNAL(clicked(bool)), this, SLOT(onAddVarClicked()));
connect(delVarButton, SIGNAL(clicked(bool)), this, SLOT(onDelVarClicked()));
connect(showVarsButton, SIGNAL(clicked(bool)), this, SLOT(onShowVarsClicked()));
connect(addVarDialog, SIGNAL(successAddVar(Var*)), this, SLOT(onSuccessAddVar(Var*)));
connect(delVarDialog, SIGNAL(successDelVar(QString)), this, SLOT(onSuccessDelVar(QString)));
}
void GlobalVarAreaViewer::updateVarText()
{
varTitles->clear();
varTitles->setText(GlobalVarArea::toText());
}
void GlobalVarAreaViewer::regButton(QPushButton *btn, QString text, QBoxLayout *btnLay)
{
btn->setText(text);
btn->setFixedSize(BUTTON_WIDTH, BUTTON_HEIGHT);
btnLay->addWidget(btn);
}
void GlobalVarAreaViewer::onAddVarClicked()
{
addVarDialog->show();
}
void GlobalVarAreaViewer::onSuccessAddVar(Var *var)
{
GlobalVarArea::addVar(var);
updateVarText();
}
void GlobalVarAreaViewer::onDelVarClicked()
{
delVarDialog->show();
}
void GlobalVarAreaViewer::onSuccessDelVar(QString idDelVar)
{
GlobalVarArea::deleteById(idDelVar);
updateVarText();
}
void GlobalVarAreaViewer::onShowVarsClicked()
{
showVarsDialog->show();
}