Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/plugins/mergecontactswidget.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Line(s) | 93 | Q_FOREACH (const QPersistentModelIndex &duplicate, duplicates) { | |||
---|---|---|---|---|---|
110 | m_containerListDetails->layout()->addWidget(myMergeContactWidget); | 110 | m_containerListDetails->layout()->addWidget(myMergeContactWidget); | ||
111 | m_listMergeContacts.append(qMakePair(duplicate, myMergeContactWidget)); | 111 | m_listMergeContacts.append(qMakePair(duplicate, myMergeContactWidget)); | ||
112 | } | 112 | } | ||
113 | } | 113 | } | ||
114 | 114 | | |||
115 | QList<QPersistentModelIndex> MergeContactsWidget::duplicateBusterFromPerson(const QUrl &uri) const | 115 | QList<QPersistentModelIndex> MergeContactsWidget::duplicateBusterFromPerson(const QUrl &uri) const | ||
116 | { | 116 | { | ||
117 | Q_ASSERT(m_duplicatesBuster); | 117 | Q_ASSERT(m_duplicatesBuster); | ||
118 | QList<Match> wrongFormatResults = m_duplicatesBuster->results(); | 118 | const QList<Match> wrongFormatResults = m_duplicatesBuster->results(); | ||
119 | QList<QPersistentModelIndex> duplicateMatching; | 119 | QList<QPersistentModelIndex> duplicateMatching; | ||
120 | 120 | | |||
121 | Q_FOREACH (const Match &match, wrongFormatResults) { | 121 | for (const Match &match : wrongFormatResults) { | ||
122 | // pick up only the couple with match with our parameter index | 122 | // pick up only the couple with match with our parameter index | ||
123 | QUrl uriA = match.indexA.data(PersonsModel::UriRole).toUrl(); | 123 | QUrl uriA = match.indexA.data(PersonsModel::UriRole).toUrl(); | ||
124 | 124 | | |||
125 | // Tested with URI because QModelIndex isn't reliable | 125 | // Tested with URI because QModelIndex isn't reliable | ||
126 | if (uriA == uri) { | 126 | if (uriA == uri) { | ||
127 | duplicateMatching.append(match.indexB); | 127 | duplicateMatching.append(match.indexB); | ||
128 | } | 128 | } | ||
129 | QUrl uriB = match.indexB.data(PersonsModel::UriRole).toUrl(); | 129 | QUrl uriB = match.indexB.data(PersonsModel::UriRole).toUrl(); | ||
Show All 34 Lines | |||||
164 | 164 | | |||
165 | void MergeContactsWidget::onMergeButtonPressed() | 165 | void MergeContactsWidget::onMergeButtonPressed() | ||
166 | { | 166 | { | ||
167 | // Retrieve the selected contacts | 167 | // Retrieve the selected contacts | ||
168 | QList<QUrl> urisToMerge; | 168 | QList<QUrl> urisToMerge; | ||
169 | urisToMerge << m_person->uri(); | 169 | urisToMerge << m_person->uri(); | ||
170 | 170 | | |||
171 | // do the merge | 171 | // do the merge | ||
172 | Q_FOREACH (const QPersistentModelIndex &pIndex, getContactsCheckedToMerge()) { | 172 | const auto lst = getContactsCheckedToMerge(); | ||
173 | for (const QPersistentModelIndex &pIndex : lst) { | ||||
173 | urisToMerge << pIndex.data(PersonsModel::UriRole).toUrl(); | 174 | urisToMerge << pIndex.data(PersonsModel::UriRole).toUrl(); | ||
174 | } | 175 | } | ||
175 | m_model->createPersonFromUris(urisToMerge); | 176 | m_model->createPersonFromUris(urisToMerge); | ||
176 | searchForDuplicates(); | 177 | searchForDuplicates(); | ||
177 | } | 178 | } | ||
178 | 179 | | |||
179 | QList<QPersistentModelIndex> MergeContactsWidget::getContactsCheckedToMerge() const | 180 | QList<QPersistentModelIndex> MergeContactsWidget::getContactsCheckedToMerge() const | ||
180 | { | 181 | { | ||
181 | QList<QPersistentModelIndex> indexesToMerge; | 182 | QList<QPersistentModelIndex> indexesToMerge; | ||
182 | 183 | | |||
183 | // retrieve all the widget where the box is checked | 184 | // retrieve all the widget where the box is checked | ||
184 | QPair<QPersistentModelIndex, PersonPresentationWidget *> mergeContact ; | 185 | for (QPair<QPersistentModelIndex, PersonPresentationWidget *> mergeContact : qAsConst(m_listMergeContacts)) { | ||
dfaure: const & would be even better.
(It'll get lengthy, so this might be a reason to switch for… | |||||
185 | Q_FOREACH (mergeContact, m_listMergeContacts) { | | |||
186 | if (mergeContact.second->isContactSelected()) { | 186 | if (mergeContact.second->isContactSelected()) { | ||
187 | indexesToMerge.append(mergeContact.first); | 187 | indexesToMerge.append(mergeContact.first); | ||
188 | } | 188 | } | ||
189 | } | 189 | } | ||
190 | qCDebug(KPEOPLE_LOG) << "Amount of checked box enable :" << indexesToMerge.size(); | 190 | qCDebug(KPEOPLE_LOG) << "Amount of checked box enable :" << indexesToMerge.size(); | ||
191 | return indexesToMerge; | 191 | return indexesToMerge; | ||
192 | } | 192 | } |
const & would be even better.
(It'll get lengthy, so this might be a reason to switch for const auto & here, although some might object that the type isn't visible in the code here)