From 1634c62b9a156b59faab4ed89d64c359ba0580f2 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 5 Apr 2016 21:17:37 -0700 Subject: 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 --- qt-models/divelistmodel.cpp | 21 ++++++++++++++++++--- qt-models/divelistmodel.h | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'qt-models') diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp index 79d770853..f0c726fae 100644 --- a/qt-models/divelistmodel.cpp +++ b/qt-models/divelistmodel.cpp @@ -31,13 +31,28 @@ DiveListModel::DiveListModel(QObject *parent) : QAbstractListModel(parent) m_instance = this; } -void DiveListModel::addDive(dive *d) +void DiveListModel::addDive(QListlistOfDives) { - 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() +{ + QListlistOfDives; + 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); diff --git a/qt-models/divelistmodel.h b/qt-models/divelistmodel.h index 39c3497b9..05514ecba 100644 --- a/qt-models/divelistmodel.h +++ b/qt-models/divelistmodel.h @@ -30,7 +30,8 @@ public: static DiveListModel *instance(); DiveListModel(QObject *parent = 0); - void addDive(dive *d); + void addDive(QList listOfDives); + void addAllDives(); void insertDive(int i, DiveObjectHelper *newDive); void removeDive(int i); void removeDiveById(int id); -- cgit v1.2.3-70-g09d2