mirror of
https://github.com/KDE/kasts.git
synced 2025-01-10 23:53:59 +01:00
Don't use contextProperty to make KAboutData available on QML
Context properties always takes in a QVariant, which means that whenever you access the property it is re-evaluated because in between each access the property may be changed as setContextProperty() can be used at any moment in time.
This commit is contained in:
parent
b4d67ffeb4
commit
e1c80bff3d
@ -3,6 +3,7 @@
|
||||
|
||||
set(SRCS_base
|
||||
main.cpp
|
||||
about.cpp
|
||||
fetcher.cpp
|
||||
database.cpp
|
||||
entry.cpp
|
||||
|
7
src/about.cpp
Normal file
7
src/about.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#include "about.h"
|
27
src/about.h
Normal file
27
src/about.h
Normal file
@ -0,0 +1,27 @@
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <KAboutData>
|
||||
|
||||
class AboutType : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(KAboutData aboutData READ aboutData CONSTANT)
|
||||
public:
|
||||
static AboutType &instance()
|
||||
{
|
||||
static AboutType _instance;
|
||||
return _instance;
|
||||
}
|
||||
|
||||
[[nodiscard]] KAboutData aboutData() const
|
||||
{
|
||||
return KAboutData::applicationData();
|
||||
}
|
||||
};
|
@ -31,6 +31,7 @@
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include "androidlogging.h"
|
||||
#endif
|
||||
#include "about.h"
|
||||
#include "audiomanager.h"
|
||||
#include "author.h"
|
||||
#include "database.h"
|
||||
@ -118,8 +119,6 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
about.processCommandLine(&parser);
|
||||
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("_aboutData"), QVariant::fromValue(about));
|
||||
|
||||
qmlRegisterType<FeedsProxyModel>("org.kde.kasts", 1, 0, "FeedsProxyModel");
|
||||
qmlRegisterType<QueueModel>("org.kde.kasts", 1, 0, "QueueModel");
|
||||
qmlRegisterType<EpisodeProxyModel>("org.kde.kasts", 1, 0, "EpisodeProxyModel");
|
||||
@ -132,6 +131,7 @@ int main(int argc, char *argv[])
|
||||
qmlRegisterUncreatableType<EpisodeModel>("org.kde.kasts", 1, 0, "EpisodeModel", QStringLiteral("Only for enums"));
|
||||
qmlRegisterUncreatableType<FeedsModel>("org.kde.kasts", 1, 0, "FeedsModel", QStringLiteral("Only for enums"));
|
||||
|
||||
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "AboutType", &AboutType::instance());
|
||||
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "Fetcher", &Fetcher::instance());
|
||||
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "Database", &Database::instance());
|
||||
qmlRegisterSingletonInstance("org.kde.kasts", 1, 0, "DataManager", &DataManager::instance());
|
||||
|
@ -14,5 +14,5 @@ import org.kde.kasts 1.0
|
||||
|
||||
Kirigami.AboutPage {
|
||||
title: i18n("About")
|
||||
aboutData: _aboutData
|
||||
aboutData: AboutType.aboutData
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user