Kirigami-addons

treeviewplugin.cpp
1/*
2 * SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "treeviewplugin.h"
8
9#include <QFile>
10#include <QQuickStyle>
11
12#include <QQmlEngine>
13
14static QString s_selectedStyle;
15
16TreeViewPlugin::TreeViewPlugin(QObject *parent)
17 : QQmlExtensionPlugin(parent)
18{
19 m_stylesFallbackChain << QString();
20}
21
22QUrl TreeViewPlugin::componentUrl(const QString &fileName) const
23{
24 for (const QString &style : std::as_const(m_stylesFallbackChain)) {
25 const QString candidate = QStringLiteral("styles/") + style + QLatin1Char('/') + fileName;
26 if (QFile::exists(resolveFilePath(candidate))) {
27 return QUrl(resolveFileUrl(candidate));
28 }
29 }
30
31 return QUrl(resolveFileUrl(fileName));
32}
33
34void TreeViewPlugin::registerTypes(const char *uri)
35{
36 Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.kirigamiaddons.treeview"));
37 const QString style = QQuickStyle::name();
38
39
40#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
41 //org.kde.desktop.plasma is a couple of files that fall back to desktop by purpose
42 if (style.isEmpty() && QFile::exists(resolveFilePath(QStringLiteral("/styles/org.kde.desktop")))) {
43 m_stylesFallbackChain.prepend(QStringLiteral("org.kde.desktop"));
44 }
45#endif
46
47 if (!style.isEmpty() && QFile::exists(resolveFilePath(QStringLiteral("/styles/") + style)) && !m_stylesFallbackChain.contains(style)) {
48 m_stylesFallbackChain.prepend(style);
49 }
50
51 //At this point the fallback chain will be selected->org.kde.desktop->Fallback
52 s_selectedStyle = m_stylesFallbackChain.first();
53
54 qmlRegisterType(componentUrl(QStringLiteral("TreeViewDecoration.qml")), uri, 1, 0, "TreeViewDecoration");
55
56
57 qmlProtectModule(uri, 2);
58}
59
60#include "treeviewplugin.moc"
61
62#include "moc_treeviewplugin.cpp"
bool exists() const const
T & first()
void prepend(parameter_type value)
QString name()
bool isEmpty() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.