{
QPointF bottomRight
= mapToScene
(viewport
()->width
(),viewport
()->height
());
QPointF size
= bottomRight
-topLeft;
qreal scaley = viewport()->height()/size.y();
int zoom = qBound(0, (int)floor(log2(scaley)), 20); // upsampling
//int zoom = qBound(0, (int)ceil(log2(scaley)), 20); // downsampling
int scaleFactor = 1<<zoom;
double factorX = qreal(0x100000>>zoom)/(0x1000);
int xbegin = qBound(0, (int)floor(rect.left ()* scaleFactor/SceneSize), scaleFactor);
int xend = qBound(0, (int)ceil (rect.right ()* scaleFactor/SceneSize), scaleFactor);
int ybegin = qBound(0, (int)floor(rect.top ()* scaleFactor/SceneSize), scaleFactor);
int yend = qBound(0, (int)ceil (rect.bottom()* scaleFactor/SceneSize), scaleFactor);
for(int y=ybegin; y<yend; y++)
{
for(int x=xbegin; x<xend; x++)
{
QImage pixmap
= downloader
->requestMap
(zoom, x, y
);
painter
->drawImage
(QRectF( qreal
(x
*SceneSize
)/scaleFactor, qreal
(y
*SceneSize
)/scaleFactor, factorX, factorX
), pixmap, pixmap.
rect());
}
}
}
void MapView::drawBackground(QPainter* painter, const QRectF & rect)
{
QPointF topLeft = mapToScene(0,0);
QPointF bottomRight = mapToScene(viewport()->width(),viewport()->height());
QPointF size = bottomRight-topLeft;
qreal scaley = viewport()->height()/size.y();
int zoom = qBound(0, (int)floor(log2(scaley)), 20); // upsampling
//int zoom = qBound(0, (int)ceil(log2(scaley)), 20); // downsampling
int scaleFactor = 1<<zoom;
double factorX = qreal(0x100000>>zoom)/(0x1000);
int xbegin = qBound(0, (int)floor(rect.left ()* scaleFactor/SceneSize), scaleFactor);
int xend = qBound(0, (int)ceil (rect.right ()* scaleFactor/SceneSize), scaleFactor);
int ybegin = qBound(0, (int)floor(rect.top ()* scaleFactor/SceneSize), scaleFactor);
int yend = qBound(0, (int)ceil (rect.bottom()* scaleFactor/SceneSize), scaleFactor);
for(int y=ybegin; y<yend; y++)
{
for(int x=xbegin; x<xend; x++)
{
QImage pixmap = downloader->requestMap(zoom, x, y);
painter->drawImage(QRectF( qreal(x*SceneSize)/scaleFactor, qreal(y*SceneSize)/scaleFactor, factorX, factorX), pixmap, pixmap.rect());
}
}
}
To copy to clipboard, switch view to plain text mode
Sorry about the lack of comments, but you should get the idea.
Bookmarks