Marble

DgmlDownloadPolicyTagHandler.cpp
1 /*
2  SPDX-FileCopyrightText: 2009, 2010 Jens-Michael Hoffmann <[email protected]>
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 
17 namespace Marble
18 {
19 namespace dgml
20 {
21 static 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 
29 GeoNode* 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 }
@ DownloadBrowse
Browsing mode, normal operation of Marble, like a web browser.
Definition: MarbleGlobal.h:155
DownloadUsage
This enum is used to describe the type of download.
Definition: MarbleGlobal.h:153
QString trimmed() const const
int toInt(bool *ok, int base) const const
Binds a QML item to a specific geodetic location in screen coordinates.
@ DownloadBulk
Bulk download, for example "File/Download region".
Definition: MarbleGlobal.h:154
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Oct 2 2023 03:52:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.