File indexing completed on 2023-05-30 10:45:26
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Peter Hedlund <peter.hedlund@kdemail.net> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef KWQQUIZMODEL_H 0007 #define KWQQUIZMODEL_H 0008 0009 #include <QSortFilterProxyModel> 0010 0011 #include "prefs.h" 0012 0013 /** 0014 @author Peter Hedlund <peter.hedlund@kdemail.net> 0015 */ 0016 0017 class KWQSortFilterModel; 0018 0019 class KWQQuizModel : public QSortFilterProxyModel 0020 { 0021 Q_OBJECT 0022 public: 0023 enum QuizIcon {IconLeftCol, IconRightCol, IconQuestion, IconCorrect, IconError}; 0024 0025 explicit KWQQuizModel(QObject *parent); 0026 0027 void setFilterModel(KWQSortFilterModel * sourceModel); 0028 KWQSortFilterModel * sourceModel() const; 0029 0030 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0031 0032 bool init(); 0033 0034 void activateErrorList(); 0035 void activateBaseList(); 0036 0037 void finish(); 0038 void toNext(); 0039 bool atEnd(); 0040 bool checkAnswer(const QString & ); 0041 bool hasErrors(); 0042 QStringList multiOptions(); 0043 QString quizIcon(QuizIcon ico); 0044 QString yourAnswer(const QString &) const; 0045 QString hint(); 0046 0047 Prefs::EnumStartSession::type quizType() const {return m_quizType;} 0048 void setQuizType(Prefs::EnumStartSession::type qt); 0049 0050 int quizMode() const {return m_quizMode;} 0051 void setQuizMode(int qm); 0052 0053 int questionCount(); 0054 QString question(); 0055 QString blankAnswer(); 0056 QString answer(); 0057 QString langQuestion(); 0058 QString langAnswer(); 0059 QPixmap imageQuestion(); 0060 QPixmap imageAnswer(); 0061 QUrl soundQuestion(); 0062 QUrl soundAnswer(); 0063 0064 QString kbAnswer(); 0065 0066 QList<int> errorList() const {return m_errorList;} 0067 void removeLastError(); 0068 0069 Q_SIGNALS: 0070 void checkingAnswer(int ); 0071 0072 protected: 0073 bool lessThan(const QModelIndex & left, const QModelIndex & right) const override; 0074 0075 // Disable from external calls; use setFilterModel() instead 0076 // (It's not even implemented so will give a link error anyway.) 0077 //void setSourceModel(QAbstractItemModel * sourceModel); 0078 0079 private: 0080 KWQSortFilterModel * m_sourceModel; 0081 0082 QList<int> m_list; 0083 QList<int> m_errorList; 0084 QList<int> m_quizList; 0085 0086 int m_quizMode; 0087 int m_currentQuestion; 0088 int m_questionCount; 0089 0090 Prefs::EnumStartSession::type m_quizType; 0091 QString m_correctBlank; 0092 QString m_answerBlank; 0093 0094 bool isOdd(int ) const; 0095 int column(int ); 0096 }; 0097 0098 #endif // KWQQUIZMODEL_H