File indexing completed on 2024-12-08 07:19:11

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KPUBLICTRANSPORT_LOCATIONREQUEST_H
0008 #define KPUBLICTRANSPORT_LOCATIONREQUEST_H
0009 
0010 #include "kpublictransport_export.h"
0011 
0012 #include <KPublicTransport/Datatypes>
0013 #include <KPublicTransport/Location>
0014 
0015 #include <QMetaType>
0016 #include <QSharedDataPointer>
0017 
0018 class QJsonObject;
0019 
0020 namespace KPublicTransport {
0021 
0022 class LocationRequestPrivate;
0023 
0024 /** Describes a location search.
0025  *  Either a geo coordinate, a name or an address must be specified as search criteria.
0026  */
0027 class KPUBLICTRANSPORT_EXPORT LocationRequest
0028 {
0029     KPUBLICTRANSPORT_GADGET(LocationRequest)
0030     /** Location object containing the search parameters. */
0031     Q_PROPERTY(KPublicTransport::Location location READ location WRITE setLocation)
0032     // TODO deprecated those?
0033     Q_PROPERTY(float latitude READ latitude WRITE setLatitude STORED false)
0034     Q_PROPERTY(float longitude READ longitude WRITE setLongitude STORED false)
0035     Q_PROPERTY(QString name READ name WRITE setName STORED false)
0036     Q_PROPERTY(QStringList backends READ backendIds WRITE setBackendIds)
0037 
0038     /** When searching by coordinate, the expected maximum distance of the results in meters.
0039      *  @note This is only an optimization hint for backends, not a guarantee
0040      *  that all results comply with this constraint.
0041      */
0042     KPUBLICTRANSPORT_PROPERTY(int, maximumDistance, setMaximumDistance)
0043     /** The maximum amount of expected results.
0044      *  @note This is only an optimization hint for backends, not a guarantee
0045      *  that all results comply with this constraint.
0046      */
0047     KPUBLICTRANSPORT_PROPERTY(int, maximumResults, setMaximumResults)
0048     /** The type of locations you are interested in.
0049      *  @note This is only an optimization hint for backends, not a guarantee
0050      *  that all results comply with this constraint.
0051      */
0052     KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location::Types, types, setTypes)
0053 
0054 public:
0055     /** Create a LocationRequest from @p locaction.
0056      *  Whatever fields set in @p location will be used for the search request.
0057      */
0058     LocationRequest(const Location &locaction);
0059 
0060     /** Returns @c true if this is a valid request, that is it has enough parameters set to perform a query. */
0061     bool isValid() const;
0062 
0063     Location location() const;
0064     void setLocation(const Location &location);
0065 
0066     /** Latitude of the location to search. */
0067     float latitude() const;
0068     /** Sets the latitude of the location to search. */
0069     void setLatitude(float lat);
0070     /** Longitude of the location to search. */
0071     float longitude() const;
0072     /** Sets the longitude of the location to search. */
0073     void setLongitude(float lon);
0074     /** Search by geo coordinate. */
0075     void setCoordinate(float lat, float lon);
0076     /** Returns true if a valid geo coordinate has been set. */
0077     bool hasCoordinate() const;
0078 
0079     /** The name of the location to search. */
0080     QString name() const;
0081     /** Search by name or name fragment. */
0082     void setName(const QString &name);
0083     // TODO select full name or name fragment mode for auto-completion
0084 
0085     /** Unique string representation used for caching results. */
0086     QString cacheKey() const;
0087 
0088     /** Identifiers of the backends that should be queried.
0089      *  @see setBackendIds()
0090      */
0091     QStringList backendIds() const;
0092     /** Set identifiers of backends that should be queried.
0093      *  Settings this is only needed when you want explicit control over this, leaving
0094      *  this empty picks suitable backends automatically.
0095      */
0096     void setBackendIds(const QStringList &backendIds);
0097 
0098     ///@cond internal
0099     static QJsonObject toJson(const LocationRequest &req);
0100     ///@endcond
0101 };
0102 
0103 }
0104 
0105 Q_DECLARE_METATYPE(KPublicTransport::LocationRequest)
0106 
0107 #endif // KPUBLICTRANSPORT_LOCATIONREQUEST_H