maplocationmodel: add the addList() method

This method should be used if many markers are added at once.
It's main purpose is to reduces the number of beingInsertRows()
calls.

Make MapWidgetHelper::reloadMapLocations() use it.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
This commit is contained in:
Lubomir I. Ivanov 2017-07-17 22:59:14 +03:00 committed by Dirk Hohndel
parent 8fe068f191
commit 6ed807f52d
3 changed files with 13 additions and 1 deletions

View file

@ -29,12 +29,14 @@ void MapWidgetHelper::reloadMapLocations()
struct dive_site *ds; struct dive_site *ds;
int idx; int idx;
m_mapLocationModel->clear(); m_mapLocationModel->clear();
QList<MapLocation *> locationList;
for_each_dive_site(idx, ds) { for_each_dive_site(idx, ds) {
if (!dive_site_has_gps_location(ds)) if (!dive_site_has_gps_location(ds))
continue; continue;
const qreal longitude = ds->longitude.udeg / 1000000.0; const qreal longitude = ds->longitude.udeg / 1000000.0;
const qreal latitude = ds->latitude.udeg / 1000000.0; const qreal latitude = ds->latitude.udeg / 1000000.0;
m_mapLocationModel->add(new MapLocation(QGeoCoordinate(latitude, longitude))); locationList.append(new MapLocation(QGeoCoordinate(latitude, longitude)));
} }
m_mapLocationModel->addList(locationList);
} }

View file

@ -68,6 +68,15 @@ void MapLocationModel::add(MapLocation *location)
endInsertRows(); endInsertRows();
} }
void MapLocationModel::addList(QList<MapLocation *> list)
{
if (!list.size())
return;
beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size() + list.size() - 1);
m_mapLocations.append(list);
endInsertRows();
}
void MapLocationModel::clear() void MapLocationModel::clear()
{ {
if (!m_mapLocations.size()) if (!m_mapLocations.size())

View file

@ -43,6 +43,7 @@ public:
int rowCount(const QModelIndex &parent) const override; int rowCount(const QModelIndex &parent) const override;
int count(); int count();
void add(MapLocation *); void add(MapLocation *);
void addList(QList<MapLocation *>);
void clear(); void clear();
protected: protected: