Marble

WaypointParser.h
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2010 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#ifndef MARBLE_WAYPOINTPARSER_H
7#define MARBLE_WAYPOINTPARSER_H
8
9#include "RoutingWaypoint.h"
10#include "marble_export.h"
11
12#include <QMap>
13#include <QVariant>
14#include <QStringList>
15
16class QTextStream;
17
18namespace Marble
19{
20
21class MARBLE_EXPORT WaypointParser
22{
23public:
24 /** Fields which can be parsed */
25 enum Field {
26 Longitude,
27 Latitude,
28 JunctionType,
29 RoadName,
30 TotalSecondsRemaining,
31 RoadType
32 };
33
34 /** Constructor */
35 WaypointParser();
36
37 /** Parses the given stream and returns the extracted waypoint list */
38 RoutingWaypoints parse( QTextStream &stream ) const;
39
40 /** Associate the zero-based field no index with the given semantic type */
41 void setFieldIndex( Field field, int index );
42
43 /** The line separator used in the stream passed to #parse. Default is "\n" */
44 void setLineSeparator( const QString &separator );
45
46 /** The field separator. Default is ',' */
47 void setFieldSeparator( const QChar &separator );
48
49 /** Associate the given string key with the given junction type */
50 void addJunctionTypeMapping( const QString &key, RoutingWaypoint::JunctionType value );
51
52private:
53 template<class T>
54 T readField( Field field, const QStringList &fields, const T &defaultValue = T() ) const {
55 int index = m_fieldIndices[field];
56 if ( index >= 0 && index < fields.size() ) {
57 return QVariant( fields[index] ).value<T>();
58 }
59
60 return defaultValue;
61 }
62
63 QString m_lineSeparator;
64
65 QChar m_fieldSeparator;
66
67 QMap<Field, int> m_fieldIndices;
68
70
71 Q_DISABLE_COPY( WaypointParser )
72};
73
74} // namespace Marble
75
76#endif // MARBLE_WAYPOINTPARSER_H
KHEALTHCERTIFICATE_EXPORT QVariant parse(const QByteArray &data)
Binds a QML item to a specific geodetic location in screen coordinates.
qsizetype size() const const
T value() 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.