3
World::World(QObject *parent) :
9
void World::save(QIODevice *device)
11
//Presuming that the device is open
14
qDebug()<<"Device is not open";
17
QDataStream ds(device);
18
QList<QVariant> layers;
19
foreach(Layer *layer, myLayers.values()){
20
QMap<QString, QVariant> data;
21
data.insert("y", layer->y());
22
QVariant matrix = layer->variantMatrix();
23
data.insert("matrix", matrix);
29
void World::load(QIODevice *device)
31
if(!device->isOpen()){
32
qDebug()<<"Device is not open";
35
QDataStream ds(device);
39
QList<QVariant> layers=data.toList();
40
foreach(QVariant layer, layers){
41
QMap<QString, QVariant> layerData=layer.toMap();
42
int y=layerData["y"].toInt();
49
QVariant matrix=layerData["matrix"];
50
l->setVariantMatrix(matrix);
54
Layer * World::addLayer(bool onTop)
59
getMinMaxLayer(min, max);
65
myLayers.insert(layer, l);
68
l->setActiveLayer(true);
71
qDebug()<<"adding Layer"<<layer;
72
emit(layerCountChanged(myLayers.count()));
73
emit(activeLayerChanged(layer));
77
void World::getMinMaxLayer(int &min, int &max)
80
foreach(int key, myLayers.keys()){
90
void World::setActiveLayer(int layer)
93
getMinMaxLayer(min, max);
94
foreach(Layer *l, myLayers.values()){
96
l->setActiveLayer(false);
98
if(layer>=min && layer <=max){
100
for(int i=layer+1;i<=max;i++){
101
myLayers.value(i)->setVisible(false);
103
myLayers.value(layer)->setActiveLayer(true);
106
qDebug()<<"This layer does not exist:"<<layer<<". Should also never happen :(";
110
Block * World::addBlock(QPoint pos, int y, BlockType type)
113
getMinMaxLayer(min, max);
115
Layer *l=myLayers.value(y);
116
return l->addBlock(pos, type);
118
qDebug()<<"This layer does not exist:"<<y<<". Should also never happen :(";
123
QRect World::boundaries()
128
void World::addPointToBoundaries(QPoint pos)
131
path.addRect(myBoundaries);
132
path.addRect(QRect(pos-QPoint(1,1), pos+QPoint(1,1)));
133
myBoundaries=path.boundingRect().toRect();
134
foreach(Layer *l, myLayers.values()){
141
QGraphicsScene::clear();
143
myBoundaries=QRect(-1,-1,2,2);