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 "GeoSceneTypes.h"
9#include "GeoWriter.h"
10#include "GeoSceneTileDataset.h"
11#include "DownloadPolicy.h"
12#include "DgmlElementDictionary.h"
13#include "ServerLayout.h"
14
15#include <QUrl>
16
17namespace Marble
18{
19
20static GeoTagWriterRegistrar s_writerTexture( GeoTagWriter::QualifiedName( GeoSceneTypes::GeoSceneTileDatasetType, dgml::dgmlTag_nameSpace20 ),
21 new DgmlTextureTagWriter() );
22
23bool DgmlTextureTagWriter::write(const GeoNode *node, GeoWriter& writer) const
24{
25 const GeoSceneTileDataset *texture = static_cast<const GeoSceneTileDataset*>( node );
26 writer.writeStartElement( dgml::dgmlTag_Texture );
27 writer.writeAttribute( "name", texture->name() );
28 writer.writeAttribute( "expire", QString::number( texture->expire() ) );
29
30 writer.writeStartElement( dgml::dgmlTag_SourceDir );
31 writer.writeAttribute( "format", texture->fileFormat() );
32 if( texture->expire() ) {
33 writer.writeAttribute( "expire", QString::number( texture->expire() ) );
34 }
35 writer.writeCharacters( texture->sourceDir() );
36 writer.writeEndElement();
37 writer.writeStartElement( dgml::dgmlTag_TileSize );
38 writer.writeAttribute( "width", QString::number( texture->tileSize().width() ) );
39 writer.writeAttribute( "height", QString::number( texture->tileSize().height() ) );
40 writer.writeEndElement();
41
42 writer.writeOptionalElement( dgml::dgmlTag_InstallMap, texture->installMap() );
43
44 writer.writeStartElement( dgml::dgmlTag_StorageLayout );
45 if( texture->hasMaximumTileLevel() )
46 {
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().size() > 0 )
55 {
56 for( int i = 0; i < texture->downloadUrls().size(); ++i )
57 {
58 QString protocol = texture->downloadUrls().at(i).toString().left(texture->downloadUrls().at(i).toString().indexOf(QLatin1Char(':')));
59 QString host = QString( texture->downloadUrls().at(i).host() );
60 int port = texture->downloadUrls().at(i).port();
61 QString path = QString( texture->downloadUrls().at(i).path() );
62 QString query = texture->downloadUrls().at(i).query(QUrl::FullyEncoded);
63
64 writer.writeStartElement( dgml::dgmlTag_DownloadUrl );
65 writer.writeAttribute( "protocol", protocol );
66 writer.writeAttribute( "host", host );
67 if( port != -1 )
68 {
69 writer.writeAttribute( "port", QString::number( port ) );
70 }
71 writer.writeAttribute( "path", path );
72 writer.writeAttribute( "query", query );
73 writer.writeEndElement();
74 }
75 }
76
77 for( const DownloadPolicy *policy: texture->downloadPolicies() )
78 {
79 writer.writeStartElement( dgml::dgmlTag_DownloadPolicy );
80
81 if( policy->key().usage() == DownloadBrowse )
82 {
83 writer.writeAttribute( "usage", "Browse" );
84 writer.writeAttribute( "maximumConnections", QString::number( policy->maximumConnections() ) );
85 }
86
87 else if( policy->key().usage() == DownloadBulk )
88 {
89 writer.writeAttribute( "usage", "Bulk" );
90 writer.writeAttribute( "maximumConnections", QString::number( policy->maximumConnections() ) );
91 }
92
93 writer.writeEndElement();
94 }
95
96 writer.writeStartElement( dgml::dgmlTag_Projection );
97 const GeoSceneAbstractTileProjection::Type tileProjectionType = texture->tileProjectionType();
98 if (tileProjectionType == GeoSceneAbstractTileProjection::Mercator) {
99 writer.writeAttribute( "name", "Mercator" );
100 } else if (tileProjectionType == GeoSceneAbstractTileProjection::Equirectangular) {
101 writer.writeAttribute( "name", "Equirectangular" );
102 }
103 writer.writeEndElement();
104
105 writer.writeStartElement( dgml::dgmlTag_Blending );
106 if (!texture->blending().isEmpty()) {
107 writer.writeAttribute( "name", texture->blending() );
108 }
109 writer.writeEndElement();
110
111 writer.writeEndElement();
112 return true;
113}
114
115}
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 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 Fri Jun 21 2024 12:00:07 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.