File indexing completed on 2024-10-13 04:31:43
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 0008 class PollEditorBackend : public QObject 0009 { 0010 Q_OBJECT 0011 0012 Q_PROPERTY(QVariantList options MEMBER m_options NOTIFY optionsChanged) 0013 Q_PROPERTY(bool multipleChoice MEMBER m_multipleChoice NOTIFY multipleChoiceChanged) 0014 Q_PROPERTY(bool hideTotals MEMBER m_hideTotals NOTIFY hideTotalsChanged) 0015 Q_PROPERTY(int expiresIn MEMBER m_expiresIn NOTIFY expiresInChanged) 0016 Q_PROPERTY(bool isValid READ isValid NOTIFY validityChanged) 0017 0018 public: 0019 explicit PollEditorBackend(QObject *parent = nullptr); 0020 0021 Q_INVOKABLE void addOption(); 0022 Q_INVOKABLE void removeOption(int index); 0023 Q_INVOKABLE void setOption(int index, const QString &name); 0024 0025 bool isValid() const; 0026 0027 QJsonObject toJsonObject() const; 0028 0029 Q_SIGNALS: 0030 void optionsChanged(); 0031 void multipleChoiceChanged(); 0032 void hideTotalsChanged(); 0033 void expiresInChanged(); 0034 void validityChanged(); 0035 0036 private: 0037 void checkValidity(); 0038 0039 QVariantList m_options; 0040 bool m_multipleChoice = false; 0041 bool m_hideTotals = false; 0042 int m_expiresIn = 86400; // 1 day 0043 bool m_valid = false; 0044 };