1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Moved all the map bounds checking where it belongs

This commit is contained in:
Martin Tůma 2017-12-03 10:41:07 +01:00
parent 179f2f1451
commit 5bdc263cda
3 changed files with 14 additions and 20 deletions

View File

@ -738,11 +738,14 @@ void MapView::setBackgroundColor(const QColor &color)
void MapView::drawBackground(QPainter *painter, const QRectF &rect)
{
if (_showMap) {
if (_opacity < 1.0) {
QRectF ir = rect.intersected(_map->bounds());
if (_opacity < 1.0 || ir != rect)
painter->fillRect(rect, _backgroundColor);
if (_opacity < 1.0)
painter->setOpacity(_opacity);
}
_map->draw(painter, rect);
_map->draw(painter, ir);
} else
painter->fillRect(rect, _backgroundColor);
}

View File

@ -610,17 +610,12 @@ void OfflineMap::drawImage(QPainter *painter, const QRectF &rect)
void OfflineMap::draw(QPainter *painter, const QRectF &rect)
{
QRectF ir = rect.intersected(bounds());
if (ir != rect)
painter->fillRect(rect, _backgroundColor);
if (_ozf.isOpen())
drawOZF(painter, ir);
drawOZF(painter, rect);
else if (_tileSize.isValid())
drawTiled(painter, ir);
drawTiled(painter, rect);
else
drawImage(painter, ir);
drawImage(painter, rect);
}
QPointF OfflineMap::ll2xy(const Coordinates &c)

View File

@ -228,18 +228,14 @@ qreal OnlineMap::zoomOut()
void OnlineMap::draw(QPainter *painter, const QRectF &rect)
{
qreal scale = zoom2scale(_zoom);
QRectF ir = rect.intersected(bounds());
if (ir != rect)
painter->fillRect(rect, _backgroundColor);
QPoint tile = mercator2tile(QPointF(ir.topLeft().x() * scale,
-ir.topLeft().y() * scale), _zoom);
QPoint tl = QPoint((int)floor(ir.left() / (qreal)TILE_SIZE)
* TILE_SIZE, (int)floor(ir.top() / TILE_SIZE) * TILE_SIZE);
QPoint tile = mercator2tile(QPointF(rect.topLeft().x() * scale,
-rect.topLeft().y() * scale), _zoom);
QPoint tl = QPoint((int)floor(rect.left() / (qreal)TILE_SIZE)
* TILE_SIZE, (int)floor(rect.top() / TILE_SIZE) * TILE_SIZE);
QList<Tile> tiles;
QSizeF s(ir.right() - tl.x(), ir.bottom() - tl.y());
QSizeF s(rect.right() - tl.x(), rect.bottom() - tl.y());
for (int i = 0; i < ceil(s.width() / TILE_SIZE); i++)
for (int j = 0; j < ceil(s.height() / TILE_SIZE); j++)
tiles.append(Tile(QPoint(tile.x() + i, tile.y() + j), _zoom));