-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patheventmatrix.cpp
170 lines (143 loc) · 3.55 KB
/
eventmatrix.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
#include "eventmatrix.h"
EventTile::EventTile()
{
Events.clear();
}
void EventTile::toggleEvent(int eventNum)
{
if (Events.contains(eventNum))
Events.removeAll(eventNum);
else
Events.append(eventNum);
}
bool EventTile::isEmpty()
{
return Events.isEmpty();
}
int EventTile::getEventAt(int index)
{
return Events.at(index);
}
bool EventTile::contains(int eventNum)
{
return Events.contains(eventNum);
}
int EventTile::getCount()
{
return Events.count();
}
EventMatrix::EventMatrix(int SizeX, int SizeY)
{
Matrix.fill(QVector<EventTile* >().fill( NULL ,SizeX),SizeY);
}
EventMatrix::EventMatrix()
{
Matrix.fill(QVector<EventTile* >().fill( NULL ,50),50);
}
EventMatrix::~EventMatrix()
{
this->clear();
}
void EventMatrix::setMatrixSize(int x, int y)
{
Matrix.resize(x);
for (int i=0;i<x;i++)
Matrix[i].resize(y);
}
EventTile* EventMatrix::getNumsAt(int x, int y)
{
if (x >= Matrix.count())
return NULL;
if (y >= Matrix[0].count())
return NULL;
return Matrix.at(x).at(y);
}
#define MIN(X,Y) ((X)>(Y) ? (Y) : (X))
#define MAX(X,Y) ((X)>(Y) ? (X) : (Y))
void EventMatrix::toggleNumAt(int x, int y, int Num)
{
if ((x >= Matrix.count()) || (y >= Matrix[0].count()))
setMatrixSize(MAX(x+1, Matrix.count()), MAX(y+1, Matrix[0].count()));
if ( Matrix.at(x).at(y) == NULL)
{
EventTile *buf = new EventTile();
Matrix[x][y] = buf;
}
Matrix.at(x).at(y)->toggleEvent( Num );
if ( Matrix.at(x).at(y)->isEmpty() )
{
delete Matrix.at(x).at(y);
Matrix[x][y] = NULL;
}
}
void EventMatrix::toggleRectArea(QRect area, int EventNum)
{
if ((area.right() >= Matrix.count()) || (area.bottom() >= Matrix[0].count()))
setMatrixSize(MAX(area.right()+1, Matrix.count()), MAX(area.bottom()+1, Matrix[0].count())); //w celu optymalizacji dodane też tutaj
int ix,iy;
for (ix= area.left(); ix<area.right(); ix++)
for (iy= area.top(); iy<area.bottom(); iy++)
this->toggleNumAt(ix,iy,EventNum);
}
int EventMatrix::getSizeX()
{
return Matrix.count();
}
int EventMatrix::getSizeY()
{
return Matrix[0].count();
}
QString EventMatrix::getAllNamesAt(int x, int y)
{
QString sBuf = "";
for(int a=0;a<this->getNumsAt(x,y)->getCount();a++)
{
sBuf += this->getEvent(this->getNumsAt(x,y)->getEventAt(a))->Name;
if (a+1 < this->getNumsAt(x,y)->getCount())
sBuf += " ";
}
return sBuf;
}
void EventMatrix::createNewEvent(QString Name, QString Params)
{
Event *buf = new Event;
//buf->index = Events.count()-1;
buf->Name = Name;
buf->Params = Params;
Events.append( buf );
}
void EventMatrix::deleteEvent(int index)
{
int ix,iy;
for (ix= 0; ix<Matrix.count(); ix++)
for (iy= 0; iy<Matrix.at(ix).count(); iy++)
{
if ( Matrix.at(ix).at(iy) != NULL )
if (Matrix.at(ix).at(iy)->contains(index))
Matrix.at(ix).at(iy)->toggleEvent(index);
}
delete Events.at( index );
Events.remove( index );
}
Event *EventMatrix::getEvent(int index)
{
return Events.at(index);
}
int EventMatrix::getCount()
{
return Events.count();
}
void EventMatrix::clear()
{
int ix,iy;
for (ix= 0; ix<Matrix.count(); ix++)
for (iy= 0; iy<Matrix.at(ix).count(); iy++)
{
delete Matrix.at(ix).at(iy);
Matrix[ix].clear();
}
Matrix.clear();
qDeleteAll(Events);
Events.clear();
Matrix.fill(QVector<EventTile* >().fill( NULL ,50),50);
}