File indexing completed on 2024-12-08 12:55:20
0001 // SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com> 0002 // SPDX-License-Identifier: LGPL-2.1-or-later 0003 0004 #pragma once 0005 0006 #include <QJsonObject> 0007 #include <QObject> 0008 #include <QVariant> 0009 0010 class PollEditorBackend : public QObject 0011 { 0012 Q_OBJECT 0013 0014 Q_PROPERTY(QVariantList options MEMBER m_options NOTIFY optionsChanged) 0015 Q_PROPERTY(bool multipleChoice MEMBER m_multipleChoice NOTIFY multipleChoiceChanged) 0016 Q_PROPERTY(bool hideTotals MEMBER m_hideTotals NOTIFY hideTotalsChanged) 0017 Q_PROPERTY(int expiresIn MEMBER m_expiresIn NOTIFY expiresInChanged) 0018 Q_PROPERTY(bool isValid READ isValid NOTIFY validityChanged) 0019 public: 0020 explicit PollEditorBackend(QObject *parent = nullptr); 0021 0022 Q_INVOKABLE void addOption(); 0023 Q_INVOKABLE void removeOption(int index); 0024 Q_INVOKABLE void setOption(int index, const QString &name); 0025 0026 bool isValid() const; 0027 0028 QJsonObject toJsonObject() const; 0029 0030 Q_SIGNALS: 0031 void optionsChanged(); 0032 void multipleChoiceChanged(); 0033 void hideTotalsChanged(); 0034 void expiresInChanged(); 0035 void validityChanged(); 0036 0037 private: 0038 void checkValidity(); 0039 0040 QVariantList m_options; 0041 bool m_multipleChoice = false; 0042 bool m_hideTotals = false; 0043 int m_expiresIn = 86400; // 1 day 0044 bool m_valid = false; 0045 };