#include "tile.h"
{
}
Tile::~Tile()
{
}
{
this->image = NULL;
this->future = new QFuture<void>;
this->watcher = new QFutureWatcher<void>;
connect(watcher,SIGNAL(finished()),this,SLOT(updateSceneSlot()));
}
QRectF Tile
::boundingRect() const {
if(image == NULL)
return(QRectF(image
->rect
()));
}
void Tile::updateSceneSlot()
{
qDebug
("updateSceneSlot Thread id %i",
QThread::currentThread());
this->paint(TilePainter, TileOption, TileWidget);
}
{
if(image==NULL)
{
qDebug("Image is null");
TilePainter=painter;
TileOption=option;
TileWidget=widget;
qDebug
()<<
"Paint Thread id "<<
QThread::currentThread();
*future=QtConcurrent::run(this, &Tile::LoadTilePixmap);
watcher->setFuture(*future);
}else
{
qDebug("Image is not null");
painter->drawImage(*p, *image);
}
}
void Tile::LoadTilePixmap()
{
qDebug("Loading Pixmap");
/*...go out to disk here, and populate floatData...*/
for (int i = 0 ; i < nYSize ; i++)
{
for (int j = 0 ; j < nXSize ; j++)
{
image->setPixel(j,i,qRgb((unsigned char)floatData[i*nXSize+j],(unsigned char)floatData[i*nXSize+j],(unsigned char)floatData[i*nXSize+j]));
}
}
qDebug("Image complete loading");
if(image != NULL)
qDebug("Image not null");
}
#include "tile.h"
Tile::Tile(QGraphicsItem *parent) : QGraphicsItem(parent)
{
}
Tile::~Tile()
{
}
Tile::Tile(QGraphicsItem *parent)
: QGraphicsItem(parent)
{
this->image = NULL;
this->future = new QFuture<void>;
this->watcher = new QFutureWatcher<void>;
connect(watcher,SIGNAL(finished()),this,SLOT(updateSceneSlot()));
}
QRectF Tile::boundingRect() const
{
if(image == NULL)
return(QRectF(0,0,0,0));
return(QRectF(image->rect()));
}
void Tile::updateSceneSlot()
{
qDebug("updateSceneSlot Thread id %i", QThread::currentThread());
this->paint(TilePainter, TileOption, TileWidget);
}
void Tile::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget)
{
if(image==NULL)
{
qDebug("Image is null");
TilePainter=painter;
TileOption=option;
TileWidget=widget;
qDebug()<<"Paint Thread id "<< QThread::currentThread();
*future=QtConcurrent::run(this, &Tile::LoadTilePixmap);
watcher->setFuture(*future);
}else
{
qDebug("Image is not null");
QPointF *p = new QPointF(0.0,0.0);
painter->drawImage(*p, *image);
}
}
void Tile::LoadTilePixmap()
{
qDebug("Loading Pixmap");
/*...go out to disk here, and populate floatData...*/
image = new QImage(nXSize, nYSize, QImage::Format_RGB32);
for (int i = 0 ; i < nYSize ; i++)
{
for (int j = 0 ; j < nXSize ; j++)
{
image->setPixel(j,i,qRgb((unsigned char)floatData[i*nXSize+j],(unsigned char)floatData[i*nXSize+j],(unsigned char)floatData[i*nXSize+j]));
}
}
qDebug("Image complete loading");
if(image != NULL)
qDebug("Image not null");
}
To copy to clipboard, switch view to plain text mode
Here is the header file:
#ifndef TILE_H
#define TILE_H
#include <QGraphicsItem>
#include <QThread>
#include <QFutureWatcher>
#include <QtConcurrentRun>
#include "gdal_priv.h"
#include <QPainter>
{
Q_OBJECT
public:
~Tile();
void LoadTilePixmap();
protected:
private:
QFutureWatcher<void> *watcher;
QFuture<void> *future;
signals:
public slots:
void updateSceneSlot();
};
#endif // TILE_H
#ifndef TILE_H
#define TILE_H
#include <QGraphicsItem>
#include <QThread>
#include <QFutureWatcher>
#include <QtConcurrentRun>
#include "gdal_priv.h"
#include <QPainter>
class Tile : public QObject, public QGraphicsItem
{
Q_OBJECT
Q_INTERFACES(QGraphicsItem)
public:
Tile(QGraphicsItem *parent = 0);
~Tile();
void LoadTilePixmap();
protected:
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
QRectF boundingRect() const;
private:
QFutureWatcher<void> *watcher;
QFuture<void> *future;
QImage *image;
const QStyleOptionGraphicsItem *TileOption;
QPainter *TilePainter;
QWidget *TileWidget;
signals:
public slots:
void updateSceneSlot();
};
#endif // TILE_H
To copy to clipboard, switch view to plain text mode
Bookmarks