aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@qt.io>2016-11-17 22:50:17 +0100
committerJ-P Nurmi <jpnurmi@qt.io>2016-11-17 21:55:22 +0000
commit24135738e48464d5ca633fd5dc304f006fbfe5c1 (patch)
tree1a08fa102cf750b338f92543bd6c636dfe067abe
parentbd3cb530795a6233024166a81518c5cde1e62273 (diff)
Contact List: fix model insertion
New contacts must be inserted in alphabetical order so the sections stay sane. Change-Id: I39279bbeb429198b38a2b4da1d76eb50bfab723c Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
-rw-r--r--examples/quickcontrols2/contactlist/contactmodel.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/examples/quickcontrols2/contactlist/contactmodel.cpp b/examples/quickcontrols2/contactlist/contactmodel.cpp
index 3252c80a..1f435a56 100644
--- a/examples/quickcontrols2/contactlist/contactmodel.cpp
+++ b/examples/quickcontrols2/contactlist/contactmodel.cpp
@@ -104,10 +104,12 @@ void ContactModel::updateContact(int row,
m_contacts.replace(row, { fullName, address, city, number });
dataChanged(index(row, 0), index(row, 0), { FullNameRole, AddressRole, CityRole, NumberRole });
} else if (row < 0) {
- beginInsertRows(QModelIndex(), rowCount() - 1, rowCount() - 1);
- m_contacts.append({fullName, address, city, number});
+ row = 0;
+ while (row < m_contacts.count() && fullName > m_contacts.at(row).fullName)
+ ++row;
+ beginInsertRows(QModelIndex(), row, row);
+ m_contacts.insert(row, {fullName, address, city, number});
endInsertRows();
- dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), { FullNameRole, AddressRole, CityRole, NumberRole });
}
}