-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpropertiesdock.cpp
82 lines (71 loc) · 2.41 KB
/
propertiesdock.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
#include "propertiesdock.h"
#include <QMainWindow>
#include <QLabel>
PropertiesDock::PropertiesDock(ProcessSystem *processSystem, FileSystem *fileSystem, QWidget *parent) : QDockWidget("Properties", parent)
{
this->processSystem = processSystem;
this->fileSystem = fileSystem;
/* create the properties layout */
propertiesLayout = new QVBoxLayout();
propertiesLayout->setAlignment(Qt::AlignTop);
setToNoProperties();
innerDockWidget = new QWidget();
innerDockWidget->setLayout(propertiesLayout);
this->setWidget(innerDockWidget);
}
void PropertiesDock::setToNoProperties()
{
/* empty the layout (is usually already empty) */
QLayoutItem *item;
while ((item = propertiesLayout->takeAt(0))) {
propertiesLayout->removeWidget(item->widget());
delete item->widget();
}
/* show a QLabel that tells the user that no properties have been defined */
QLabel *noPropertiesLabel = new QLabel("No properties have been defined");
propertiesLayout->addWidget(noPropertiesLabel);
propertyWidgets.clear();
}
void PropertiesDock::addProperty(Property *property)
{
if (propertyWidgets.empty()) {
/* remove the QLabel */
QWidget *label = propertiesLayout->takeAt(0)->widget();
propertiesLayout->removeWidget(label);
delete label;
propertiesLayout->addStretch(1);
}
/* add the property to the rest */
PropertyWidget *propertyWidget = new PropertyWidget(property, processSystem, fileSystem, this);
propertiesLayout->insertWidget(propertiesLayout->count() - 1, propertyWidget);
propertyWidgets.push_back(propertyWidget);
}
void PropertiesDock::deleteProperty(PropertyWidget *propertyWidget)
{
propertiesLayout->removeWidget(propertyWidget);
if (propertiesLayout->isEmpty()) {
this->setToNoProperties();
}
propertyWidgets.remove(propertyWidget);
}
bool PropertiesDock::propertyNameExists(QString propertyName)
{
for (PropertyWidget *propertyWidget : propertyWidgets) {
if (propertyWidget->getProperty()->name == propertyName) {
return true;
}
}
return false;
}
void PropertiesDock::saveAllProperties()
{
for (PropertyWidget *propertyWidget : propertyWidgets) {
propertyWidget->saveProperty();
}
}
void PropertiesDock::verifyAllProperties()
{
for (PropertyWidget *propertyWidget : propertyWidgets) {
propertyWidget->actionVerify();
}
}