File: main.cpp

package info (click to toggle)
kquickcharts 5.116.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 880 kB
  • sloc: cpp: 6,146; sh: 48; makefile: 11
file content (57 lines) | stat: -rw-r--r-- 2,040 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * This file is part of KQuickCharts
 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QSurfaceFormat>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QCommandLineParser parser;
    parser.addOption({QStringLiteral("page"), QStringLiteral("The page to show."), QStringLiteral("page")});
    parser.addOption({QStringLiteral("api"),
                      QStringLiteral("The graphics API to use. Can be one of 'default', 'core45', 'compat45', 'compat21' or 'es'."),
                      QStringLiteral("api"),
                      QStringLiteral("default")});
    parser.addHelpOption();
    parser.process(app);

    QSurfaceFormat format;
    auto api = parser.value(QStringLiteral("api"));
    if (api == QStringLiteral("core45")) {
        format.setProfile(QSurfaceFormat::CoreProfile);
        format.setVersion(4, 5);
    } else if (api == QStringLiteral("compat45")) {
        format.setProfile(QSurfaceFormat::CompatibilityProfile);
        format.setVersion(4, 5);
    } else if (api == QStringLiteral("es")) {
        format.setRenderableType(QSurfaceFormat::OpenGLES);
    } else if (api == QStringLiteral("default") || api == QStringLiteral("compat20")) {
        format.setVersion(2, 1);
    } else {
        qWarning() << "Unknown API option" << api << "\n";
        parser.showHelp(1);
    }
    QSurfaceFormat::setDefaultFormat(format);

    QQmlApplicationEngine engine;

    if (parser.isSet(QStringLiteral("page"))) {
        engine.rootContext()->setContextProperty(QStringLiteral("__commandLinePage"), parser.value(QStringLiteral("page")));
    } else {
        engine.rootContext()->setContextProperty(QStringLiteral("__commandLinePage"), nullptr);
    }

    engine.load(QStringLiteral("qrc:/main.qml"));

    return app.exec();
}