File indexing completed on 2024-04-21 03:56:42

0001 /*
0002  * This file is part of KQuickCharts
0003  * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006  */
0007 
0008 #include <QApplication>
0009 #include <QCommandLineParser>
0010 #include <QDebug>
0011 #include <QQmlApplicationEngine>
0012 #include <QQmlContext>
0013 #include <QSurfaceFormat>
0014 
0015 int main(int argc, char **argv)
0016 {
0017     QApplication app(argc, argv);
0018 
0019     QCommandLineParser parser;
0020     parser.addOption({QStringLiteral("page"), QStringLiteral("The page to show."), QStringLiteral("page")});
0021     parser.addOption({QStringLiteral("api"),
0022                       QStringLiteral("The graphics API to use. Can be one of 'default', 'core45', 'compat45', 'compat21' or 'es'."),
0023                       QStringLiteral("api"),
0024                       QStringLiteral("default")});
0025     parser.addHelpOption();
0026     parser.process(app);
0027 
0028     QSurfaceFormat format;
0029     auto api = parser.value(QStringLiteral("api"));
0030     if (api == QStringLiteral("core45")) {
0031         format.setProfile(QSurfaceFormat::CoreProfile);
0032         format.setVersion(4, 5);
0033     } else if (api == QStringLiteral("compat45")) {
0034         format.setProfile(QSurfaceFormat::CompatibilityProfile);
0035         format.setVersion(4, 5);
0036     } else if (api == QStringLiteral("es")) {
0037         format.setRenderableType(QSurfaceFormat::OpenGLES);
0038     } else if (api == QStringLiteral("default") || api == QStringLiteral("compat20")) {
0039         format.setVersion(2, 1);
0040     } else {
0041         qWarning() << "Unknown API option" << api << "\n";
0042         parser.showHelp(1);
0043     }
0044     QSurfaceFormat::setDefaultFormat(format);
0045 
0046     QQmlApplicationEngine engine;
0047 
0048     if (parser.isSet(QStringLiteral("page"))) {
0049         engine.rootContext()->setContextProperty(QStringLiteral("__commandLinePage"), parser.value(QStringLiteral("page")));
0050     } else {
0051         engine.rootContext()->setContextProperty(QStringLiteral("__commandLinePage"), nullptr);
0052     }
0053 
0054     engine.load(QStringLiteral("qrc:/main.qml"));
0055 
0056     return app.exec();
0057 }