propagate with signal sources removal, connection and disconnection

svn path=/trunk/KDE/kdebase/runtime/; revision=1194425
This commit is contained in:
Marco Martin 2010-11-08 23:07:25 +00:00
parent 6165b3cf6e
commit 29f4ac0d99
4 changed files with 26 additions and 6 deletions

View File

@ -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 ||

View File

@ -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;

View File

@ -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();
}

View File

@ -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();