MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / updateTemplateCache

Method updateTemplateCache

src/gui/map/map_widget.cpp:1305–1346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1303}
1304
1305void MapWidget::updateTemplateCache(QImage& cache, QRect& dirty_rect, int first_template, int last_template, bool use_background)
1306{
1307 Q_ASSERT(containsVisibleTemplate(first_template, last_template));
1308
1309 if (cache.isNull())
1310 {
1311 // Lazy allocation of cache image
1312 cache = QImage(size(), QImage::Format_ARGB32_Premultiplied);
1313 dirty_rect = rect();
1314 }
1315 else
1316 {
1317 // Make sure not to use a bigger draw rect than necessary
1318 dirty_rect = dirty_rect.intersected(rect());
1319 }
1320
1321 // Start drawing
1322 QPainter painter(&cache);
1323 painter.setClipRect(dirty_rect);
1324
1325 // Fill with background color (TODO: make configurable)
1326 if (use_background)
1327 painter.fillRect(dirty_rect, Qt::white);
1328 else
1329 {
1330 QPainter::CompositionMode mode = painter.compositionMode();
1331 painter.setCompositionMode(QPainter::CompositionMode_Clear);
1332 painter.fillRect(dirty_rect, Qt::transparent);
1333 painter.setCompositionMode(mode);
1334 }
1335
1336 // Draw templates
1337 painter.translate(width() / 2.0, height() / 2.0);
1338 painter.setWorldTransform(view->worldTransform(), true);
1339
1340 Map* map = view->getMap();
1341 QRectF map_view_rect = view->calculateViewedRect(viewportToView(dirty_rect));
1342
1343 map->drawTemplates(&painter, map_view_rect, first_template, last_template, view, true);
1344
1345 dirty_rect.setWidth(-1); // => !dirty_rect.isValid()
1346}
1347
1348void MapWidget::updateMapCache(bool use_background)
1349{

Callers

nothing calls this directly

Calls 5

calculateViewedRectMethod · 0.80
drawTemplatesMethod · 0.80
QImageClass · 0.50
translateMethod · 0.45
getMapMethod · 0.45

Tested by

no test coverage detected