use a QQmlPropertyMap instead of a variantmap

this way when a source is updated, only that will be updated, and not the whole data

so whould be way more efficient.

it remains API compatible
This commit is contained in:
Marco Martin 2014-01-07 14:33:20 +01:00
parent eb83537f63
commit 3feb6ac3ae
3 changed files with 14 additions and 20 deletions

View File

@ -198,21 +198,17 @@ void DataModel::dataUpdated(const QString &sourceName, const QVariantMap &data)
//an item is represented by a source: keys are roles m_roleLevel == FirstLevel
QVariantList list;
if (!m_dataSource->data().isEmpty()) {
QVariantMap::const_iterator i = m_dataSource->data().constBegin();
while (i != m_dataSource->data().constEnd()) {
if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(i.key())) {
++i;
if (!m_dataSource->data()->isEmpty()) {
foreach (const QString &key, m_dataSource->data()->keys()) {
if (!m_sourceFilter.isEmpty() && m_sourceFilterRE.isValid() && !m_sourceFilterRE.exactMatch(key)) {
continue;
}
QVariant value = i.value();
QVariant value = m_dataSource->data()->value(key);
if (value.isValid() && value.canConvert<Plasma::DataEngine::Data>()) {
Plasma::DataEngine::Data data = value.value<Plasma::DataEngine::Data>();
data["DataEngineSource"] = i.key();
data["DataEngineSource"] = key;
list.append(data);
}
++i;
}
}
setItems(QString(), list);
@ -252,11 +248,8 @@ void DataModel::setDataSource(QObject *object)
m_dataSource = source;
const QMap<QString, QVariant> data = source->data();
QMap<QString, QVariant>::const_iterator i = data.constBegin();
while (i != data.constEnd()) {
dataUpdated(i.key(), i.value().value<Plasma::DataEngine::Data>());
++i;
foreach (const QString &key, m_dataSource->data()->keys()) {
dataUpdated(key, m_dataSource->data()->value(key).value<Plasma::DataEngine::Data>());
}
connect(m_dataSource, &DataSource::newData,

View File

@ -31,6 +31,7 @@ DataSource::DataSource(QObject* parent)
m_dataEngineConsumer(0)
{
m_models = new QQmlPropertyMap(this);
m_data = new QQmlPropertyMap(this);
setObjectName("DataSource");
}
@ -50,7 +51,7 @@ void DataSource::setConnectedSources(const QStringList &sources)
foreach (const QString &source, m_connectedSources) {
if (!sources.contains(source)) {
m_data.remove(source);
m_data->clear(source);
sourcesChanged = true;
if (m_dataEngine) {
m_dataEngine->disconnectSource(source, this);
@ -141,7 +142,7 @@ void DataSource::dataUpdated(const QString &sourceName, const Plasma::DataEngine
{
//it can arrive also data we don't explicitly connected a source
if (m_connectedSources.contains(sourceName)) {
m_data.insert(sourceName.toLatin1(), data);
m_data->insert(sourceName.toLatin1(), data);
emit dataChanged();
emit newData(sourceName, data);
} else if (m_dataEngine) {
@ -165,7 +166,7 @@ void DataSource::modelChanged(const QString &sourceName, QAbstractItemModel *mod
void DataSource::removeSource(const QString &source)
{
m_data.remove(source);
m_data->clear(source);
m_models->clear(source);
//TODO: emit those signals as last thing

View File

@ -91,8 +91,8 @@ public:
* All the data fetched by this dataengine.
* This is a map of maps. At the first level, there are the source names, at the second, they keys set by the DataEngine
*/
Q_PROPERTY(QVariantMap data READ data NOTIFY dataChanged);
QVariantMap data() const {return m_data;}
Q_PROPERTY(QQmlPropertyMap *data READ data CONSTANT);
QQmlPropertyMap *data() const {return m_data;}
/**
* All the models associated to this DataEngine, indexed by source.
@ -140,7 +140,7 @@ private:
QString m_id;
int m_interval;
QString m_engine;
QVariantMap m_data;
QQmlPropertyMap *m_data;
QQmlPropertyMap *m_models;
Plasma::DataEngine* m_dataEngine;
Plasma::DataEngineConsumer* m_dataEngineConsumer;