KUserFeedback

qmlpropertysource.cpp
1/*
2 SPDX-FileCopyrightText: 2017 Aleix Pol Gonzalez <aleixpol@kde.org>
3
4 SPDX-License-Identifier: MIT
5*/
6
7#include "qmlpropertysource.h"
8#include <abstractdatasource.h>
9
10using namespace KUserFeedback;
11
12class CustomPropertySource : public AbstractDataSource
13{
14public:
15 CustomPropertySource() : AbstractDataSource({}) {}
16
17 QVariant data() override { return m_data; }
18 QString name() const override { return m_name; }
19 QString description() const override { return m_description; }
20
21 void setSourceId(const QString &id) { setId(id); }
22
23 QVariant m_data;
24 QString m_name;
25 QString m_description;
26};
27
28QmlPropertySource::QmlPropertySource(QObject* parent)
29 : QmlAbstractDataSource(new CustomPropertySource(), parent)
30{
31}
32
33QVariant QmlPropertySource::data() const
34{
35 return source()->data();
36}
37
38QString QmlPropertySource::name() const
39{
40 return source()->name();
41}
42
43QString QmlPropertySource::description() const
44{
45 return source()->description();
46}
47
48QString QmlPropertySource::sourceId() const
49{
50 return source()->id();
51}
52
53void QmlPropertySource::setData(const QVariant& data)
54{
55 if (customSource()->m_data != data) {
56 customSource()->m_data = data;
57 Q_EMIT dataChanged(data);
58 }
59}
60
61void QmlPropertySource::setName(const QString &name)
62{
63 if (customSource()->m_name != name) {
64 customSource()->m_name = name;
65 Q_EMIT nameChanged(name);
66 }
67}
68
69void QmlPropertySource::setDescription(const QString& description)
70{
71 if (customSource()->m_description != description) {
72 customSource()->m_description = description;
73 Q_EMIT descriptionChanged(description);
74 }
75}
76
77void QmlPropertySource::setSourceId(const QString& id)
78{
79 if (id != source()->id()) {
80 customSource()->setSourceId(id);
81 Q_EMIT idChanged(id);
82 }
83}
84
85CustomPropertySource * KUserFeedback::QmlPropertySource::customSource()
86{
87 return dynamic_cast<CustomPropertySource*>(source());
88}
89
90#include "moc_qmlpropertysource.cpp"
Base class for data sources for telemetry data.
QString id() const
Returns the ID of this data source.
virtual QVariant data()=0
Returns the data gathered by this source.
virtual QString name() const
Returns a short name of this data source.
void setId(const QString &id)
Set the ID of this data source.
virtual QString description() const =0
Returns a human-readable, translated description of what this source provides.
QString name(GameStandardAction id)
Classes for integrating telemetry collection, survey targeting, and contribution encouragenemt and co...
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:48:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.