File indexing completed on 2024-12-15 03:45:04

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #ifndef KUSERFEEDBACK_PROPERTYRATIOSOURCE_H
0008 #define KUSERFEEDBACK_PROPERTYRATIOSOURCE_H
0009 
0010 #include "kuserfeedbackcore_export.h"
0011 #include "abstractdatasource.h"
0012 
0013 namespace KUserFeedback {
0014 
0015 class PropertyRatioSourcePrivate;
0016 
0017 /*! Records the time ratio a given QObject property has a specific value.
0018  *
0019  *  An example use-case would be the usage ratio of a applications
0020  *  views/modes selected by a QTabWidget or QRadioButton.
0021  *
0022  *  The default telemetry mode for this source is Provider::DetailedUsageStatistics.
0023  */
0024 class KUSERFEEDBACKCORE_EXPORT PropertyRatioSource :  public AbstractDataSource
0025 {
0026 public:
0027     /*! Create a new property ratio data source.
0028      * @param obj the QObject of which a property should be monitored.
0029      * @param propertyName The name of the property to monitor.
0030      * This property must have a change notification signal. The value must have
0031      * comparison operators registered.
0032      * @param sampleName This is the name of the database field this data source is
0033      * associated with.
0034      */
0035     explicit PropertyRatioSource(QObject *obj, const char* propertyName, const QString &sampleName);
0036 
0037     /*! Returns the monitored object. */
0038     QObject* object() const;
0039     /*! Sets the monitoried object. */
0040     void setObject(QObject *object);
0041 
0042     /*! Returns the property name. */
0043     QString propertyName() const;
0044     /*! Sets the property name that should be monitored. */
0045     void setPropertyName(const QString &name);
0046 
0047     /*! Map property value @p value to @p str for sending to the server.
0048      *  This is useful to map internal identifiers to portable and persistable values,
0049      *  such as turning pointers or indexes into meaningful descriptions.
0050      *  @param value The property value to map.
0051      *  @param str The string the property value @p value should be mapped to.
0052      */
0053     void addValueMapping(const QVariant &value, const QString &str);
0054 
0055     QString name() const override;
0056     /*! Set human readable name.
0057      *  @see AbstractDataSource::name()
0058      */
0059     void setName(const QString &name);
0060 
0061     QString description() const override;
0062 
0063     /*! Set human-readable and translated description of the data provided by this source.
0064      *  @note This must be set before adding this source, sources without description are
0065      *  discarded.
0066      *  @param desc The description.
0067      */
0068     void setDescription(const QString &desc);
0069 
0070     QVariant data() override;
0071 
0072     void loadImpl(QSettings *settings) override;
0073     void storeImpl(QSettings *settings) override;
0074     void resetImpl(QSettings *settings) override;
0075 
0076     using AbstractDataSource::setId;
0077 private:
0078     Q_DECLARE_PRIVATE(PropertyRatioSource)
0079 };
0080 
0081 }
0082 
0083 #endif // KUSERFEEDBACK_PROPERTYRATIOSOURCE_H