removed invariant from data() and rowCount(). Performance should be ok now.
authorJohn Kern <johnk@symbian.org>
Thu, 26 Aug 2010 14:34:34 -0700
changeset 40 edc0144719a1
parent 39 3ed811ba9e2e
child 41 b56d7e268634
removed invariant from data() and rowCount(). Performance should be ok now.
contactengine/contactsengine.cpp
contactengine/contactsengine.h
--- a/contactengine/contactsengine.cpp	Thu Aug 26 10:26:51 2010 -0700
+++ b/contactengine/contactsengine.cpp	Thu Aug 26 14:34:34 2010 -0700
@@ -121,6 +121,11 @@
         m_manager = new QContactManager();
     }
 
+    if(this->m_manager && (this->m_manager->error() == QContactManager::NoError ))
+    {
+        this->m_allContacts = this->m_manager->contacts();
+    }
+
     // Show message to the user
     QString msg = QString("Manager %1 created, that has %2 contacts")
                   .arg(m_manager->managerName()).arg(contactIds.count());
@@ -352,7 +357,7 @@
 
 int ContactsEngine::rowCount(const QModelIndex &parent) const
  {
-    return this->m_manager->contacts().count();
+    return this->m_allContacts.count();
  }
 
 void ContactsEngine::enumerateMgrs()
@@ -394,17 +399,16 @@
 QVariant ContactsEngine::data(const QModelIndex &index, int role) const
  {
     QVariant rc;
-    QList<QContact> allContacts;
     QContact c;
 
-    allContacts = this->m_manager->contacts();
+
 
-    if (!index.isValid() || index.row() >= allContacts.size()) {
+    if (!index.isValid() || index.row() >= this->m_allContacts.size()) {
          return rc;
     }
     if (role == Qt::DisplayRole) {
         //rc = QVariant(allContacts.at(index.row()).displayLabel());
-        c = allContacts.at(index.row());
+        c = this->m_allContacts.at(index.row());
         // organizations do not have first and last names.  So the displayLabel() is empty.
         QContactDetail cd = c.detail(QContactName::DefinitionName);
         if (cd.isEmpty()) {
@@ -414,4 +418,4 @@
         }
     }
     return rc;
- }
+}
--- a/contactengine/contactsengine.h	Thu Aug 26 10:26:51 2010 -0700
+++ b/contactengine/contactsengine.h	Thu Aug 26 14:34:34 2010 -0700
@@ -46,6 +46,8 @@
     QPointer<QContactManager> m_manager;
     // this one is simply in memory. Put the Symbian Foundation contacts here.
     QPointer<QContactManager> m_manager_sf;
+    // cache list of all contacts.
+    QList<QContact> m_allContacts;
 };
 
 #endif // CONTACTSENGINE_H