-
Notifications
You must be signed in to change notification settings - Fork 0
/
additemdialog.cpp
121 lines (112 loc) · 3.62 KB
/
additemdialog.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
#include "additemdialog.h"
#include "ui_additemdialog.h"
AddItemDialog::AddItemDialog(Interpreter& inter, std::map<std::string, cstruct> const& structs, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddItemDialog),
structs(structs),
inter(inter)
{
ui->setupUi(this);
layout()->setSizeConstraint(QLayout::SetFixedSize);
ui->userTypeGroupBox->hide();
ui->simpleTypeGroupBox->hide();
ui->pointerGroupBox->hide();
//ui->buttonBox->setEnabled(false);
}
AddItemDialog::~AddItemDialog()
{
delete ui;
qDebug("Closing dialog...");
}
void AddItemDialog::on_buttonBox_accepted()
{
//type_name = ui->typeComboBox->currentText();
// GraphicsWidget *item;
if(ui->typeComboBox->currentIndex() == 1) {
str = "int ";
str += ui->nameText->text();
if(ui->valueText->text().length()) {
str += " = " + ui->valueText->text();
}
str += ";";
}
else if(ui->typeComboBox->currentIndex() == 2) {
str = "struct " + ui->structTypeComboBox->currentText();
str += " " + ui->structNameText->text() + ";\n";
for(int i=0; i < ui->structMembersWidget->rowCount(); i++) {
str += ui->structNameText->text() + ".";
str += ui->structMembersWidget->item(i,0)->text();
str += " = " + ui->structMembersWidget->item(i,1)->text() + ";\n";
}
}
else if(ui->typeComboBox->currentIndex() == 3) {
str = ui->pointerTypeText->text() + " * ";
str += ui->pointerNameText->text();
if(ui->pointerValueText->text().length()) {
str += " = " + ui->pointerValueText->text();
}
str += ";";
}
else {
return;
}
if(inter.parse(str)) {
inter.execute();
dynamic_cast<MainWindow*>(parent())->updateAll();
this->close();
}
// else
// item = new Variable(typeName, ui->nameText->displayText(), ui->valueText->displayText());
// items->insert(item->name, item);
// scene->addItem(item);
}
void AddItemDialog::on_typeComboBox_activated(int index)
{
ui->userTypeGroupBox->hide();
ui->simpleTypeGroupBox->hide();
ui->pointerGroupBox->hide();
switch(index)
{
case 0://none
break;
case 1:
ui->simpleTypeGroupBox->setVisible(true);
break;
case 2:{
int i = 0;
for(auto const& sn : structs) {
ui->structTypeComboBox->insertItem(i, QString::fromStdString(sn.first));
++i;
}
ui->userTypeGroupBox->setVisible(true);
}
break;
case 3:
ui->pointerGroupBox->setVisible(true);
break;
default:
break;
}
}
void AddItemDialog::on_structTypeComboBox_activated(const QString &arg1)
{
std::string str = arg1.toStdString();
cstruct const* cs;
auto i = structs.find(str);
if(i != structs.end()) {
cs = &(i->second);
}
QStringList labels;
for(auto member : cs->member_specs) {
const int j = ui->structMembersWidget->rowCount();
ui->structMembersWidget->insertRow(ui->structMembersWidget->rowCount());
QTableWidgetItem* name = new QTableWidgetItem(QString::fromStdString(member.first));
name->setFlags(name->flags() &= ~Qt::ItemIsEditable);
ui->structMembersWidget->setItem(j, 0, name);
QTableWidgetItem* value;
value = new QTableWidgetItem(QString::number(0));
ui->structMembersWidget->setItem(j, 1, value);
labels << QString::fromStdString(member.second.type_str);
}
ui->structMembersWidget->setVerticalHeaderLabels(labels);
}