From a721878fda0de83e913f4f31e27ddecbcbba89b2 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 24 Dec 2013 15:42:44 +0100 Subject: [PATCH] use q QQmlPropertyMap, crash-- and more efficient --- src/declarativeimports/core/datasource.cpp | 7 +++---- src/declarativeimports/core/datasource.h | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/declarativeimports/core/datasource.cpp b/src/declarativeimports/core/datasource.cpp index 64cd38f5b..2278803b3 100644 --- a/src/declarativeimports/core/datasource.cpp +++ b/src/declarativeimports/core/datasource.cpp @@ -30,6 +30,7 @@ DataSource::DataSource(QObject* parent) m_dataEngine(0), m_dataEngineConsumer(0) { + m_models = new QQmlPropertyMap(this); setObjectName("DataSource"); } @@ -150,12 +151,10 @@ void DataSource::dataUpdated(const QString &sourceName, const Plasma::DataEngine void DataSource::modelChanged(const QString &sourceName, QAbstractItemModel *model) { - m_models[sourceName] = QVariant::fromValue(model); + m_models->insert(sourceName, QVariant::fromValue(model)); connect(model, &QObject::destroyed, [=]() { - m_models.remove(sourceName); - emit modelsChanged(); + m_models->clear(sourceName); }); - emit modelsChanged(); } void DataSource::removeSource(const QString &source) diff --git a/src/declarativeimports/core/datasource.h b/src/declarativeimports/core/datasource.h index 16b11b3bd..5008c934e 100644 --- a/src/declarativeimports/core/datasource.h +++ b/src/declarativeimports/core/datasource.h @@ -97,8 +97,8 @@ public: /** * All the models associated to this DataEngine, indexed by source */ - Q_PROPERTY(QVariantMap models READ models NOTIFY modelsChanged); - QVariantMap models() const {return m_models;} + Q_PROPERTY(QQmlPropertyMap *models READ models CONSTANT); + QQmlPropertyMap *models() const {return m_models;} /** * @returns a Plasma::Service given a source name @@ -131,7 +131,6 @@ Q_SIGNALS: void intervalChanged(); void engineChanged(); void dataChanged(); - void modelsChanged(); void connectedSourcesChanged(); void sourcesChanged(); @@ -140,7 +139,7 @@ private: int m_interval; QString m_engine; QVariantMap m_data; - QVariantMap m_models; + QQmlPropertyMap *m_models; Plasma::DataEngine* m_dataEngine; Plasma::DataEngineConsumer* m_dataEngineConsumer; QStringList m_connectedSources;