use q QQmlPropertyMap, crash-- and more efficient

This commit is contained in:
Marco Martin 2013-12-24 15:42:44 +01:00
parent 124139c2bf
commit a721878fda
2 changed files with 6 additions and 8 deletions

View File

@ -30,6 +30,7 @@ DataSource::DataSource(QObject* parent)
m_dataEngine(0), m_dataEngine(0),
m_dataEngineConsumer(0) m_dataEngineConsumer(0)
{ {
m_models = new QQmlPropertyMap(this);
setObjectName("DataSource"); setObjectName("DataSource");
} }
@ -150,12 +151,10 @@ void DataSource::dataUpdated(const QString &sourceName, const Plasma::DataEngine
void DataSource::modelChanged(const QString &sourceName, QAbstractItemModel *model) 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, [=]() { connect(model, &QObject::destroyed, [=]() {
m_models.remove(sourceName); m_models->clear(sourceName);
emit modelsChanged();
}); });
emit modelsChanged();
} }
void DataSource::removeSource(const QString &source) void DataSource::removeSource(const QString &source)

View File

@ -97,8 +97,8 @@ public:
/** /**
* All the models associated to this DataEngine, indexed by source * All the models associated to this DataEngine, indexed by source
*/ */
Q_PROPERTY(QVariantMap models READ models NOTIFY modelsChanged); Q_PROPERTY(QQmlPropertyMap *models READ models CONSTANT);
QVariantMap models() const {return m_models;} QQmlPropertyMap *models() const {return m_models;}
/** /**
* @returns a Plasma::Service given a source name * @returns a Plasma::Service given a source name
@ -131,7 +131,6 @@ Q_SIGNALS:
void intervalChanged(); void intervalChanged();
void engineChanged(); void engineChanged();
void dataChanged(); void dataChanged();
void modelsChanged();
void connectedSourcesChanged(); void connectedSourcesChanged();
void sourcesChanged(); void sourcesChanged();
@ -140,7 +139,7 @@ private:
int m_interval; int m_interval;
QString m_engine; QString m_engine;
QVariantMap m_data; QVariantMap m_data;
QVariantMap m_models; QQmlPropertyMap *m_models;
Plasma::DataEngine* m_dataEngine; Plasma::DataEngine* m_dataEngine;
Plasma::DataEngineConsumer* m_dataEngineConsumer; Plasma::DataEngineConsumer* m_dataEngineConsumer;
QStringList m_connectedSources; QStringList m_connectedSources;