Add bounding box property for LocationsModel as well
Needed to property position the room map.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <QAbstractListModel>
|
||||
#include <QPointer>
|
||||
#include <QRectF>
|
||||
|
||||
#include "neochatroom.h"
|
||||
|
||||
@@ -24,18 +25,23 @@ public:
|
||||
};
|
||||
Q_ENUM(Roles)
|
||||
Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged)
|
||||
/** Bounding box of all locations covered by this model. */
|
||||
Q_PROPERTY(QRectF boundingBox READ boundingBox NOTIFY boundingBoxChanged)
|
||||
|
||||
explicit LocationsModel(QObject *parent = nullptr);
|
||||
|
||||
[[nodiscard]] NeoChatRoom *room() const;
|
||||
void setRoom(NeoChatRoom *room);
|
||||
|
||||
QRectF boundingBox() const;
|
||||
|
||||
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
|
||||
[[nodiscard]] QVariant data(const QModelIndex &index, int roleName) const override;
|
||||
[[nodiscard]] int rowCount(const QModelIndex &parent) const override;
|
||||
[[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void roomChanged();
|
||||
void boundingBoxChanged();
|
||||
|
||||
private:
|
||||
QPointer<NeoChatRoom> m_room;
|
||||
|
||||
Reference in New Issue
Block a user