From 200acb76602e839f8ea86b196e795c3f61a8d3ed Mon Sep 17 00:00:00 2001 From: Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com> Date: Fri, 5 May 2017 11:09:08 -0400 Subject: [PATCH] RecentModel: move Calls from CM to Person MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make sure child Calls of a ContactMethod node are moved to the Person node when a Person node replaces a CM node. This should prevent two bugs. One is Calls not appearing in the smart list. The second is the model not properly signaling the tree view about the child rows moving. Change-Id: Ibff9186e8494d930726ccb0e8a0e61d2119bc315 Reviewed-by: Nicolas Jäger <nicolas.jager@savoirfairelinux.com> --- src/recentmodel.cpp | 59 ++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/recentmodel.cpp b/src/recentmodel.cpp index 9899e4f7..95649d84 100644 --- a/src/recentmodel.cpp +++ b/src/recentmodel.cpp @@ -712,15 +712,25 @@ void RecentModelPrivate::removeNode(RecentViewNode* n) void RecentModelPrivate::slotPersonAdded(const Person* p) { - if (p) { - // prevent person duplication by checking if the contact method - // is already present in m_hCMsToNodes - for ( const auto cmToRm : p->phoneNumbers() ) - if ( auto cmNode = m_hCMsToNodes.take(cmToRm) ) - removeNode(cmNode); - - slotLastUsedTimeChanged(p, p->lastUsedTime()); - } + if (!p) return; + // make sure the Person node exists first, then move any children of the CM nodes + slotLastUsedTimeChanged(p, p->lastUsedTime()); + + for ( const auto contactMethod : p->phoneNumbers() ) { + if ( auto oldParentNode = m_hCMsToNodes.take(contactMethod) ) { + // move any child nodes (Calls) to new Person + if (auto newParentNode = m_hPersonsToNodes.value(p)) { + // we need to make a copy of the container since we're modifying it + const auto callListCopy = oldParentNode->m_lChildren; + for (const auto &callNode : callListCopy) { + moveCallNode(newParentNode, callNode); + } + removeNode(oldParentNode); + } else { + qWarning("RecentModel: ContactMethod has new Person, but corresponding Person node doesn't exist"); + } + } + } } void RecentModelPrivate::slotPersonRemoved(const Person* p) @@ -775,25 +785,24 @@ void RecentModelPrivate::slotLastUsedChanged(ContactMethod* cm, time_t t) ///Remove the contact method once they are associated with a contact void RecentModelPrivate::slotContactChanged(ContactMethod* cm, Person* np, Person* op) { + if (!np->phoneNumbers().contains(cm)) + qWarning() << "CM has new Person parent, but is not contained in its list of CMs"; + + // TODO: implement for when the Person of the CM changes, ie: op != nullptr Q_UNUSED(op) // m_hCMsToNodes contains RecentViewNode pointers, take will return a default // constructed ptr (e.g nullptr) if key is not in the QHash - if (auto n = m_hCMsToNodes.take(cm)) { - // remove its child calls from the list first, they will be destroyed when the call is over - auto newParentNode = np != nullptr ? m_hPersonsToNodes[np] : nullptr; - Q_FOREACH(auto cmNode, n->m_lChildren) { - if (newParentNode) { - cmNode->m_pParent = newParentNode; - newParentNode->m_lChildren.append(cmNode); - } else - cmNode->m_pParent = nullptr; - } - - n->m_lChildren.clear(); - removeNode(n); - - if (newParentNode && newParentNode->m_lChildren.size()) { - selectNode(newParentNode); + if (auto oldParentNode = m_hCMsToNodes.take(cm)) { + // move any child nodes (Calls) to new Person + if (auto newParentNode = m_hPersonsToNodes.value(np)) { + // we need to make a copy of the container since we're modifying it + const auto callListCopy = oldParentNode->m_lChildren; + for (const auto &callNode : callListCopy) { + moveCallNode(newParentNode, callNode); + } + removeNode(oldParentNode); + } else { + qWarning("RecentModel: ContactMethod has new Person, but corresponding Person node doesn't exist"); } } } -- GitLab