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 <QStringList>
14#include <QVariant>
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 {
56 int index = m_fieldIndices[field];
57 if (index >= 0 && index < fields.size()) {
58 return QVariant(fields[index]).value<T>();
59 }
60
61 return defaultValue;
62 }
63
64 QString m_lineSeparator;
65
66 QChar m_fieldSeparator;
67
68 QMap<Field, int> m_fieldIndices;
69
71
72 Q_DISABLE_COPY(WaypointParser)
73};
74
75} // namespace Marble
76
77#endif // MARBLE_WAYPOINTPARSER_H
QList< QVariant > parse(const QString &message, const QDateTime &externalIssueDateTime=QDateTime())
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 Fri Dec 27 2024 11:51:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.