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
|
/*
* 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 "ChartsControlsPlugin.h"
#include <QDebug>
#include <QFile>
#include <QQmlEngine>
#include <QQuickStyle>
#include <QUrl>
ChartsControlsPlugin::ChartsControlsPlugin(QObject *parent)
: QQmlExtensionPlugin(parent)
{
}
void ChartsControlsPlugin::registerTypes(const char *uri)
{
Q_ASSERT(QString::fromLatin1(uri) == QLatin1String("org.kde.quickcharts.controls"));
m_styleName = QQuickStyle::name();
qmlRegisterSingletonType(componentUrl(QStringLiteral("Theme.qml")), uri, 1, 0, "Theme");
qmlRegisterType(componentUrl(QStringLiteral("Legend.qml")), uri, 1, 0, "Legend");
qmlRegisterType(componentUrl(QStringLiteral("LegendDelegate.qml")), uri, 1, 0, "LegendDelegate");
qmlRegisterType(componentUrl(QStringLiteral("LineChartControl.qml")), uri, 1, 0, "LineChartControl");
qmlRegisterType(componentUrl(QStringLiteral("PieChartControl.qml")), uri, 1, 0, "PieChartControl");
qmlRegisterSingletonType(componentUrl(QStringLiteral("Logging.qml")), uri, 1, 0, "Logging");
}
QUrl ChartsControlsPlugin::componentUrl(const QString &fileName)
{
auto url = baseUrl();
url.setPath(url.path() % QLatin1Char('/'));
auto styled = url.resolved(QUrl{QStringLiteral("styles/") % m_styleName % QLatin1Char('/') % fileName});
if (QFile::exists(styled.toLocalFile())) {
return styled;
}
return url.resolved(QUrl{fileName});
}
#include "moc_ChartsControlsPlugin.cpp"
|