Commit c0aabf5e authored by Volker Krause's avatar Volker Krause
Browse files

Support persisting data source information.

parent 22400b66
......@@ -39,6 +39,16 @@ AbstractDataSource::~AbstractDataSource()
delete d_ptr;
}
void AbstractDataSource::load(QSettings *settings)
{
Q_UNUSED(settings);
}
void AbstractDataSource::store(QSettings *settings)
{
Q_UNUSED(settings);
}
Provider::StatisticsCollectionMode AbstractDataSource::collectionMode() const
{
Q_D(const AbstractDataSource);
......
......@@ -22,6 +22,7 @@
#include "provider.h"
class QJsonObject;
class QSettings;
namespace UserFeedback {
......@@ -37,6 +38,12 @@ public:
/** Override this to serialize the data you collected. */
virtual void toJson(QJsonObject &obj) = 0;
/** Load persistent state for this data source. */
virtual void load(QSettings *settings);
/** Store persistent state for this data source. */
virtual void store(QSettings *settings);
/** Returns which colleciton mode this data source belongs to. */
Provider::StatisticsCollectionMode collectionMode() const;
/** Sets which colleciton mode this data source belongs to. */
......
......@@ -23,6 +23,7 @@
#include <QMap>
#include <QMetaProperty>
#include <QObject>
#include <QSettings>
#include <QTime>
using namespace UserFeedback;
......@@ -141,4 +142,43 @@ void PropertyRatioSource::toJson(QJsonObject &obj)
obj.insert(d->sampleName, set);
}
void PropertyRatioSource::load(QSettings *settings)
{
Q_D(PropertyRatioSource);
settings->beginGroup(QStringLiteral("PropertyRatioSource"));
settings->beginGroup(d->sampleName);
const auto count = settings->beginReadArray(QStringLiteral("RatioSet"));
for (int i = 0; i < count; ++i) {
settings->setArrayIndex(i);
const auto value = settings->value(QStringLiteral("Value"));
const auto amount = settings->value(QStringLiteral("Amount"), 0).toInt();
d->ratioSet.insert(value, amount);
}
settings->endArray();
settings->endGroup();
settings->endGroup();
}
void PropertyRatioSource::store(QSettings *settings)
{
Q_D(const PropertyRatioSource);
settings->beginGroup(QStringLiteral("PropertyRatioSource"));
settings->beginGroup(d->sampleName);
settings->beginWriteArray(QStringLiteral("RatioSet"), d->ratioSet.size());
int i = 0;
for (auto it = d->ratioSet.constBegin(); it != d->ratioSet.constEnd(); ++it) {
settings->setArrayIndex(i++);
settings->setValue(QStringLiteral("Value"), it.key());
settings->setValue(QStringLiteral("Amount"), it.value());
}
settings->endArray();
settings->endGroup();
settings->endGroup();
}
#include "propertyratiosource.moc"
......@@ -50,6 +50,8 @@ public:
void addValueMapping(const QVariant &value, const QString &str);
void toJson(QJsonObject &obj) Q_DECL_OVERRIDE;
void load(QSettings *settings) Q_DECL_OVERRIDE;
void store(QSettings *settings) Q_DECL_OVERRIDE;
private:
Q_DECLARE_PRIVATE(PropertyRatioSource)
......
......@@ -163,6 +163,9 @@ void ProviderPrivate::store()
settings.setValue(QStringLiteral("ApplicationTime"), currentApplicationTime());
settings.setValue(QStringLiteral("EncouragementDisplayed"), encouragementDisplayed);
foreach (auto source, dataSources)
source->store(&settings);
}
void ProviderPrivate::aboutToQuit()
......@@ -315,6 +318,10 @@ void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMod
Q_ASSERT(mode != NoStatistics);
source->setCollectionMode(mode);
d->dataSources.push_back(source);
QSettings settings;
settings.beginGroup(QStringLiteral("UserFeedback"));
source->load(&settings);
}
int Provider::surveyInterval() const
......
Markdown is supported
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