From 50d794c2ac488ec1f6d79ade67a3c39c2d3d8a35 Mon Sep 17 00:00:00 2001 From: Chris Adams Date: Tue, 16 Apr 2019 16:08:53 +1000 Subject: [PATCH] [libcontacts] Force models to reload data upon receiving dataChanged. Contributes to JB#44742 The qtcontacts-sqlite backend will emit dataChanged() when the group property changes and it updates its internal data structures accordingly. This commit ensures that when this signal is received by libcontacts, it will force all models to update all source data, to ensure that the group labels are updated appropriately. --- src/seasidecache.cpp | 41 +++++++++++++++++------------------------ src/seasidecache.h | 3 +-- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/seasidecache.cpp b/src/seasidecache.cpp index f111e1c..49dfc72 100644 --- a/src/seasidecache.cpp +++ b/src/seasidecache.cpp @@ -564,7 +564,6 @@ SeasideCache::SeasideCache() connect(config, SIGNAL(displayLabelOrderChanged(CacheConfiguration::DisplayLabelOrder)), this, SLOT(displayLabelOrderChanged(CacheConfiguration::DisplayLabelOrder))); connect(config, SIGNAL(sortPropertyChanged(QString)), this, SLOT(sortPropertyChanged(QString))); - connect(config, SIGNAL(groupPropertyChanged(QString)), this, SLOT(groupPropertyChanged(QString))); // Is this a GUI application? If so, we want to defer some processing when the display is off if (qApp && qApp->property("applicationDisplayName").isValid()) { @@ -585,7 +584,7 @@ SeasideCache::SeasideCache() this, SLOT(displayLabelGroupsChanged(QStringList))); displayLabelGroupsChanged(cme->displayLabelGroups()); - connect(mgr, SIGNAL(dataChanged()), this, SLOT(updateContacts())); + connect(mgr, SIGNAL(dataChanged()), this, SLOT(dataChanged())); connect(mgr, SIGNAL(contactsAdded(QList)), this, SLOT(contactsAdded(QList))); connect(mgr, SIGNAL(contactsChanged(QList)), @@ -2025,7 +2024,7 @@ void SeasideCache::contactsRemoved(const QList &ids) requestUpdate(); } -void SeasideCache::updateContacts() +void SeasideCache::dataChanged() { QList contactIds; @@ -2036,6 +2035,21 @@ void SeasideCache::updateContacts() } updateContacts(contactIds, &m_changedContacts); + + // The backend will automatically update, but notify the models of the change. + for (int i = 0; i < FilterTypesCount; ++i) { + const QList &models = m_models[i]; + for (int j = 0; j < models.count(); ++j) { + ListModel *model = models.at(j); + model->updateGroupProperty(); + model->sourceItemsChanged(); + model->sourceDataChanged(0, m_contacts[i].size()); + } + } + + // Update the sorted list order + m_refreshRequired = true; + requestUpdate(); } void SeasideCache::fetchContacts() @@ -2935,27 +2949,6 @@ void SeasideCache::sortPropertyChanged(const QString &sortProperty) requestUpdate(); } -void SeasideCache::groupPropertyChanged(const QString &) -{ - // It is unfortunate that this is required at all! - // Maybe handling for this could be added to dataChanged() - // instead? TODO: investigate that possibility. - - // The backend will automatically update, but notify the models of the change. - for (int i = 0; i < FilterTypesCount; ++i) { - const QList &models = m_models[i]; - for (int j = 0; j < models.count(); ++j) { - ListModel *model = models.at(j); - model->updateGroupProperty(); - model->sourceItemsChanged(); - } - } - - // Update the sorted list order - m_refreshRequired = true; - requestUpdate(); -} - void SeasideCache::displayStatusChanged(const QString &status) { const bool off = (status == QLatin1String(MCE_DISPLAY_OFF_STRING)); diff --git a/src/seasidecache.h b/src/seasidecache.h index af94380..23db869 100644 --- a/src/seasidecache.h +++ b/src/seasidecache.h @@ -345,7 +345,7 @@ private slots: void relationshipsAvailable(); void requestStateChanged(QContactAbstractRequest::State state); void addressRequestStateChanged(QContactAbstractRequest::State state); - void updateContacts(); + void dataChanged(); void contactsAdded(const QList &contactIds); void contactsChanged(const QList &contactIds); void contactsPresenceChanged(const QList &contactIds); @@ -353,7 +353,6 @@ private slots: void displayLabelGroupsChanged(const QStringList &groups); void displayLabelOrderChanged(CacheConfiguration::DisplayLabelOrder order); void sortPropertyChanged(const QString &sortProperty); - void groupPropertyChanged(const QString &groupProperty); void displayStatusChanged(const QString &); private: