83 if (
model == _model) {
86 qCDebug(GeoMapSpriteLayerLog) <<
"model" << (
model ?
"set" :
"cleared");
88 disconnect(_model,
nullptr,
this,
nullptr);
92 connect(_model, &QAbstractItemModel::rowsInserted,
this, &GeoMapSpriteLayer::_markPointsDirty);
93 connect(_model, &QAbstractItemModel::rowsRemoved,
this, &GeoMapSpriteLayer::_markPointsDirty);
94 connect(_model, &QAbstractItemModel::modelReset,
this, &GeoMapSpriteLayer::_markPointsDirty);
95 connect(_model, &QAbstractItemModel::dataChanged,
this, &GeoMapSpriteLayer::_markPointsDirty);
96 connect(_model, &QAbstractItemModel::layoutChanged,
this, &GeoMapSpriteLayer::_markPointsDirty);
97 connect(_model, &QObject::destroyed,
this, [
this] {
223 auto* node =
static_cast<QSGGeometryNode*
>(oldNode);
225 QSGTexture* texture =
nullptr;
227 if (_sprite->isTextureProvider()) {
228 texture = _sprite->textureProvider()->texture();
232 if (
auto*
const dynamicTexture = qobject_cast<QSGDynamicTexture*>(texture)) {
233 dynamicTexture->updateTexture();
237 QMetaObject::invokeMethod(
this, qOverload<>(&QQuickItem::update), Qt::QueuedConnection);
239 }
else if (!_warnedNotProvider) {
241 qCWarning(GeoMapSpriteLayerLog) <<
"sprite item is not a texture provider";
242 _warnedNotProvider =
true;
247 _rebuildPointCache();
250 GeoMapCamera*
const camera = _scene ? _scene->camera() :
nullptr;
251 if (!texture || !camera || _points.empty()) {
256 const double zScale = _scene->verticalScale() * _scene->terrainScale();
257 std::vector<QPointF> screenPositions;
258 screenPositions.reserve(_points.size());
259 for (
const CachedPoint& point : _points) {
260 const auto screen = camera->
worldToScreen(point.world, point.terrainAlt * zScale);
262 screenPositions.push_back(*screen);
265 if (screenPositions.empty()) {
270 QSGGeometry* geometry =
nullptr;
272 node =
new QSGGeometryNode;
273 geometry =
new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 0);
274 geometry->setDrawingMode(QSGGeometry::DrawTriangles);
275 node->setGeometry(geometry);
276 node->setFlag(QSGNode::OwnsGeometry);
277 auto*
const material =
new QSGTextureMaterial;
278 material->setFiltering(QSGTexture::Linear);
279 node->setMaterial(material);
280 node->setFlag(QSGNode::OwnsMaterial);
282 geometry = node->geometry();
285 auto*
const material =
static_cast<QSGTextureMaterial*
>(node->material());
286 if (material->texture() != texture) {
287 material->setTexture(texture);
288 node->markDirty(QSGNode::DirtyMaterial);
291 const QRectF uv = texture->normalizedTextureSubRect();
292 const float u0 =
static_cast<float>(uv.left());
293 const float v0 =
static_cast<float>(uv.top());
294 const float u1 =
static_cast<float>(uv.right());
295 const float v1 =
static_cast<float>(uv.bottom());
296 const float half =
static_cast<float>(_spriteSize / 2.0);
298 geometry->allocate(
static_cast<int>(screenPositions.size()) * 6);
299 QSGGeometry::TexturedPoint2D* vertex = geometry->vertexDataAsTexturedPoint2D();
300 for (
const QPointF& position : screenPositions) {
301 const float cx =
static_cast<float>(position.x());
302 const float cy =
static_cast<float>(position.y());
303 vertex[0].set(cx - half, cy - half, u0, v0);
304 vertex[1].set(cx + half, cy - half, u1, v0);
305 vertex[2].set(cx - half, cy + half, u0, v1);
306 vertex[3].set(cx + half, cy - half, u1, v0);
307 vertex[4].set(cx + half, cy + half, u1, v1);
308 vertex[5].set(cx - half, cy + half, u0, v1);
311 node->markDirty(QSGNode::DirtyGeometry);