-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand.cpp
192 lines (168 loc) · 3.4 KB
/
command.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "command.h"
/*********
*Command*
*********/
Command::Command(Command *tutor) :
QObject(tutor)
{
m_tutor = tutor;
m_id = Command::Event;
}
Command::ID Command::id() const
{
return m_id;
}
void Command::setId(ID f_id)
{
m_id = f_id;
}
QString Command::desc() const
{
//This method will be replaced by subclases, i'll just make a test right now:
QString result;
switch (id()){
case NewCommand:
result = "Add New Command";
break;
case ShowDialog:
result = "Show Dialog: Dialog Name";
break;
case MultipleChoice:
result = "Multiple Choices";
break;
case ImputNumber:
result = "Imput Number : IVar[#]";
break;
case If:
result = "If a >= b";
break;
case Else:
result = "else";
break;
case SetLabel:
result = "Label: Name";
break;
case GoToLabel:
result = "Go to label: Name";
break;
case Loop:
result = "For (IVar[#] = X; IVar == Y; IVar++";
break;
case Break:
result = "Break;";
break;
case Continue:
result = "Continue";
break;
default:
result = "UnusedEvent";
break;
}
return result;
}
Command* Command::tutor() const
{
if (m_tutor != 0)
return m_tutor;
else if (m_previous != 0)
return m_previous->tutor(); //Recursion!
return 0;
}
void Command::setTutor(Command *f_tutor)
{
m_tutor = f_tutor;
}
QRect Command::rect() const
{
return m_rect;
}
QRect Command::elseRect() const
{
if (m_child == 0)
return QRect();
Command *c = child();
for(;;)
{
if (c->id() == Command::Else)
{
return c->rect();
}
if (c->next() != 0)
c = c->next();
else
break;
}
return QRect();
}
void Command::setRect(const QRect &rect)
{
m_rect = rect;
}
Command* Command::child() const
{
return m_child;
}
void Command::setChild(Command *f_child)
{
m_child = f_child;
if (m_child != 0)
m_child->m_tutor = this;
}
Command *Command::next(bool chk_child) const
{
if (chk_child && m_child != 0)
return m_child;
else if (m_next != 0)
return m_next;
else if (tutor() != 0)
return tutor()->next(false);
return 0;
}
void Command::setNext(Command *f_next)
{
m_next = f_next;
if (f_next != 0)
f_next->m_previous = this;
}
void Command::insertBack(Command* f_command)
{
if (f_command == 0)
return;
if (m_previous != 0)
{
m_previous->m_next = f_command;
f_command->m_previous = m_previous;
}
f_command->m_next = this;
m_previous = f_command;
}
Command* Command::previous() const
{
return m_previous;
}
void Command::setPrevious(Command *f_previous)
{
m_previous = f_previous;
}
int Command::count(bool count_children)
{
int result = 1;
Command *c = next(count_children);
while(c != 0 && c->nesting() >= nesting())
{
c = c->next(count_children);
result++;
}
return result;
}
int Command::nesting() const
{
int result = 0;
Command * p = tutor();
while (p != 0)
{
result +=1;
p = p->tutor();
}
return result;
}