File indexing completed on 2024-12-01 07:40:34
0001 // SPDX-FileCopyrightText: 2023 Tobias Fella <tobias.fella@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include <QAbstractListModel> 0007 #include <QPointer> 0008 #include <QQmlEngine> 0009 #include <QRectF> 0010 0011 #include "neochatroom.h" 0012 0013 #include <Quotient/events/roommessageevent.h> 0014 #include <Quotient/user.h> 0015 0016 class LocationsModel : public QAbstractListModel 0017 { 0018 Q_OBJECT 0019 QML_ELEMENT 0020 0021 public: 0022 enum Roles { 0023 TextRole = Qt::DisplayRole, 0024 LongitudeRole, 0025 LatitudeRole, 0026 AssetRole, 0027 AuthorRole, 0028 }; 0029 Q_ENUM(Roles) 0030 Q_PROPERTY(NeoChatRoom *room READ room WRITE setRoom NOTIFY roomChanged) 0031 /** Bounding box of all locations covered by this model. */ 0032 Q_PROPERTY(QRectF boundingBox READ boundingBox NOTIFY boundingBoxChanged) 0033 0034 explicit LocationsModel(QObject *parent = nullptr); 0035 0036 [[nodiscard]] NeoChatRoom *room() const; 0037 void setRoom(NeoChatRoom *room); 0038 0039 QRectF boundingBox() const; 0040 0041 [[nodiscard]] QHash<int, QByteArray> roleNames() const override; 0042 [[nodiscard]] QVariant data(const QModelIndex &index, int roleName) const override; 0043 [[nodiscard]] int rowCount(const QModelIndex &parent = {}) const override; 0044 0045 Q_SIGNALS: 0046 void roomChanged(); 0047 void boundingBoxChanged(); 0048 0049 protected: 0050 bool event(QEvent *event) override; 0051 0052 private: 0053 QPointer<NeoChatRoom> m_room; 0054 0055 struct LocationData { 0056 QString eventId; 0057 float latitude; 0058 float longitude; 0059 QJsonObject content; 0060 Quotient::User *author; 0061 }; 0062 QList<LocationData> m_locations; 0063 void addLocation(const Quotient::RoomMessageEvent *event); 0064 };