-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFOptionsCheck.cpp
86 lines (75 loc) · 2.24 KB
/
FFOptionsCheck.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
#include "ffoptions.h"
FFOptionsCheck::FFOptionsCheck(QWidget* parent)
:AbstructOption(CHECK, parent)
{
}
FFOptionsCheck::FFOptionsCheck(QString name, QString _command_checked, QString _command_unchecked, int def, QWidget* parent):
AbstructOption(CHECK, parent), command_checked(_command_checked), command_unchecked(_command_unchecked), name(name), state(def)
{
init();
}
FFOptionsCheck::~FFOptionsCheck(){
delete layout;
}
QString FFOptionsCheck::getCommand(){
if(box->checkState()==Qt::Checked){
return command_checked;
}
else{
return command_unchecked;
}
}
QString FFOptionsCheck::setInside(int st){
if(st != 0 && st != 1){
box->setCheckState(Qt::Unchecked);
return command_unchecked;
}
if(st){
box->setCheckState(Qt::Checked);
return command_checked;
}
else{
box->setCheckState(Qt::Unchecked);
return command_unchecked;
}
}
void FFOptionsCheck::init(){
layout = new QHBoxLayout(this);
box = new QCheckBox(name, this);
layout->addWidget(box);
if(state)
box->setCheckState(Qt::Checked);
else
box->setCheckState(Qt::Unchecked);
connect(box, &QCheckBox::stateChanged, this, &FFOptionsCheck::stateChanged);
}
int FFOptionsCheck::getCurrentState(){
if(box->isChecked()) return 1;
else return 0;
}
void FFOptionsCheck::read(const QJsonObject &json){
if (json.contains("name") && json["name"].isString())
name = json["name"].toString();
if (json.contains("command_checked") && json["command_checked"].isString())
command_checked = json["command_checked"].toString();
if (json.contains("command_unchecked") && json["command_unchecked"].isString())
command_unchecked = json["command_unchecked"].toString();
if (json.contains("state") && json["state"].isBool()){
bool s = json["state"].toBool();
if(s){
state = 1;
setInside(1);
}
else{
state = 0;
setInside(0);
}
}
//init();
}
void FFOptionsCheck::write(QJsonObject &json){
json["name"] = name;
json["command_checked"] = command_checked;
json["command_unchecked"] = command_unchecked;
json["state"] = getCurrentState();
}