Compute live location bounding box and center the map accordingly
This commit is contained in:
@@ -38,6 +38,9 @@ LiveLocationsModel::LiveLocationsModel(QObject *parent)
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
Qt::QueuedConnection); // deferred so we are sure the eventId filter is set
|
Qt::QueuedConnection); // deferred so we are sure the eventId filter is set
|
||||||
|
|
||||||
|
connect(this, &LiveLocationsModel::dataChanged, this, &LiveLocationsModel::boundingBoxChanged);
|
||||||
|
connect(this, &LiveLocationsModel::rowsInserted, this, &LiveLocationsModel::boundingBoxChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LiveLocationsModel::rowCount(const QModelIndex &parent) const
|
int LiveLocationsModel::rowCount(const QModelIndex &parent) const
|
||||||
@@ -101,6 +104,21 @@ QHash<int, QByteArray> LiveLocationsModel::roleNames() const
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QRectF LiveLocationsModel::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;
|
||||||
|
}
|
||||||
|
|
||||||
void LiveLocationsModel::addEvent(const Quotient::RoomEvent *event)
|
void LiveLocationsModel::addEvent(const Quotient::RoomEvent *event)
|
||||||
{
|
{
|
||||||
if (event->isStateEvent() && event->matrixType() == "org.matrix.msc3672.beacon_info") {
|
if (event->isStateEvent() && event->matrixType() == "org.matrix.msc3672.beacon_info") {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QRectF>
|
||||||
|
|
||||||
namespace Quotient
|
namespace Quotient
|
||||||
{
|
{
|
||||||
@@ -36,6 +37,9 @@ class LiveLocationsModel : public QAbstractListModel
|
|||||||
*/
|
*/
|
||||||
Q_PROPERTY(QString eventId MEMBER m_eventId NOTIFY eventIdChanged)
|
Q_PROPERTY(QString eventId MEMBER m_eventId NOTIFY eventIdChanged)
|
||||||
|
|
||||||
|
/** Bounding box of all live location beacons covered by this model. */
|
||||||
|
Q_PROPERTY(QRectF boundingBox READ boundingBox NOTIFY boundingBoxChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit LiveLocationsModel(QObject *parent = nullptr);
|
explicit LiveLocationsModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
@@ -52,9 +56,12 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int roleName) const override;
|
QVariant data(const QModelIndex &index, int roleName) const override;
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
QRectF boundingBox() const;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void roomChanged();
|
void roomChanged();
|
||||||
void eventIdChanged();
|
void eventIdChanged();
|
||||||
|
void boundingBoxChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addEvent(const Quotient::RoomEvent *event);
|
void addEvent(const Quotient::RoomEvent *event);
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ TimelineContainer {
|
|||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: root.contentMaxWidth / 16 * 9
|
Layout.preferredHeight: root.contentMaxWidth / 16 * 9
|
||||||
|
|
||||||
// center: QtPositioning.coordinate(root.latitude, root.longitude)
|
center: QtPositioning.coordinate(liveLocationModel.boundingBox.y, liveLocationModel.boundingBox.x)
|
||||||
// zoomLevel: 15
|
zoomLevel: 15
|
||||||
|
|
||||||
plugin: OsmLocationPlugin.plugin
|
plugin: OsmLocationPlugin.plugin
|
||||||
onCopyrightLinkActivated: Qt.openUrlExternally(link)
|
onCopyrightLinkActivated: Qt.openUrlExternally(link)
|
||||||
|
|||||||
Reference in New Issue
Block a user