File indexing completed on 2024-10-06 03:40:50

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 "ChartsControlsPlugin.h"
0009 
0010 #include <QDebug>
0011 #include <QFile>
0012 #include <QQmlEngine>
0013 #include <QQuickStyle>
0014 #include <QUrl>
0015 
0016 ChartsControlsPlugin::ChartsControlsPlugin(QObject *parent)
0017     : QQmlExtensionPlugin(parent)
0018 {
0019 }
0020 
0021 void ChartsControlsPlugin::registerTypes(const char *uri)
0022 {
0023     Q_ASSERT(QString::fromLatin1(uri) == QLatin1String("org.kde.quickcharts.controls"));
0024 
0025     m_styleName = QQuickStyle::name();
0026 
0027     qmlRegisterSingletonType(componentUrl(QStringLiteral("Theme.qml")), uri, 1, 0, "Theme");
0028     qmlRegisterType(componentUrl(QStringLiteral("Legend.qml")), uri, 1, 0, "Legend");
0029     qmlRegisterType(componentUrl(QStringLiteral("LegendDelegate.qml")), uri, 1, 0, "LegendDelegate");
0030     qmlRegisterType(componentUrl(QStringLiteral("LineChartControl.qml")), uri, 1, 0, "LineChartControl");
0031     qmlRegisterType(componentUrl(QStringLiteral("PieChartControl.qml")), uri, 1, 0, "PieChartControl");
0032 
0033     qmlRegisterSingletonType(componentUrl(QStringLiteral("Logging.qml")), uri, 1, 0, "Logging");
0034 }
0035 
0036 QUrl ChartsControlsPlugin::componentUrl(const QString &fileName)
0037 {
0038     auto url = baseUrl();
0039     url.setPath(url.path() % QLatin1Char('/'));
0040 
0041     auto styled = url.resolved(QUrl{QStringLiteral("styles/") % m_styleName % QLatin1Char('/') % fileName});
0042     if (QFile::exists(styled.toLocalFile())) {
0043         return styled;
0044     }
0045 
0046     return url.resolved(QUrl{fileName});
0047 }
0048 
0049 #include "moc_ChartsControlsPlugin.cpp"