Marble

DgmlDownloadPolicyTagHandler.cpp
1/*
2 SPDX-FileCopyrightText: 2009, 2010 Jens-Michael Hoffmann <jmho@c-xx.com>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "DgmlDownloadPolicyTagHandler.h"
8
9#include "DgmlAttributeDictionary.h"
10#include "DgmlElementDictionary.h"
11#include "GeoParser.h"
12#include "GeoSceneTileDataset.h"
13
14#include "MarbleGlobal.h"
15#include "MarbleDebug.h"
16
17namespace Marble
18{
19namespace dgml
20{
21static GeoTagHandlerRegistrar handler( GeoParser::QualifiedName( dgmlTag_DownloadPolicy,
22 dgmlTag_nameSpace20 ),
23 new DgmlDownloadPolicyTagHandler );
24
25// Error handling:
26// Here it is not possible to return an error code or throw an exception
27// so in case of an error we just ignore the element.
28
29GeoNode* DgmlDownloadPolicyTagHandler::parse( GeoParser& parser ) const
30{
31 // Check whether the tag is valid
32 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1String(dgmlTag_DownloadPolicy)));
33
34 // Checking for parent item
35 GeoStackItem parentItem = parser.parentElement();
36 if ( !parentItem.represents( dgmlTag_Texture ) && !parentItem.represents( dgmlTag_Vectortile ) ) {
37 qCritical( "Parse error: parent element is not 'texture' or 'vectortile'" );
38 return nullptr;
39 }
40
41 // Attribute usage
42 DownloadUsage usage;
43 const QString usageStr = parser.attribute( dgmlAttr_usage ).trimmed();
44 if (usageStr == QLatin1String("Browse"))
45 usage = DownloadBrowse;
46 else if (usageStr == QLatin1String("Bulk"))
47 usage = DownloadBulk;
48 else {
49 qCritical( "Parse error: invalid attribute downloadPolicy/@usage" );
50 return nullptr;
51 }
52
53 // Attribute maximumConnections
54 const QString maximumConnectionsStr = parser.attribute( dgmlAttr_maximumConnections ).trimmed();
55 bool ok;
56 const int maximumConnections = maximumConnectionsStr.toInt( &ok );
57 if ( !ok ) {
58 qCritical( "Parse error: invalid attribute downloadPolicy/@maximumConnections" );
59 return nullptr;
60 }
61
62 parentItem.nodeAs<GeoSceneTileDataset>()->addDownloadPolicy( usage, maximumConnections );
63 return nullptr;
64}
65
66}
67}
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".
int toInt(bool *ok, int base) const const
QString trimmed() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:18:17 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.