Add bounding box property for LocationsModel as well

Needed to property position the room map.
This commit is contained in:
Volker Krause
2023-06-18 11:07:24 +02:00
parent c06e69931a
commit a3b8168744
2 changed files with 24 additions and 1 deletions

View File

@@ -41,6 +41,8 @@ LocationsModel::LocationsModel(QObject *parent)
}
});
});
connect(this, &LocationsModel::rowsInserted, this, &LocationsModel::boundingBoxChanged);
}
void LocationsModel::addLocation(const RoomMessageEvent *event)
@@ -110,3 +112,18 @@ int LocationsModel::rowCount(const QModelIndex &parent) const
{
return m_locations.size();
}
QRectF LocationsModel::boundingBox() const
{
QRectF bbox(QPointF(180.0, 90.0), QPointF(-180.0, -90.0));
for (auto i = 0; i < rowCount(); ++i) {
const auto lat = data(index(i, 0), LatitudeRole).toDouble();
const auto lon = data(index(i, 0), LongitudeRole).toDouble();
bbox.setLeft(std::min(bbox.left(), lon));
bbox.setRight(std::max(bbox.right(), lon));
bbox.setTop(std::min(bbox.top(), lat));
bbox.setBottom(std::max(bbox.bottom(), lat));
}
return bbox;
}