-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpropertywidget.cpp
167 lines (142 loc) · 5.88 KB
/
propertywidget.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
164
165
166
167
#include "addeditpropertydialog.h"
#include <QMessageBox>
#include <QSpacerItem>
#include <QStyleOption>
#include <QPainter>
PropertyWidget::PropertyWidget(Property *property, ProcessSystem *processSystem, FileSystem *fileSystem, PropertiesDock *parent) : QWidget(parent)
{
this->property = property;
this->processSystem = processSystem;
this->fileSystem = fileSystem;
this->parent = parent;
verificationProcessId = -1;
fileSystem->setPropertyModified(property->name);
/* create the label for the property name */
propertyNameLabel = new QLabel(property->name);
/* create the verify button */
QPushButton *verifyButton = new QPushButton();
verifyButton->setIcon(QIcon(":/icons/verify.png"));
verifyButton->setIconSize(QSize(24, 24));
verifyButton->setStyleSheet("border:none;");
connect(verifyButton, SIGNAL(clicked()), this, SLOT(actionVerify()));
/* create the abort button for when a property is being verified */
QPushButton *abortButton = new QPushButton();
abortButton->setIcon(QIcon(":/icons/abort.png"));
abortButton->setIconSize(QSize(24, 24));
abortButton->setStyleSheet("border:none;");
connect(abortButton, SIGNAL(clicked()), this, SLOT(actionAbortVerification()));
/* create the label for when a property is true */
QPixmap *trueIcon = new QPixmap(":/icons/true.png");
QLabel *trueLabel = new QLabel();
trueLabel->setPixmap(trueIcon->scaled(QSize(24, 24)));
/* create the label for when a property is false */
QPixmap *falseIcon = new QPixmap(":/icons/false.png");
QLabel *falseLabel = new QLabel();
falseLabel->setPixmap(falseIcon->scaled(QSize(24, 24)));
/* stack the verification widgets */
verificationWidgets = new QStackedWidget(this);
verificationWidgets->setMaximumSize(QSize(30, 30));
verificationWidgets->addWidget(verifyButton); /* index = 0 */
verificationWidgets->addWidget(abortButton); /* index = 1 */
verificationWidgets->addWidget(trueLabel); /* index = 2 */
verificationWidgets->addWidget(falseLabel); /* index = 3 */
verificationWidgets->setCurrentIndex(0);
/* create the edit button */
editButton = new QPushButton();
editButton->setIcon(QIcon(":/icons/edit.png"));
editButton->setIconSize(QSize(24, 24));
editButton->setStyleSheet("border:none;");
connect(editButton, SIGNAL(clicked()), this, SLOT(actionEdit()));
/* create the delete button */
deleteButton = new QPushButton();
deleteButton->setIcon(QIcon(":/icons/delete.png"));
deleteButton->setIconSize(QSize(24, 24));
deleteButton->setStyleSheet("border:none;");
connect(deleteButton, SIGNAL(clicked()), this, SLOT(actionDelete()));
/* lay them out */
propertyLayout = new QHBoxLayout();
propertyLayout->addWidget(propertyNameLabel);
propertyLayout->addStretch();
propertyLayout->addWidget(verificationWidgets);
propertyLayout->addWidget(editButton);
propertyLayout->addWidget(deleteButton);
this->setLayout(propertyLayout);
}
void PropertyWidget::paintEvent(QPaintEvent *pe) {
QStyleOption o;
o.initFrom(this);
QPainter p(this);
style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
}
Property *PropertyWidget::getProperty()
{
return this->property;
}
void PropertyWidget::setPropertyName(QString name)
{
this->property->name = name;
propertyNameLabel->setText(name);
}
void PropertyWidget::setPropertyText(QString text)
{
this->property->text = text;
}
void PropertyWidget::saveProperty()
{
fileSystem->saveProperty(property);
}
void PropertyWidget::actionVerify()
{
/* check if the property isn't already being verified or has been verified */
if (verificationWidgets->currentIndex() == 0) {
/* change the buttons */
verificationWidgets->setCurrentIndex(1);
editButton->setEnabled(false);
deleteButton->setEnabled(false);
/* start the verification process */
connect(processSystem, SIGNAL(processFinished(int)), this, SLOT(actionVerifyResult(int)));
verificationProcessId = processSystem->verifyProperty(property);
}
}
void PropertyWidget::actionVerifyResult(int processid)
{
/* check if the process that is finished is the verification process of this property */
if (processid == verificationProcessId) {
/* get the result and apply it to the widget */
QString result = processSystem->getResult(verificationProcessId);
if (result == "true") {
verificationWidgets->setCurrentIndex(2);
this->setStyleSheet("background-color:rgb(153,255,153)");
} else if (result == "false") {
verificationWidgets->setCurrentIndex(3);
this->setStyleSheet("background-color:rgb(255,153,153)");
} else {
verificationWidgets->setCurrentIndex(0);
}
editButton->setEnabled(true);
deleteButton->setEnabled(true);
}
}
void PropertyWidget::actionAbortVerification()
{
qDebug("abort");
}
void PropertyWidget::actionEdit()
{
AddEditPropertyDialog *editPropertyDialog = new AddEditPropertyDialog(false, parent, this, property->name, property->text);
/* if editing was succesful (Edit button was pressed), update the property and its widget */
if (editPropertyDialog->exec()) {
property->name = editPropertyDialog->getPropertyName();
property->text = editPropertyDialog->getPropertyText();
propertyNameLabel->setText(property->name);
fileSystem->setPropertyModified(property->name);
}
}
void PropertyWidget::actionDelete()
{
/* show a message box to ask the user whether he is sure to delete the property, only delete the property if the user agrees */
if (QMessageBox::question(this, "Delete Property", "Are you sure you want to delete the property " + property->name + "?", QMessageBox::Yes | QMessageBox::Cancel) == QMessageBox::Yes) {
parent->deleteProperty(this);
delete this;
}
}