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

Give property ratio sources a description

Also, sanity check sources that are added, and ignore those that try to
report data even when telemetry is disabled, or provide no explanation
about what they do.
parent fbe352b6
......@@ -137,6 +137,7 @@ MainWindow::MainWindow() :
m_feedbackProvider->setSubmissionInterval(1);
m_feedbackProvider->setApplicationUsageTimeUntilEncouragement(10);
auto viewModeSource = new UserFeedback::PropertyRatioSource(ui->viewStack, "currentIndex", QStringLiteral("viewRatio"));
viewModeSource->setDescription(tr("Usage ratio of the analytics view, survey editor and schema editor."));
viewModeSource->addValueMapping(0, QStringLiteral("analytics"));
viewModeSource->addValueMapping(1, QStringLiteral("surveyEditor"));
viewModeSource->addValueMapping(2, QStringLiteral("schemaEditor"));
......
......@@ -37,6 +37,7 @@ public:
void propertyChanged();
QString valueToString(const QVariant &value) const;
QString description;
QObject *obj = nullptr; // TODO make this a QPointer?
QObject *signalMonitor = nullptr;
QMetaProperty property;
......@@ -126,7 +127,14 @@ void PropertyRatioSource::addValueMapping(const QVariant &value, const QString &
QString PropertyRatioSource::description() const
{
return QString(); // TODO
Q_D(const PropertyRatioSource);
return d->description;
}
void PropertyRatioSource::setDescription(const QString& desc)
{
Q_D(PropertyRatioSource);
d->description = desc;
}
QVariant PropertyRatioSource::data()
......
......@@ -50,6 +50,12 @@ public:
void addValueMapping(const QVariant &value, const QString &str);
QString description() const override;
/** Set human-readable and translated description of the data provided by this source.
* @note This must be set before adding this source, sources without description are
* discarded.
*/
void setDescription(const QString &desc);
QVariant data() override;
void load(QSettings *settings) override;
void store(QSettings *settings) override;
......
......@@ -341,7 +341,20 @@ void Provider::setStatisticsCollectionMode(StatisticsCollectionMode mode)
void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMode mode)
{
// sanity-check sources
if (mode == NoStatistics) {
qCritical() << "Source" << source->name() << "attempts to report data unconditionally, ignoring!";
delete source;
return;
}
if (source->description().isEmpty()) {
qCritical() << "Source" << source->name() << "has no description, ignoring!";
delete source;
return;
}
Q_ASSERT(mode != NoStatistics);
Q_ASSERT(!source->description().isEmpty());
source->setCollectionMode(mode);
d->dataSources.push_back(source);
......
......@@ -65,6 +65,7 @@ Orwell::Orwell(QWidget* parent) :
connect(ui->actionQuit, &QAction::triggered, qApp, &QCoreApplication::quit);
auto propertyMonitorSource = new UserFeedback::PropertyRatioSource(ui->dial, "value", QStringLiteral("dialRatio"));
propertyMonitorSource->setDescription(QStringLiteral("The dial position."));
propertyMonitorSource->addValueMapping(0, QStringLiteral("off"));
propertyMonitorSource->addValueMapping(11, QStringLiteral("max"));
provider->addDataSource(propertyMonitorSource, UserFeedback::Provider::AllStatistics);
......
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