File indexing completed on 2024-10-06 03:31:31
0001 // SPDX-FileCopyrightText: 2006-2010 Peter Hedlund <peter.hedlund@kdemail.net> 0002 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu> 0003 // SPDX-License-Identifier: GPL-2.0-or-later 0004 0005 #pragma once 0006 0007 #include <QAbstractListModel> 0008 #include <keduvocdocument.h> 0009 0010 /// @author Carl Schwan <carl@carlschwan.eu> 0011 class KWQCardModel : public QAbstractListModel 0012 { 0013 Q_OBJECT 0014 Q_PROPERTY(KEduVocDocument *document READ document WRITE setDocument NOTIFY documentChanged) 0015 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0016 Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged) 0017 Q_PROPERTY(QString authorContact READ authorContact WRITE setAuthorContact NOTIFY authorContactChanged) 0018 Q_PROPERTY(QString license READ license WRITE setLicense NOTIFY licenseChanged) 0019 Q_PROPERTY(bool enabled READ enabled NOTIFY enabledChanged) 0020 0021 Q_PROPERTY(QString identifierLeft READ identifierLeft WRITE setIdentifierLeft NOTIFY identifierLeftChanged) 0022 Q_PROPERTY(QString identifierRight READ identifierRight WRITE setIdentifierRight NOTIFY identifierRightChanged) 0023 0024 Q_PROPERTY(QString langQuestion READ langQuestion WRITE setLangQuestion NOTIFY langQuestionChanged) 0025 Q_PROPERTY(QString langAnswer READ langAnswer WRITE setLangAnswer NOTIFY langAnswerChanged) 0026 Q_PROPERTY(bool multipleChoiceAvailable READ multipleChoiceAvailable NOTIFY multipleChoiceAvailableChanged) 0027 0028 public: 0029 enum ExtraRoles { 0030 QuestionRole = Qt::DisplayRole + 1, 0031 QuestionImageRole, 0032 QuestionSoundRole, 0033 0034 AnswerRole, 0035 AnswerImageRole, 0036 AnswerSoundRole, 0037 0038 ExtraUserRoles, 0039 }; 0040 Q_ENUMS(ExtraRoles) 0041 0042 explicit KWQCardModel(QObject *parent = nullptr); 0043 0044 bool enabled() const; 0045 0046 KEduVocDocument *document() const; 0047 void setDocument(KEduVocDocument *document); 0048 0049 QString title() const; 0050 void setTitle(const QString &title); 0051 0052 QString author() const; 0053 void setAuthor(const QString &author); 0054 0055 QString authorContact() const; 0056 void setAuthorContact(const QString &authorContact); 0057 0058 QString license() const; 0059 void setLicense(const QString &license); 0060 0061 QString identifierLeft() const; 0062 void setIdentifierLeft(const QString &identifierLeft); 0063 0064 QString identifierRight() const; 0065 void setIdentifierRight(const QString &identifierRight); 0066 0067 QString langQuestion() const; 0068 void setLangQuestion(const QString &langQuestion); 0069 0070 QString langAnswer() const; 0071 void setLangAnswer(const QString &langAnswer); 0072 0073 bool multipleChoiceAvailable() const; 0074 0075 int rowCount(const QModelIndex &parent = {}) const override; 0076 QVariant data(const QModelIndex &index, int role) const override; 0077 QHash<int, QByteArray> roleNames() const override; 0078 0079 Q_INVOKABLE void createNew(); 0080 Q_INVOKABLE void add(const QString &question, const QString &answer); 0081 Q_INVOKABLE void edit(const int row, const QString &question, const QString &answer); 0082 0083 Q_INVOKABLE void addQuestionImage(const int row, const QUrl &url); 0084 Q_INVOKABLE void addAnswerImage(const int row, const QUrl &url); 0085 0086 Q_INVOKABLE void removeQuestionImage(const int row); 0087 Q_INVOKABLE void removeAnswerImage(const int row); 0088 0089 Q_INVOKABLE void addQuestionSound(const int row, const QUrl &url); 0090 Q_INVOKABLE void addAnswerSound(const int row, const QUrl &url); 0091 0092 Q_INVOKABLE void removeQuestionSound(const int row); 0093 Q_INVOKABLE void removeAnswerSound(const int row); 0094 0095 Q_INVOKABLE bool save(); 0096 0097 Q_SIGNALS: 0098 void enabledChanged(); 0099 void documentChanged(); 0100 void titleChanged(); 0101 void authorChanged(); 0102 void authorContactChanged(); 0103 void licenseChanged(); 0104 void identifierLeftChanged(); 0105 void identifierRightChanged(); 0106 void langQuestionChanged(); 0107 void langAnswerChanged(); 0108 void multipleChoiceAvailableChanged(); 0109 0110 /// Triggered when the document was edited. 0111 void reloaded(); 0112 0113 private: 0114 KEduVocDocument *m_document = nullptr; 0115 };