diff --git a/src/provider/core/provider.h b/src/provider/core/provider.h --- a/src/provider/core/provider.h +++ b/src/provider/core/provider.h @@ -182,6 +182,12 @@ */ QVector dataSources() const; + /*! Returns a data source with matched @p id + * @param id data source unique identifier + * @return pointer to found data source or nullptr if data source is not found + */ + AbstractDataSource *findDataSource(const QString &id) const; + /*! Returns the minimum time between two surveys in days. * The default is -1 (no surveys enabled). */ diff --git a/src/provider/core/provider.cpp b/src/provider/core/provider.cpp --- a/src/provider/core/provider.cpp +++ b/src/provider/core/provider.cpp @@ -504,6 +504,7 @@ timeSrc->setProvider(d); d->dataSources.push_back(source); + d->dataSourcesById[source->id()] = source; auto s = d->makeSettings(); s->beginGroup(QStringLiteral("Source-") + source->id()); @@ -515,6 +516,12 @@ return d->dataSources; } +AbstractDataSource *Provider::findDataSource(const QString &id) const +{ + auto it = d->dataSourcesById.find(id); + return it != std::end(d->dataSourcesById) ? *it : nullptr; +} + int Provider::surveyInterval() const { return d->surveyInterval; diff --git a/src/provider/core/provider_p.h b/src/provider/core/provider_p.h --- a/src/provider/core/provider_p.h +++ b/src/provider/core/provider_p.h @@ -100,6 +100,7 @@ int encouragementInterval; QVector dataSources; + QHash dataSourcesById; }; }