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
16namespace Marble
17{
18namespace dgml
19{
20static GeoTagHandlerRegistrar handler(GeoParser::QualifiedName(QString::fromLatin1(dgmlTag_DownloadPolicy), QString::fromLatin1(dgmlTag_nameSpace20)),
21 new DgmlDownloadPolicyTagHandler);
22
23// Error handling:
24// Here it is not possible to return an error code or throw an exception
25// so in case of an error we just ignore the element.
26
27GeoNode *DgmlDownloadPolicyTagHandler::parse(GeoParser &parser) const
28{
29 // Check whether the tag is valid
30 Q_ASSERT(parser.isStartElement() && parser.isValidElement(QLatin1StringView(dgmlTag_DownloadPolicy)));
31
32 // Checking for parent item
33 GeoStackItem parentItem = parser.parentElement();
34 if (!parentItem.represents(dgmlTag_Texture) && !parentItem.represents(dgmlTag_Vectortile)) {
35 qCritical("Parse error: parent element is not 'texture' or 'vectortile'");
36 return nullptr;
37 }
38
39 // Attribute usage
40 DownloadUsage usage;
41 const QString usageStr = parser.attribute(dgmlAttr_usage).trimmed();
42 if (usageStr == QLatin1StringView("Browse"))
43 usage = DownloadBrowse;
44 else if (usageStr == QLatin1StringView("Bulk"))
45 usage = DownloadBulk;
46 else {
47 qCritical("Parse error: invalid attribute downloadPolicy/@usage");
48 return nullptr;
49 }
50
51 // Attribute maximumConnections
52 const QString maximumConnectionsStr = parser.attribute(dgmlAttr_maximumConnections).trimmed();
53 bool ok;
54 const int maximumConnections = maximumConnectionsStr.toInt(&ok);
55 if (!ok) {
56 qCritical("Parse error: invalid attribute downloadPolicy/@maximumConnections");
57 return nullptr;
58 }
59
60 parentItem.nodeAs<GeoSceneTileDataset>()->addDownloadPolicy(usage, maximumConnections);
61 return nullptr;
62}
63
64}
65}
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".
QString fromLatin1(QByteArrayView str)
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 Sat Dec 21 2024 17:04:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.