KPublicTransport

locationrequest.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_LOCATIONREQUEST_H
8#define KPUBLICTRANSPORT_LOCATIONREQUEST_H
9
10#include "kpublictransport_export.h"
11
12#include <KPublicTransport/Datatypes>
13#include <KPublicTransport/Location>
14
15#include <QMetaType>
16#include <QSharedDataPointer>
17
18class QJsonObject;
19
20namespace KPublicTransport {
21
22class LocationRequestPrivate;
23
24/** Describes a location search.
25 * Either a geo coordinate, a name or an address must be specified as search criteria.
26 */
27class KPUBLICTRANSPORT_EXPORT LocationRequest
28{
29 KPUBLICTRANSPORT_GADGET(LocationRequest)
30 /** Location object containing the search parameters. */
31 Q_PROPERTY(KPublicTransport::Location location READ location WRITE setLocation)
32 // TODO deprecated those?
33 Q_PROPERTY(double latitude READ latitude WRITE setLatitude STORED false)
34 Q_PROPERTY(double longitude READ longitude WRITE setLongitude STORED false)
35 Q_PROPERTY(QString name READ name WRITE setName STORED false)
36 Q_PROPERTY(QStringList backends READ backendIds WRITE setBackendIds)
37
38 /** When searching by coordinate, the expected maximum distance of the results in meters.
39 * @note This is only an optimization hint for backends, not a guarantee
40 * that all results comply with this constraint.
41 */
42 KPUBLICTRANSPORT_PROPERTY(int, maximumDistance, setMaximumDistance)
43 /** The maximum amount of expected results.
44 * @note This is only an optimization hint for backends, not a guarantee
45 * that all results comply with this constraint.
46 */
47 KPUBLICTRANSPORT_PROPERTY(int, maximumResults, setMaximumResults)
48 /** The type of locations you are interested in.
49 * @note This is only an optimization hint for backends, not a guarantee
50 * that all results comply with this constraint.
51 */
52 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location::Types, types, setTypes)
53
54public:
55 /** Create a LocationRequest from @p locaction.
56 * Whatever fields set in @p location will be used for the search request.
57 */
58 LocationRequest(const Location &locaction);
59
60 /** Returns @c true if this is a valid request, that is it has enough parameters set to perform a query. */
61 bool isValid() const;
62
63 Location location() const;
64 void setLocation(const Location &location);
65
66 /** Latitude of the location to search. */
67 [[nodiscard]] double latitude() const;
68 /** Sets the latitude of the location to search. */
69 void setLatitude(double lat);
70 /** Longitude of the location to search. */
71 [[nodiscard]] double longitude() const;
72 /** Sets the longitude of the location to search. */
73 void setLongitude(double lon);
74 /** Search by geo coordinate. */
75 void setCoordinate(double lat, double lon);
76 /** Returns true if a valid geo coordinate has been set. */
77 bool hasCoordinate() const;
78
79 /** The name of the location to search. */
80 QString name() const;
81 /** Search by name or name fragment. */
82 void setName(const QString &name);
83 // TODO select full name or name fragment mode for auto-completion
84
85 /** Unique string representation used for caching results. */
86 QString cacheKey() const;
87
88 /** Identifiers of the backends that should be queried.
89 * @see setBackendIds()
90 */
91 QStringList backendIds() const;
92 /** Set identifiers of backends that should be queried.
93 * Settings this is only needed when you want explicit control over this, leaving
94 * this empty picks suitable backends automatically.
95 */
96 void setBackendIds(const QStringList &backendIds);
97
98 ///@cond internal
99 static QJsonObject toJson(const LocationRequest &req);
100 ///@endcond
101};
102
103}
104
105Q_DECLARE_METATYPE(KPublicTransport::LocationRequest)
106
107#endif // KPUBLICTRANSPORT_LOCATIONREQUEST_H
Describes a location search.
Query operations and data types for accessing realtime public transport information from online servi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.