File indexing completed on 2024-04-21 04:41:38

0001 /*
0002     SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "exampleutil.h"
0008 
0009 #include <QQmlApplicationEngine>
0010 #include <QQmlContext>
0011 
0012 #include <QApplication>
0013 #include <QDateTime>
0014 #include <QIdentityProxyModel>
0015 #include <QLocale>
0016 
0017 using namespace KPublicTransport;
0018 
0019 class JourneyQueryProxyModel : public QIdentityProxyModel
0020 {
0021     Q_OBJECT
0022 public:
0023     JourneyQueryProxyModel(QObject *parent = nullptr) : QIdentityProxyModel(parent) {}
0024     QVariant data(const QModelIndex &index, int role) const override
0025     {
0026         if (role == Qt::DisplayRole) {
0027             const auto j = index.data(JourneyQueryModel::JourneyRole).value<Journey>();
0028             return QString(QLocale().toString(j.scheduledDepartureTime(), QLocale::ShortFormat) + QLatin1String(" (") +
0029                 QString::number(j.duration()/60) + QLatin1String("min) - ") + QString::number(j.numberOfChanges()) + QLatin1String(" change(s)"));
0030         }
0031         return QIdentityProxyModel::data(index, role);
0032     }
0033 };
0034 
0035 int main(int argc, char **argv)
0036 {
0037     QCoreApplication::setApplicationName(QStringLiteral("journeyquery"));
0038     QCoreApplication::setOrganizationName(QStringLiteral("KDE"));
0039     QCoreApplication::setOrganizationDomain(QStringLiteral("kde.org"));
0040 
0041     QApplication app(argc, argv);
0042 
0043     qmlRegisterType<JourneyQueryProxyModel>("org.kde.example", 1, 0, "JourneyTitleModel");
0044     qmlRegisterSingletonType<ExampleUtil>("org.kde.example", 1, 0, "ExampleUtil", [](QQmlEngine*, QJSEngine*) -> QObject*{
0045         return new ExampleUtil;
0046     });
0047 
0048     QQmlApplicationEngine engine;
0049     engine.load(QStringLiteral("qrc:/journeyquery.qml"));
0050     return app.exec();
0051 }
0052 
0053 #include "journeyquery.moc"
0054 #include "moc_exampleutil.cpp"