Commit 3b093276 authored by Nicolas Fella's avatar Nicolas Fella

Use JourneyQueryModel directly from QML

parent 2876f5ed
......@@ -18,6 +18,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "androidutils.h"
#include "locationquerymodel.h"
#include "querycontroller.h"
#include <QQmlApplicationEngine>
#include <QQmlContext>
......@@ -27,16 +31,9 @@
#include <QApplication>
#endif
#include "locationquerymodel.h"
#include "querycontroller.h"
#include <KPublicTransport/JourneyQueryModel>
#include <KPublicTransport/Manager>
#include <KLocalizedContext>
#include "androidutils.h"
#ifdef Q_OS_ANDROID
Q_DECL_EXPORT
#endif
......@@ -53,11 +50,13 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
qmlRegisterType<LocationQueryModel>("org.kde.ktrip", 0, 1, "LocationQueryModel");
qmlRegisterType<KPublicTransport::JourneyQueryModel>("org.kde.ktrip", 0, 1, "JourneyQueryModel");
QueryController queryController;
engine.rootContext()->setContextProperty(QStringLiteral("_queryController"), &queryController);
KPublicTransport::Manager manager;
engine.rootContext()->setContextProperty(QStringLiteral("_manager"), &manager);
#ifdef Q_OS_ANDROID
engine.rootContext()->setContextProperty(QStringLiteral("_isAndroid"), true);
engine.rootContext()->setContextProperty(QStringLiteral("_androidUtils"), QVariant::fromValue(AndroidUtils::instance()));
......
......@@ -23,6 +23,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Controls 2.4
import org.kde.kirigami 2.4 as Kirigami
import org.kde.ktrip 0.1
import org.kde.kpublictransport 1.0 as KPT
Kirigami.Page
{
......@@ -32,7 +33,10 @@ Kirigami.Page
anchors.fill: parent
model: _queryController.journeyModel
model: KPT.JourneyQueryModel {
request: _queryController.createJourneyRequest()
manager: _manager
}
delegate: Kirigami.AbstractListItem {
......
......@@ -30,8 +30,6 @@ QueryController::QueryController(QObject* parent)
: QObject(parent)
, m_start()
, m_destination()
, m_journeyModel(new KPublicTransport::JourneyQueryModel)
, m_manager()
, m_locationCacheFile(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + QStringLiteral("/locations.cache"))
, m_cachedLocationsJson()
{
......@@ -42,8 +40,6 @@ QueryController::QueryController(QObject* parent)
m_departureDate = QDate::currentDate().toString(Qt::ISODate);
m_departureTime = QTime::currentTime().toString(Qt::ISODate);
m_journeyModel->setManager(&m_manager);
loadLocationsFromCache();
}
......@@ -69,19 +65,8 @@ KPublicTransport::Location QueryController::destination() const
return m_destination;
}
KPublicTransport::JourneyQueryModel * QueryController::journeyModel()
{
createJourneyRequest();
return m_journeyModel;
}
void QueryController::createJourneyRequest()
KPublicTransport::JourneyRequest QueryController::createJourneyRequest()
{
if (m_start.isEmpty() || m_destination.isEmpty()) {
return;
}
KPublicTransport::JourneyRequest req;
req.setFrom(m_start);
req.setTo(m_destination);
......@@ -90,7 +75,7 @@ void QueryController::createJourneyRequest()
req.setDepartureTime(depTime);
qDebug() << depTime << m_departureDate + QStringLiteral("T") + m_departureTime;
m_journeyModel->setRequest(req);
return req;
}
QString QueryController::departureDate() const
......
......@@ -26,15 +26,12 @@
#include <KPublicTransport/Location>
#include <KPublicTransport/JourneyRequest>
#include <KPublicTransport/JourneyQueryModel>
#include <KPublicTransport/Manager>
class QueryController : public QObject {
Q_OBJECT
Q_PROPERTY(KPublicTransport::Location start READ start WRITE setStart NOTIFY startChanged)
Q_PROPERTY(KPublicTransport::Location destination READ destination WRITE setDestination NOTIFY destinationChanged)
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)
......@@ -48,8 +45,6 @@ public:
KPublicTransport::Location destination() const;
void setDestination(const KPublicTransport::Location destination);
KPublicTransport::JourneyQueryModel * journeyModel();
QString departureDate() const;
void setDepartureDate(const QString& date);
......@@ -60,6 +55,7 @@ public:
void setCachedLocations(const QVariantList& locations);
Q_INVOKABLE void addCachedLocation(const KPublicTransport::Location location);
Q_INVOKABLE KPublicTransport::JourneyRequest createJourneyRequest();
Q_SIGNALS:
void startChanged();
......@@ -68,16 +64,11 @@ Q_SIGNALS:
void departureTimeChanged();
void cachedLocationsChanged();
private Q_SLOTS:
void createJourneyRequest();
private:
void loadLocationsFromCache();
KPublicTransport::Location m_start;
KPublicTransport::Location m_destination;
KPublicTransport::JourneyQueryModel *m_journeyModel;
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