File indexing completed on 2024-04-28 15:39:06

0001 // SPDX-FileCopyrightText: 2021 Tobias Leupold <tl at stonemx dot de>
0002 //
0003 // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 // Local includes
0006 #include "ImagesLayer.h"
0007 #include "ImagesModel.h"
0008 
0009 // Marble includes
0010 #include <marble/GeoPainter.h>
0011 #include <marble/ViewportParams.h>
0012 #include <marble/GeoDataLatLonAltBox.h>
0013 
0014 // Qt includes
0015 #include <QDebug>
0016 
0017 static QStringList s_renderPosition { QStringLiteral("HOVERS_ABOVE_SURFACE") };
0018 
0019 ImagesLayer::ImagesLayer(QObject *parent, ImagesModel *model)
0020     : QObject(parent),
0021       m_imagesModel(model)
0022 {
0023 }
0024 
0025 QStringList ImagesLayer::renderPosition() const
0026 {
0027     return s_renderPosition;
0028 }
0029 
0030 bool ImagesLayer::render(Marble::GeoPainter *painter, Marble::ViewportParams *viewport,
0031                          const QString &, Marble::GeoSceneLayer *)
0032 {
0033     const auto viewportCoordinates = viewport->viewLatLonAltBox();
0034 
0035     for (int row = 0; row < m_imagesModel->rowCount(); row++) {
0036         const auto index = m_imagesModel->index(row, 0);
0037         const auto coordinates = index.data(KGeoTag::CoordinatesRole).value<Coordinates>();
0038         if (! coordinates.isSet()) {
0039             continue;
0040         }
0041 
0042         const auto marbleCoordinates = Marble::GeoDataCoordinates(
0043             coordinates.lon(), coordinates.lat(), coordinates.alt(),
0044             Marble::GeoDataCoordinates::Degree);
0045 
0046         if (! viewportCoordinates.contains(marbleCoordinates)) {
0047             continue;
0048         }
0049 
0050         painter->drawPixmap(marbleCoordinates, index.data(KGeoTag::ThumbnailRole).value<QPixmap>());
0051     }
0052 
0053     return true;
0054 }