MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / paintMap

Method paintMap

app/src/UI/Widgets/GPS.cpp:755–807  ·  view source on GitHub ↗

* @brief Renders the visible portion of the map using cached tiles. */

Source from the content-addressed store, hash-verified

753 * @brief Renders the visible portion of the map using cached tiles.
754 */
755void Widgets::GPS::paintMap(QPainter* painter, const QSize& view)
756{
757 if (!painter) {
758 qWarning() << "GPS::paintMap: null painter";
759 return;
760 }
761
762 painter->setRenderHint(QPainter::Antialiasing, false);
763 painter->setRenderHint(QPainter::SmoothPixmapTransform, true);
764 painter->fillRect(painter->viewport(), QColor(0x0C, 0x47, 0x5C));
765
766 const int baseZoom = qFloor(m_zoom);
767 const double fractionalZoom = m_zoom - baseZoom;
768 const double scale = qPow(2.0, fractionalZoom);
769 const int tileSize = 256;
770 const double scaledTileSize = tileSize * scale;
771
772 const QPointF centerTileBase = m_centerTile / scale;
773 const int centerX = static_cast<int>(centerTileBase.x());
774 const int centerY = static_cast<int>(centerTileBase.y());
775
776 const int offsetX = qRound((centerTileBase.x() - centerX) * scaledTileSize);
777 const int offsetY = qRound((centerTileBase.y() - centerY) * scaledTileSize);
778
779 const int tilesX = qCeil(view.width() / scaledTileSize) + 1;
780 const int tilesY = qCeil(view.height() / scaledTileSize) + 1;
781
782 for (int dx = -tilesX / 2; dx <= tilesX / 2; ++dx) {
783 for (int dy = -tilesY / 2; dy <= tilesY / 2; ++dy) {
784 const int tx = centerX + dx;
785 const int ty = centerY + dy;
786 const int wrappedTx = (tx % (1 << baseZoom) + (1 << baseZoom)) % (1 << baseZoom);
787
788 if (ty < 0 || ty >= (1 << baseZoom))
789 continue;
790
791 const QString url = tileUrl(wrappedTx, ty, baseZoom);
792 const int drawX = view.width() / 2 + qRound(dx * scaledTileSize) - offsetX;
793 const int drawY = view.height() / 2 + qRound(dy * scaledTileSize) - offsetY;
794 const QRect targetRect(drawX, drawY, qRound(scaledTileSize), qRound(scaledTileSize));
795
796 if (s_tileCache.contains(url))
797 painter->drawImage(targetRect, *s_tileCache.object(url));
798
799 else
800 renderFallbackTile(painter, tx, ty, baseZoom, targetRect, scaledTileSize);
801
802 renderCloudOverlay(painter, wrappedTx, ty, baseZoom, targetRect, scaledTileSize);
803 renderWeatherOverlay(painter, wrappedTx, ty, baseZoom, targetRect);
804 renderReferenceOverlay(painter, wrappedTx, ty, baseZoom, targetRect);
805 }
806 }
807}
808
809/**
810 * @brief Overlays the equirectangular cloud image onto the given tile rect.

Callers

nothing calls this directly

Calls 6

fillRectMethod · 0.80
xMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
drawImageMethod · 0.80
containsMethod · 0.45

Tested by

no test coverage detected