File indexing completed on 2024-02-25 03:50:25

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 <qsortfilterproxymodel.h>
0009 
0010 #include "prefs.h"
0011 
0012 class KWQCardModel;
0013 class KWQSortFilterModel;
0014 
0015 /**
0016   @author Peter Hedlund <peter.hedlund@kdemail.net>
0017 */
0018 class KWQQuizModel : public QAbstractListModel
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     enum QuizIcon {
0024         IconLeftCol, IconRightCol, IconQuestion, IconCorrect, IconError,
0025     };
0026 
0027     explicit KWQQuizModel(QObject *parent = nullptr);
0028 
0029     void setFilterModel(KWQCardModel *sourceModel);
0030     KWQCardModel *sourceModel() const;
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