-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattribute.cpp
More file actions
107 lines (89 loc) · 2.26 KB
/
Copy pathattribute.cpp
File metadata and controls
107 lines (89 loc) · 2.26 KB
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
#include "attribute.h"
#include "QDebug"
Attribute::Attribute(type typeInput, std::string nameInput) : QObject(nullptr)
{
attributeType = typeInput;
name = nameInput;
field = nullptr;
data = "";
switch(attributeType)
{
case COLOR:
colorData = new QColor;
break;
default:
case STRING:
colorData = nullptr;
break;
}
}
Attribute::~Attribute()
{
}
std::string Attribute::GetName()
{
return name;
}
Attribute::type Attribute::GetType()
{
return attributeType;
}
std::string Attribute::GetText()
{
return data;
}
QColor Attribute::GetColor()
{
if(attributeType == COLOR)
return *colorData;
else return Qt::white;
}
void Attribute::setData(std::string input)
{
data = input;
if(attributeType == COLOR)
{
colorData->setNamedColor(QString::fromStdString(data));
}
}
void Attribute::setData(QColor colorInput)
{
if(attributeType == COLOR)
*colorData = colorInput;
}
void Attribute::editedAttribute()
{
data = field->text().toUtf8().constData();
if(attributeType == COLOR)
{
colorData->setNamedColor(QString::fromStdString(data));
}
if(name.compare("name") == 0 || name.compare("color") == 0)
{
VisualDataUpdated();
}
}
void Attribute::Display(QDialog *parent, QBoxLayout* layout, std::vector<std::string> fieldValues)
{
//Make the name label
QLabel* nameLab = new QLabel(parent);
nameLab->setText(QString::fromStdString(name));
//Get the field value for the VisualEditor in a line editor
QLineEdit* newField = new QLineEdit(parent);
std::string value;
if(attributeType == STRING)
value = GetText();
else if(attributeType == COLOR)
value = colorData->name().toUtf8().constData();
newField->setText(QString::fromStdString(value));
//connect line edit with change
field = newField;
QObject::connect(field, SIGNAL(editingFinished()),this, SLOT(editedAttribute()));
//Group name label and line edit together
QHBoxLayout* newGroup = new QHBoxLayout;
newGroup->addWidget(nameLab);
newGroup->addWidget(field);
//Add to the new dialog window
layout->addItem(newGroup);
fieldValues.push_back(value);
}