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

Allow data sources to reset their internal counters after submitting

This allows differential rather than just absolute data collection too.
parent 0503c892
......@@ -153,12 +153,23 @@ private slots:
src2.store(&s);
}
PropertyRatioSource src3(this, "prop", QStringLiteral("ratioSample"));
src3.load(&s);
const auto map = src3.data().toMap();
QCOMPARE(map.size(), 2);
QVERIFY(map.contains(QStringLiteral("value1")));
QVERIFY(map.contains(QStringLiteral("value2")));
{
PropertyRatioSource src3(this, "prop", QStringLiteral("ratioSample"));
src3.load(&s);
const auto map = src3.data().toMap();
QCOMPARE(map.size(), 2);
QVERIFY(map.contains(QStringLiteral("value1")));
QVERIFY(map.contains(QStringLiteral("value2")));
src3.reset(&s);
QVERIFY(src3.data().toMap().isEmpty());
}
{
PropertyRatioSource src4(this, "prop", QStringLiteral("ratioSample"));
src4.load(&s);
const auto map = src4.data().toMap();
QCOMPARE(map.size(), 0);
}
}
void testApplicationVersionSource()
......
......@@ -51,6 +51,11 @@ void AbstractDataSource::store(QSettings *settings)
Q_UNUSED(settings);
}
void AbstractDataSource::reset(QSettings *settings)
{
Q_UNUSED(settings);
}
Provider::StatisticsCollectionMode AbstractDataSource::collectionMode() const
{
Q_D(const AbstractDataSource);
......
......@@ -83,6 +83,15 @@ public:
*/
virtual void store(QSettings *settings);
/*! Reset the persistent state of this data source.
* This is called after a successful submission of data, and can be used
* by sources that track differential rather than absolute data to reset
* their counters.
* @param settings A QSettings object opened in the dedicated group of this
* data source.
*/
virtual void reset(QSettings *settings);
/*! Returns which colleciton mode this data source belongs to.
* @return The statistics collection category this source belongs to.
*/
......
......@@ -190,7 +190,6 @@ void PropertyRatioSource::load(QSettings *settings)
}
}
void PropertyRatioSource::store(QSettings *settings)
{
Q_D(PropertyRatioSource);
......@@ -208,4 +207,12 @@ void PropertyRatioSource::store(QSettings *settings)
}
}
void PropertyRatioSource::reset(QSettings* settings)
{
Q_D(PropertyRatioSource);
d->baseRatioSet.clear();
d->ratioSet.clear();
settings->remove(QString());
}
#include "propertyratiosource.moc"
......@@ -63,6 +63,7 @@ public:
QVariant data() override;
void load(QSettings *settings) override;
void store(QSettings *settings) override;
void reset(QSettings *settings) override;
private:
Q_DECLARE_PRIVATE(PropertyRatioSource)
......
......@@ -267,7 +267,18 @@ void ProviderPrivate::submitFinished()
}
lastSubmitTime = QDateTime::currentDateTime();
storeOne(QStringLiteral("LastEncouragement"), lastEncouragementTime);
auto s = makeSettings();
s->beginGroup(QStringLiteral("UserFeedback"));
s->setValue(QStringLiteral("LastEncouragement"), lastEncouragementTime);
s->endGroup();
// reset source counters
foreach (auto source, dataSources) {
s->beginGroup(QStringLiteral("Source-") + source->name());
source->reset(s.get());
s->endGroup();
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
const auto obj = QJsonDocument::fromJson(reply->readAll()).object();
......
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