File indexing completed on 2024-06-23 11:24:41

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <QDateTime>
0007 #include <QJsonObject>
0008 
0009 class Poll
0010 {
0011     Q_GADGET
0012 
0013     Q_PROPERTY(QString id READ id CONSTANT);
0014     Q_PROPERTY(QDateTime expiresAt READ expiresAt CONSTANT);
0015     Q_PROPERTY(bool expired READ expired CONSTANT);
0016     Q_PROPERTY(bool multiple READ multiple CONSTANT);
0017     Q_PROPERTY(int votesCount READ votesCount CONSTANT);
0018     Q_PROPERTY(int votersCount READ votersCount CONSTANT);
0019     Q_PROPERTY(bool voted READ voted CONSTANT);
0020     Q_PROPERTY(QList<int> ownVotes READ ownVotes CONSTANT);
0021     Q_PROPERTY(QList<QVariantMap> options READ options CONSTANT);
0022 
0023 public:
0024     Poll();
0025     explicit Poll(const QJsonObject &json);
0026 
0027     QString id() const;
0028     QDateTime expiresAt() const;
0029     bool expired() const;
0030     bool multiple() const;
0031     int votesCount() const;
0032     int votersCount() const;
0033     bool voted() const;
0034     QList<int> ownVotes() const;
0035     QList<QVariantMap> options() const;
0036 
0037 private:
0038     QString m_id;
0039     QDateTime m_expiresAt;
0040     bool m_expired = false;
0041     bool m_multiple = false;
0042     int m_votesCount = 0;
0043     int m_votersCount = 0;
0044     bool m_voted = false;
0045     QList<int> m_ownVotes;
0046     QList<QVariantMap> m_options;
0047 };
0048 
0049 Q_DECLARE_METATYPE(Poll *)