From 29f4ac0d995d3e0f3094e8e0192da29a8c716c9c Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Mon, 8 Nov 2010 23:07:25 +0000 Subject: [PATCH] propagate with signal sources removal, connection and disconnection svn path=/trunk/KDE/kdebase/runtime/; revision=1194425 --- declarativeimports/core/datamodel.cpp | 10 ++++++++++ declarativeimports/core/datamodel.h | 1 + declarativeimports/core/datasource.cpp | 13 +++++++++++-- declarativeimports/core/datasource_p.h | 8 ++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/declarativeimports/core/datamodel.cpp b/declarativeimports/core/datamodel.cpp index 8e07ea8c4..e30352d9f 100644 --- a/declarativeimports/core/datamodel.cpp +++ b/declarativeimports/core/datamodel.cpp @@ -179,6 +179,8 @@ void DataModel::setDataSource(QObject *object) m_dataSource = source; connect(m_dataSource, SIGNAL(newData(const QString &, const Plasma::DataEngine::Data &)), this, SLOT(dataUpdated(const QString &, const Plasma::DataEngine::Data &))); + connect(m_dataSource, SIGNAL(sourceRemoved(const QString &)), this, SLOT(removeSource(const QString &))); + connect(m_dataSource, SIGNAL(sourceDisconnected(const QString &)), this, SLOT(removeSource(const QString &))); } QObject *DataModel::dataSource() const @@ -234,6 +236,14 @@ void DataModel::setItems(const QString &sourceName, const QVariantList &list) emit modelReset(); } +void DataModel::removeSource(const QString &sourceName) +{ + //FIXME: this could be way more efficient by not resetting the whole model + emit modelAboutToBeReset(); + m_items.remove(sourceName); + emit modelReset(); +} + QVariant DataModel::data(const QModelIndex &index, int role) const { if (!index.isValid() || index.column() > 0 || diff --git a/declarativeimports/core/datamodel.h b/declarativeimports/core/datamodel.h index d17df81bd..42824efa7 100644 --- a/declarativeimports/core/datamodel.h +++ b/declarativeimports/core/datamodel.h @@ -114,6 +114,7 @@ Q_SIGNALS: private Q_SLOTS: void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data); + void removeSource(const QString &sourceName); private: DataSource *m_dataSource; diff --git a/declarativeimports/core/datasource.cpp b/declarativeimports/core/datasource.cpp index 39e628529..dbedb0107 100644 --- a/declarativeimports/core/datasource.cpp +++ b/declarativeimports/core/datasource.cpp @@ -53,7 +53,7 @@ void DataSource::setConnectedSources(const QStringList &sources) } } foreach (const QString &source, m_connectedSources) { - if (!m_connectedSources.contains(source)) { + if (!sources.contains(source)) { m_oldSources.append(source); } } @@ -86,6 +86,7 @@ void DataSource::setInterval(const int interval) emit intervalChanged(); } +//TODO: event compression for this void DataSource::setupData() { @@ -108,10 +109,13 @@ void DataSource::setupData() connect(m_dataEngine, SIGNAL(sourceAdded(const QString&)), this, SIGNAL(sourceAdded(const QString&))); connect(m_dataEngine, SIGNAL(sourceRemoved(const QString&)), this, SLOT(removeSource(const QString&))); + connect(m_dataEngine, SIGNAL(sourceRemoved(const QString&)), this, SIGNAL(sourceRemoved(const QString&))); + //TODO: remove after event compression done if (!(m_changes & SourcesChanged)) { foreach (const QString &source, m_connectedSources) { m_dataEngine->connectSource(source, this, m_interval); + emit sourceConnected(source); } } } @@ -120,9 +124,11 @@ void DataSource::setupData() if (m_dataEngine) { foreach (const QString &source, m_oldSources) { m_dataEngine->disconnectSource(source, this); + emit sourceDisconnected(source); } foreach (const QString &source, m_newSources) { m_dataEngine->connectSource(source, this, m_interval); + emit sourceConnected(source); } m_oldSources.clear(); m_newSources.clear(); @@ -143,7 +149,9 @@ void DataSource::removeSource(const QString &source) { m_data.remove(source); + //TODO: emit those signals as last thing if (m_connectedSources.contains(source)) { + emit sourceDisconnected(source); emit connectedSourcesChanged(); } if (m_dataEngine) { @@ -152,7 +160,6 @@ void DataSource::removeSource(const QString &source) m_oldSources.removeAll(source); //TODO: delete it? m_services.remove(source); - emit connectedSourcesChanged(); } } @@ -178,6 +185,7 @@ void DataSource::connectSource(const QString &source) m_newSources.append(source); m_connectedSources.append(source); m_changes |= SourcesChanged; + emit sourceConnected(source); emit connectedSourcesChanged(); } @@ -186,6 +194,7 @@ void DataSource::disconnectSource(const QString &source) m_oldSources.append(source); m_connectedSources.removeAll(source); m_changes |= SourcesChanged; + emit sourceDisconnected(source); emit connectedSourcesChanged(); } diff --git a/declarativeimports/core/datasource_p.h b/declarativeimports/core/datasource_p.h index cbdb0c6cf..2d2cb137d 100644 --- a/declarativeimports/core/datasource_p.h +++ b/declarativeimports/core/datasource_p.h @@ -81,19 +81,19 @@ public: Q_INVOKABLE void connectSource(const QString &source); Q_INVOKABLE void disconnectSource(const QString &source); -public Q_SLOTS: - void removeSource(const QString &source); - protected Q_SLOTS: void dataUpdated(const QString &sourceName, const Plasma::DataEngine::Data &data); + void removeSource(const QString &source); void setupData(); Q_SIGNALS: void newData(const QString &sourceName, const Plasma::DataEngine::Data &data); void sourceAdded(const QString &source); + void sourceRemoved(const QString &source); + void sourceConnected(const QString &source); + void sourceDisconnected(const QString &source); void intervalChanged(); void engineChanged(); - void sourceChanged(); void dataChanged(); void connectedSourcesChanged(); void sourcesChanged();