-
Notifications
You must be signed in to change notification settings - Fork 0
/
scenematrix.cpp
39 lines (34 loc) · 1.04 KB
/
scenematrix.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
#include "scenematrix.h"
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QDebug>
using namespace DG;
SceneMatrix::SceneMatrix(QGraphicsScene* scene): _scene(scene), _rows(0), _cols(0){
}
quint16 SceneMatrix::index(quint16 row, quint16 col) const{
return row*_cols+col;
}
void SceneMatrix::setGridDimension(quint16 rows, quint16 cols){
_rows = rows;
_cols = cols;
_list.reserve(sizeof(QGraphicsItem*)*_rows*_cols);
qDebug() << "SceneMatrix::setGridDimension" << _rows << _cols;
}
void SceneMatrix::addItem(quint16 row, quint16 col, QGraphicsItem* item){
if(row > _rows || col > _cols)
return;
quint16 _index = index(row, col);
_scene->addItem(item);
if(_list.count() > _index){
QGraphicsItem* _existing = _list.value(_index);
if(_existing){
qDebug() << "SceneMatrix::addItem" << _existing << _existing->isObscured();
//if(_existing->isObscured()){
_scene->removeItem(_existing);
delete _existing;
//}
}
}
qDebug() << "_list.count(): " << _list.count() << " index: " << _index << row << col;
_list[_index] = item;
}