PDA

View Full Version : Painting Pixels in QGraphicsView



cszawisza
12th April 2012, 09:46
Hi

I am making a scanner such as this
http://spritesmods.com/?art=mouseeye

from the device, everything is ready. But when i tray to print this on QGraphicsView I have a memory leak...



void MainWindow::parseFrame (QByteArray DATA){


bool frameOK = true;
QList <QByteArray> line = DATA.split('\n');

//DATA structure
//
//BO:
//DE: 2bits x movement, y movement
//SQ: 1bit Surface Quality
//MI: 1bit
//MA: 1bit
//FR: 324bits ( SOF | Data_Valid | PD5 | PD4 | PD3 | PD2 | PD1 | PD0 ) where PDx intensity of pixel in gray scale
//EO:


for (int w = 0 ; w < line.size() ; w++)
{
if ( line.at(w).startsWith("FR:") && frameOK ) //Jeżeli dane są ramką
{
QList <QByteArray> frame = line.at(w).split(':');

if ( (frame.at(1).size() < 324) || (frame.at(1).size()>324 ))
{
qDebug()<<"Frame damaged :"<<frame.at(1).size();
ramkaOK = false;
}//IF
else
{
scene->clear(); // !!!!!!!!
quint8 col;
quint16 pixelIndex;
for( pixelIndex = 0 ; pixelIndex < 18*18 ; ){
col = (quint8)(frame.at(1)[pixelIndex] << 2 );
color->setRgb(col,col,col);
brush->setColor(*color);
//That section works well
scene->addRect( ((quint8)(pixelIndex/18))*7, //X
(17 - (pixelIndex%18))*7, //Y
7,7,*pen,*brush );
//This section will leak memory, because I add data instead of overwriting
bigScene->addRect(((quint8)(pixelIndex/18))+X, //x + DELTA X
(17 - (pixelIndex%18))+Y, //y + DELTA Y
1,1,*pen,*brush );
}
} //ELSE Frame OK
}//FRAME
if ( line.at(w).startsWith("DE:") ) //DELTA
{
QList <QByteArray> delta = line.at(w).split(':');

dx = delta.at(1)[0];
dy = delta.at(1)[1];
if ( ((dx > -127) && ( dx < 128 )) &&
((dx > -127) && ( dx < 128 )) ){
X+=dx;
Y-=dy;
}
else
{
qDebug()<< "DX DY damaged" ;
frameOK = false;
}

} //IF DELTA

//ui->currentView is a QGraphicView
ui->currentView->setScene(scene);
// ui->bigView->setScene(bigScene); //This causes a memory leak
ui->sourceQuality->replot();
ui->minMaxVal->replot();

}


My question is, how can I draw the big picture?