mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
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:
parent
8fe068f191
commit
6ed807f52d
3 changed files with 13 additions and 1 deletions
|
@ -29,12 +29,14 @@ void MapWidgetHelper::reloadMapLocations()
|
|||
struct dive_site *ds;
|
||||
int idx;
|
||||
m_mapLocationModel->clear();
|
||||
QList<MapLocation *> locationList;
|
||||
|
||||
for_each_dive_site(idx, ds) {
|
||||
if (!dive_site_has_gps_location(ds))
|
||||
continue;
|
||||
const qreal longitude = ds->longitude.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);
|
||||
}
|
||||
|
|
|
@ -68,6 +68,15 @@ void MapLocationModel::add(MapLocation *location)
|
|||
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()
|
||||
{
|
||||
if (!m_mapLocations.size())
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
int rowCount(const QModelIndex &parent) const override;
|
||||
int count();
|
||||
void add(MapLocation *);
|
||||
void addList(QList<MapLocation *>);
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Add table
Reference in a new issue