File indexing completed on 2024-12-15 03:45:05
0001 /* 0002 SPDX-FileCopyrightText: 2017 Aleix Pol Gonzalez <aleixpol@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "qmlpropertysource.h" 0008 #include <abstractdatasource.h> 0009 0010 using namespace KUserFeedback; 0011 0012 class CustomPropertySource : public AbstractDataSource 0013 { 0014 public: 0015 CustomPropertySource() : AbstractDataSource({}) {} 0016 0017 QVariant data() override { return m_data; } 0018 QString name() const override { return m_name; } 0019 QString description() const override { return m_description; } 0020 0021 void setSourceId(const QString &id) { setId(id); } 0022 0023 QVariant m_data; 0024 QString m_name; 0025 QString m_description; 0026 }; 0027 0028 QmlPropertySource::QmlPropertySource(QObject* parent) 0029 : QmlAbstractDataSource(new CustomPropertySource(), parent) 0030 { 0031 } 0032 0033 QVariant QmlPropertySource::data() const 0034 { 0035 return source()->data(); 0036 } 0037 0038 QString QmlPropertySource::name() const 0039 { 0040 return source()->name(); 0041 } 0042 0043 QString QmlPropertySource::description() const 0044 { 0045 return source()->description(); 0046 } 0047 0048 QString QmlPropertySource::sourceId() const 0049 { 0050 return source()->id(); 0051 } 0052 0053 void QmlPropertySource::setData(const QVariant& data) 0054 { 0055 if (customSource()->m_data != data) { 0056 customSource()->m_data = data; 0057 Q_EMIT dataChanged(data); 0058 } 0059 } 0060 0061 void QmlPropertySource::setName(const QString &name) 0062 { 0063 if (customSource()->m_name != name) { 0064 customSource()->m_name = name; 0065 Q_EMIT nameChanged(name); 0066 } 0067 } 0068 0069 void QmlPropertySource::setDescription(const QString& description) 0070 { 0071 if (customSource()->m_description != description) { 0072 customSource()->m_description = description; 0073 Q_EMIT descriptionChanged(description); 0074 } 0075 } 0076 0077 void QmlPropertySource::setSourceId(const QString& id) 0078 { 0079 if (id != source()->id()) { 0080 customSource()->setSourceId(id); 0081 Q_EMIT idChanged(id); 0082 } 0083 } 0084 0085 CustomPropertySource * KUserFeedback::QmlPropertySource::customSource() 0086 { 0087 return dynamic_cast<CustomPropertySource*>(source()); 0088 } 0089 0090 #include "moc_qmlpropertysource.cpp"