DiveListModel: don't add the dives one at a time

Most of the time we are adding all the dives, so do this in a single model
operation. This makes the case when adding a single dive (in the undo delete
function) slightly more complicated, but that seems totally worth it for the
speedup in the common case.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-04-05 21:17:37 -07:00
parent f16a3a1709
commit 1634c62b9a
3 changed files with 30 additions and 24 deletions

View file

@ -31,13 +31,28 @@ DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent)
m_instance = this;
}
void DiveListModel::addDive(dive *d)
void DiveListModel::addDive(QList<dive *>listOfDives)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_dives.append(new DiveObjectHelper(d));
if (listOfDives.isEmpty())
return;
beginInsertRows(QModelIndex(), rowCount(), rowCount() + listOfDives.count() - 1);
foreach (dive *d, listOfDives) {
m_dives.append(new DiveObjectHelper(d));
}
endInsertRows();
}
void DiveListModel::addAllDives()
{
QList<dive *>listOfDives;
int i;
struct dive *d;
for_each_dive (i, d)
listOfDives.append(d);
addDive(listOfDives);
}
void DiveListModel::insertDive(int i, DiveObjectHelper *newDive)
{
beginInsertRows(QModelIndex(), i, i);