Commit 14ed57c8 authored by Nicolas Fella's avatar Nicolas Fella

Cache location queries

parent f38859e4
......@@ -7,6 +7,7 @@ import org.kde.ktrip 0.1
Kirigami.Page
{
property string type
property bool showCached: true
title: {
if (type == "start") {
......@@ -21,19 +22,48 @@ Kirigami.Page
header: TextField {
id: queryTextField
placeholderText: "Search..."
onAccepted: queryModel.query = text
onAccepted: {
queryModel.query = text
showCached = false
}
}
ListView {
anchors.fill: parent
model: LocationQueryModel {
id: queryModel
visible: showCached
model: _queryController.cachedLocations
delegate: Kirigami.BasicListItem {
text: modelData.name
reserveSpaceForIcon: false
onClicked: {
_queryController.addCachedLocation(modelData)
if (type == "start") {
_queryController.start = modelData
} else if (type == "destination") {
_queryController.destination = modelData
}
pageStack.pop()
}
}
}
LocationQueryModel {
id: queryModel
}
ListView {
anchors.fill: parent
visible: !showCached
model: queryModel
delegate: Kirigami.BasicListItem {
text: name
reserveSpaceForIcon: false
onClicked: {
_queryController.addCachedLocation(object)
if (type == "start") {
_queryController.start = object
} else if (type == "destination") {
......@@ -43,6 +73,7 @@ Kirigami.Page
}
}
}
}
......
......@@ -91,3 +91,24 @@ void QueryController::setDepartureTime(const QString& time)
Q_EMIT departureTimeChanged();
}
}
QVariantList QueryController::cachedLocations() const
{
return m_cachedLocations;
}
void QueryController::setCachedLocations(const QVariantList& locations)
{
if (locations != m_cachedLocations) {
m_cachedLocations = locations;
Q_EMIT cachedLocationsChanged();
}
}
void QueryController::addCachedLocation(const KPublicTransport::Location location)
{
if (!m_cachedLocations.contains(QVariant::fromValue(location))) {
m_cachedLocations.append(QVariant::fromValue(location));
}
}
......@@ -15,6 +15,7 @@ class QueryController : public QObject {
Q_PROPERTY(KPublicTransport::JourneyQueryModel* journeyModel READ journeyModel CONSTANT)
Q_PROPERTY(QString departureDate READ departureDate WRITE setDepartureDate NOTIFY departureDateChanged)
Q_PROPERTY(QString departureTime READ departureTime WRITE setDepartureTime NOTIFY departureTimeChanged)
Q_PROPERTY(QVariantList cachedLocations READ cachedLocations WRITE setCachedLocations NOTIFY cachedLocationsChanged)
public:
explicit QueryController(QObject *parent=nullptr);
......@@ -33,11 +34,17 @@ public:
QString departureTime() const;
void setDepartureTime(const QString& time);
QVariantList cachedLocations() const;
void setCachedLocations(const QVariantList& locations);
Q_INVOKABLE void addCachedLocation(const KPublicTransport::Location location);
Q_SIGNALS:
void startChanged();
void destinationChanged();
void departureDateChanged();
void departureTimeChanged();
void cachedLocationsChanged();
private Q_SLOTS:
void createJourneyRequest();
......@@ -49,4 +56,5 @@ private:
KPublicTransport::Manager m_manager;
QString m_departureDate;
QString m_departureTime;
QVariantList m_cachedLocations;
};
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