Debian Codegraph @

src/imports/PerformanceMetrics/plugin/upmplugin.cpp

raw
1 /*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Florian Boucault <[email protected]>
17 */
18
19 #include "upmplugin.h"
20
21 #include <QtQml/QtQml>
22 #include <QtQml/QQmlEngine>
23 #include <QtQml/QQmlContext>
24
25 #include "upmcpuusage.h"
26 #include "upmtexturefromimage.h"
27 #include "upmgraphmodel.h"
28 #include "upmrenderingtimes.h"
29
30 void LomiriPerformanceMetricsPlugin::registerTypeVersion(const char *uri, int major, int minor)
31 {
32 qmlRegisterType<UPMRenderingTimes>(uri, major, minor, "RenderingTimes");
33 qmlRegisterType<UPMCpuUsage>(uri, major, minor, "CpuUsage");
34 qmlRegisterType<UPMTextureFromImage>(uri, major, minor, "TextureFromImage");
35 #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
36 qmlRegisterType<UPMGraphModel>();
37 #else
38 qmlRegisterAnonymousType<UPMGraphModel>(uri, major);
39 #endif
40 }
41
42 void LomiriPerformanceMetricsPlugin::registerTypes(const char *uri)
43 {
44 Q_ASSERT(uri == QLatin1String("Lomiri.PerformanceMetrics"));
45 registerTypeVersion(uri, 0, 1);
46 registerTypeVersion(uri, 1, 0);
47 }
48
49 void LomiriPerformanceMetricsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
50 {
51 QQmlExtensionPlugin::initializeEngine(engine, uri);
52 QQmlContext* context = engine->rootContext();
53 QByteArray performanceOverlay = qgetenv("PERFORMANCE_OVERLAY");
54 context->setContextProperty("performanceOverlayEnabled", QVariant(!performanceOverlay.isEmpty()));
55 }