Commit 1938dce1 authored by Volker Krause's avatar Volker Krause
Browse files

Add sample name to the data source base class

parent 4345d795
......@@ -24,19 +24,21 @@ AbstractDataSourcePrivate::AbstractDataSourcePrivate() = default;
AbstractDataSourcePrivate::~AbstractDataSourcePrivate() = default;
AbstractDataSource::AbstractDataSource() :
d_ptr(new AbstractDataSourcePrivate)
AbstractDataSource::AbstractDataSource(const QString &name, AbstractDataSourcePrivate* dd) :
d_ptr(dd ? dd : new AbstractDataSourcePrivate)
{
Q_ASSERT(!name.isEmpty());
d_ptr->name = name;
}
AbstractDataSource::AbstractDataSource(AbstractDataSourcePrivate* dd) :
d_ptr(dd)
AbstractDataSource::~AbstractDataSource()
{
delete d_ptr;
}
AbstractDataSource::~AbstractDataSource()
QString AbstractDataSource::name() const
{
delete d_ptr;
return d_ptr->name;
}
void AbstractDataSource::load(QSettings *settings)
......
......@@ -32,9 +32,11 @@ class AbstractDataSourcePrivate;
class USERFEEDBACKCORE_EXPORT AbstractDataSource
{
public:
AbstractDataSource();
virtual ~AbstractDataSource();
/** Returns the name of this data source. */
QString name() const;
/** Override this to serialize the data you collected. */
virtual void toJson(QJsonObject &obj) = 0;
......@@ -50,7 +52,12 @@ public:
void setCollectionMode(Provider::StatisticsCollectionMode mode);
protected:
explicit AbstractDataSource(AbstractDataSourcePrivate *dd);
/** Create a new data source named @p name.
* The name of the data source must match the corresponding
* product schema entry.
* @param name Must not be empty.
*/
explicit AbstractDataSource(const QString &name, AbstractDataSourcePrivate *dd = Q_NULLPTR);
class AbstractDataSourcePrivate* const d_ptr;
private:
......
......@@ -28,6 +28,7 @@ public:
AbstractDataSourcePrivate();
virtual ~AbstractDataSourcePrivate();
QString name;
Provider::StatisticsCollectionMode mode = Provider::AllStatistics;
};
......
......@@ -22,7 +22,8 @@
using namespace UserFeedback;
PlatformInfoSource::PlatformInfoSource()
PlatformInfoSource::PlatformInfoSource() :
AbstractDataSource(QStringLiteral("platform"))
{
}
......
......@@ -45,7 +45,6 @@ public:
QTime lastChangeTime;
QHash<QString, int> ratioSet;
QMap<QVariant, QString> valueMap;
QString sampleName;
};
// inefficient workaround for not being able to connect QMetaMethod to a function directly
......@@ -90,14 +89,12 @@ QString PropertyRatioSourcePrivate::valueToString(const QVariant &value) const
}
PropertyRatioSource::PropertyRatioSource(QObject *obj, const char *propertyName, const QString &sampleName) :
AbstractDataSource(new PropertyRatioSourcePrivate)
AbstractDataSource(sampleName, new PropertyRatioSourcePrivate)
{
Q_D(PropertyRatioSource);
d->obj = obj;
Q_ASSERT(obj);
d->sampleName = sampleName;
Q_ASSERT(!sampleName.isEmpty());
auto idx = obj->metaObject()->indexOfProperty(propertyName);
Q_ASSERT(idx >= 0);
......@@ -143,14 +140,14 @@ void PropertyRatioSource::toJson(QJsonObject &obj)
for (auto it = d->ratioSet.constBegin(); it != d->ratioSet.constEnd(); ++it)
set.insert(it.key(), (double)it.value() / (double)(total));
obj.insert(d->sampleName, set);
obj.insert(name(), set);
}
void PropertyRatioSource::load(QSettings *settings)
{
Q_D(PropertyRatioSource);
settings->beginGroup(QStringLiteral("PropertyRatioSource"));
settings->beginGroup(d->sampleName);
settings->beginGroup(name());
const auto count = settings->beginReadArray(QStringLiteral("RatioSet"));
for (int i = 0; i < count; ++i) {
......@@ -172,7 +169,7 @@ void PropertyRatioSource::store(QSettings *settings)
d->propertyChanged();
settings->beginGroup(QStringLiteral("PropertyRatioSource"));
settings->beginGroup(d->sampleName);
settings->beginGroup(name());
settings->beginWriteArray(QStringLiteral("RatioSet"), d->ratioSet.size());
int i = 0;
......
......@@ -29,6 +29,11 @@ QString screenToString(QScreen *screen)
return QStringLiteral("%1x%2 %3dpi").arg(screen->size().width()).arg(screen->size().height()).arg((int)screen->physicalDotsPerInch());
}
ScreenInfoSource::ScreenInfoSource() :
AbstractDataSource(QStringLiteral("screens"))
{
}
void ScreenInfoSource::toJson(QJsonObject &obj)
{
QJsonArray a;
......
......@@ -26,6 +26,8 @@ namespace UserFeedback {
class USERFEEDBACKCORE_EXPORT ScreenInfoSource : public AbstractDataSource
{
public:
ScreenInfoSource();
void toJson(QJsonObject &obj) override;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment