Marble

DgmlTextureTagWriter.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2011 Utku Aydın <utkuaydin34@gmail.com>
4//
5
6#include "DgmlTextureTagWriter.h"
7
8#include "DgmlElementDictionary.h"
9#include "DownloadPolicy.h"
10#include "GeoSceneTileDataset.h"
11#include "GeoSceneTypes.h"
12#include "GeoWriter.h"
13#include "ServerLayout.h"
14
15#include <QUrl>
16
17namespace Marble
18{
19
20static GeoTagWriterRegistrar s_writerTexture(GeoTagWriter::QualifiedName(QString::fromLatin1(GeoSceneTypes::GeoSceneTileDatasetType),
21 QString::fromLatin1(dgml::dgmlTag_nameSpace20)),
22 new DgmlTextureTagWriter());
23
24bool DgmlTextureTagWriter::write(const GeoNode *node, GeoWriter &writer) const
25{
26 const auto texture = static_cast<const GeoSceneTileDataset *>(node);
27 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_Texture));
28 writer.writeAttribute(QStringLiteral("name"), texture->name());
29 writer.writeAttribute("expire", QString::number(texture->expire()));
30
31 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_SourceDir));
32 writer.writeAttribute(QStringLiteral("format"), texture->fileFormat());
33 if (texture->expire()) {
34 writer.writeAttribute("expire", QString::number(texture->expire()));
35 }
36 writer.writeCharacters(texture->sourceDir());
37 writer.writeEndElement();
38 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_TileSize));
39 writer.writeAttribute("width", QString::number(texture->tileSize().width()));
40 writer.writeAttribute("height", QString::number(texture->tileSize().height()));
41 writer.writeEndElement();
42
43 writer.writeOptionalElement(QString::fromLatin1(dgml::dgmlTag_InstallMap), texture->installMap());
44
45 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_StorageLayout));
46 if (texture->hasMaximumTileLevel()) {
47 writer.writeAttribute("maximumTileLevel", QString::number(texture->maximumTileLevel()));
48 writer.writeAttribute("levelZeroColumns", QString::number(texture->levelZeroColumns()));
49 writer.writeAttribute("levelZeroRows", QString::number(texture->levelZeroRows()));
50 writer.writeAttribute("mode", texture->serverLayout()->name());
51 }
52 writer.writeEndElement();
53
54 if (!texture->downloadUrls().isEmpty()) {
55 for (int i = 0; i < texture->downloadUrls().size(); ++i) {
56 QString protocol = texture->downloadUrls().at(i).toString().left(texture->downloadUrls().at(i).toString().indexOf(QLatin1Char(':')));
57 QString host = QString(texture->downloadUrls().at(i).host());
58 int port = texture->downloadUrls().at(i).port();
59 QString path = QString(texture->downloadUrls().at(i).path());
60 QString query = texture->downloadUrls().at(i).query(QUrl::FullyEncoded);
61
62 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_DownloadUrl));
63 writer.writeAttribute("protocol", protocol);
64 writer.writeAttribute("host", host);
65 if (port != -1) {
66 writer.writeAttribute("port", QString::number(port));
67 }
68 writer.writeAttribute("path", path);
69 writer.writeAttribute("query", query);
70 writer.writeEndElement();
71 }
72 }
73
74 for (const DownloadPolicy *policy : texture->downloadPolicies()) {
75 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_DownloadPolicy));
76
77 if (policy->key().usage() == DownloadBrowse) {
78 writer.writeAttribute("usage", "Browse");
79 writer.writeAttribute("maximumConnections", QString::number(policy->maximumConnections()));
80 }
81
82 else if (policy->key().usage() == DownloadBulk) {
83 writer.writeAttribute("usage", "Bulk");
84 writer.writeAttribute("maximumConnections", QString::number(policy->maximumConnections()));
85 }
86
87 writer.writeEndElement();
88 }
89
90 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_Projection));
91 const GeoSceneAbstractTileProjection::Type tileProjectionType = texture->tileProjectionType();
92 if (tileProjectionType == GeoSceneAbstractTileProjection::Mercator) {
93 writer.writeAttribute(QStringLiteral("name"), "Mercator");
94 } else if (tileProjectionType == GeoSceneAbstractTileProjection::Equirectangular) {
95 writer.writeAttribute(QStringLiteral("name"), "Equirectangular");
96 }
97 writer.writeEndElement();
98
99 writer.writeStartElement(QString::fromUtf8(dgml::dgmlTag_Blending));
100 if (!texture->blending().isEmpty()) {
101 writer.writeAttribute(QStringLiteral("name"), texture->blending());
102 }
103 writer.writeEndElement();
104
105 writer.writeEndElement();
106 return true;
107}
108
109}
QPair< QString, QString > QualifiedName
Object Name and Namespace Pair This type is intended to be used in a similar way to.
KSERVICE_EXPORT KService::List query(FilterFunc filterFunc)
QString path(const QString &relativePath)
Binds a QML item to a specific geodetic location in screen coordinates.
@ DownloadBrowse
Browsing mode, normal operation of Marble, like a web browser.
@ DownloadBulk
Bulk download, for example "File/Download region".
const_reference at(qsizetype i) const const
const QChar at(qsizetype position) const const
QString fromLatin1(QByteArrayView str)
QString fromUtf8(QByteArrayView str)
QString number(double n, char format, int precision)
FullyEncoded
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:37:03 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.