Commit 07ac5da0 authored by Volker Krause's avatar Volker Krause
Browse files

Remove boilerplate code in StopoverRequest

parent 8fad9e46
......@@ -6,6 +6,7 @@
#include "stopoverrequest.h"
#include "requestcontext_p.h"
#include "datatypes/datatypes_p.h"
#include "datatypes/json_p.h"
#include "datatypes/locationutil_p.h"
......@@ -30,10 +31,10 @@ public:
};
}
StopoverRequest::StopoverRequest()
: d(new StopoverRequestPrivate)
{
}
KPUBLICTRANSPORT_MAKE_GADGET(StopoverRequest)
KPUBLICTRANSPORT_MAKE_PROPERTY(StopoverRequest, Location, stop, setStop)
KPUBLICTRANSPORT_MAKE_PROPERTY(StopoverRequest, StopoverRequest::Mode, mode, setMode)
KPUBLICTRANSPORT_MAKE_PROPERTY(StopoverRequest, bool, downloadAssets, setDownloadAssets)
StopoverRequest::StopoverRequest(const Location &stop)
: d(new StopoverRequestPrivate)
......@@ -41,27 +42,11 @@ StopoverRequest::StopoverRequest(const Location &stop)
d->stop = stop;
}
StopoverRequest::StopoverRequest(StopoverRequest&&) noexcept = default;
StopoverRequest::StopoverRequest(const StopoverRequest&) = default;
StopoverRequest::~StopoverRequest() = default;
StopoverRequest& StopoverRequest::operator=(const StopoverRequest&) = default;
bool StopoverRequest::isValid() const
{
return !d->stop.isEmpty();
}
Location StopoverRequest::stop() const
{
return d->stop;
}
void StopoverRequest::setStop(const Location &stop)
{
d.detach();
d->stop = stop;
}
QDateTime StopoverRequest::dateTime() const
{
if (!d->dateTime.isValid()) {
......@@ -76,17 +61,6 @@ void StopoverRequest::setDateTime(const QDateTime &dt)
d->dateTime = dt;
}
StopoverRequest::Mode StopoverRequest::mode() const
{
return d->mode;
}
void StopoverRequest::setMode(StopoverRequest::Mode mode)
{
d.detach();
d->mode = mode;
}
RequestContext StopoverRequest::context(const AbstractBackend *backend) const
{
const auto it = std::lower_bound(d->contexts.begin(), d->contexts.end(), backend);
......@@ -138,17 +112,6 @@ void StopoverRequest::setBackendIds(const QStringList &backendIds)
d->backendIds = backendIds;
}
bool StopoverRequest::downloadAssets() const
{
return d->downloadAssets;
}
void StopoverRequest::setDownloadAssets(bool downloadAssets)
{
d.detach();
d->downloadAssets = downloadAssets;
}
QString StopoverRequest::cacheKey() const
{
return QString::number(d->dateTime.toSecsSinceEpoch() / DepartureCacheTimeResolution) + QLatin1Char('_')
......
......@@ -9,6 +9,8 @@
#include "kpublictransport_export.h"
#include <KPublicTransport/Datatypes>
#include <QMetaType>
#include <QSharedDataPointer>
......@@ -28,35 +30,16 @@ class StopoverRequestPrivate;
*/
class KPUBLICTRANSPORT_EXPORT StopoverRequest
{
Q_GADGET
Q_PROPERTY(KPublicTransport::Location stop READ stop WRITE setStop)
Q_PROPERTY(QDateTime dateTime READ dateTime WRITE setDateTime)
Q_PROPERTY(Mode mode READ mode WRITE setMode)
Q_PROPERTY(QStringList backends READ backendIds WRITE setBackendIds)
Q_PROPERTY(bool downloadAssets READ downloadAssets WRITE setDownloadAssets)
public:
StopoverRequest();
/** Search for arrival/departures to/from @p stop. */
explicit StopoverRequest(const Location &stop);
StopoverRequest(StopoverRequest&&) noexcept;
StopoverRequest(const StopoverRequest&);
~StopoverRequest();
StopoverRequest& operator=(const StopoverRequest&);
KPUBLICTRANSPORT_GADGET(StopoverRequest)
/** Returns @c true if this is a valid request, ie. this is complete enough to perform a query. */
bool isValid() const;
/** The location at which to look for departures. */
Location stop() const;
/** Sets the location at which to look for departures/arrivals. */
void setStop(const Location &stop);
/** Date/time at which the search should start. */
QDateTime dateTime() const;
/** Set the starting time for the search. */
void setDateTime(const QDateTime &dt);
/** The location at which to search for departures/arrivals. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, stop, setStop)
/** Date/time at which the search should start.
* Default: now
*/
KPUBLICTRANSPORT_PROPERTY(QDateTime, dateTime, setDateTime)
public:
/** Query departures or arrivals? */
enum Mode {
QueryArrival, ///< Search for arrivals.
......@@ -64,10 +47,24 @@ public:
};
Q_ENUM(Mode)
/** Returns whether to search for arrivals or departures. */
Mode mode() const;
/** Set whether to search for arrivals or departures. */
void setMode(Mode mode);
/** Controls whether to search for arrivals or departures.
* Default is QueryDeparture.
*/
KPUBLICTRANSPORT_PROPERTY(Mode, mode, setMode)
Q_PROPERTY(QStringList backends READ backendIds WRITE setBackendIds)
/** Enable downloading of graphic assets such as line logos for the data requested here.
* Default: @c false
*/
KPUBLICTRANSPORT_PROPERTY(bool, downloadAssets, setDownloadAssets)
public:
/** Search for arrival/departures to/from @p stop. */
explicit StopoverRequest(const Location &stop);
/** Returns @c true if this is a valid request, ie. this is complete enough to perform a query. */
bool isValid() const;
/** Identifiers of the backends that should be queried.
* @see setBackendIds()
......@@ -79,13 +76,6 @@ public:
*/
void setBackendIds(const QStringList &backendIds);
/** Download graphic assets such as line logos for the data requested here. */
bool downloadAssets() const;
/** Enable downloading of graphic assets.
* Default: @c false
*/
void setDownloadAssets(bool downloadAssets);
/** Unique string representation used for caching results. */
QString cacheKey() const;
......@@ -101,8 +91,6 @@ private:
Q_DECL_HIDDEN const std::vector<RequestContext>& contexts() const;
Q_DECL_HIDDEN void setContext(const AbstractBackend *backend, RequestContext &&context);
Q_DECL_HIDDEN void purgeLoops(const StopoverRequest &baseRequest);
QExplicitlySharedDataPointer<StopoverRequestPrivate> d;
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment