File indexing completed on 2024-04-21 03:51:07

0001 /*
0002     SPDX-FileCopyrightText: 1999-2001 Ewald Arnold <kvoctrain@ewald-arnold.de>
0003     SPDX-FileCopyrightText: 2005-2007 Peter Hedlund <peter.hedlund@kdemail.net>
0004     SPDX-FileCopyrightText: 2007-2010 Frederik Gladhorn <gladhorn@kde.org>
0005     SPDX-FileCopyrightText: 2014 Inge Wallin <inge@lysator.liu.se>
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef PRACTICESESSIONMANAGERBASE_H
0010 #define PRACTICESESSIONMANAGERBASE_H
0011 
0012 // Qt
0013 #include <QElapsedTimer>
0014 #include <QVector>
0015 // kdeedulibs
0016 #include <KEduVocExpression>
0017 
0018 // Parley
0019 #include "prefs.h"
0020 #include "testentry.h"
0021 
0022 class KEduVocDocument;
0023 
0024 namespace Practice
0025 {
0026 class SessionManagerBase
0027 {
0028 public:
0029     /**
0030      * Create a collection of entries to be practiced.
0031      */
0032     explicit SessionManagerBase(QWidget *parent);
0033 
0034     /**
0035      * destructor
0036      */
0037     virtual ~SessionManagerBase();
0038 
0039     /**
0040      * Prepare for practice using the entries in this document.
0041      *
0042      * The default implementation selects all available entries in the
0043      * document into the list allTestEntries and then calls
0044      * initializeTraining().
0045      */
0046     virtual void setDocument(KEduVocDocument *doc);
0047 
0048     /**
0049      * Initialize the lists of entries that will be used in the
0050      * training from the full set of available entries. Reimplement
0051      * this to create other types of training sessions.
0052      */
0053     virtual void initializeTraining() = 0;
0054 
0055     /**
0056      * Return the title of the document.
0057      */
0058     QString title() const;
0059 
0060     // Should be called when starting and ending the practice session respectively.
0061     // The default implementations only start and stop the practice timer.
0062     virtual void practiceStarted();
0063     virtual void practiceFinished();
0064 
0065     /** the time in seconds */
0066     int totalTime();
0067 
0068     /**
0069      * Get the next entry to show to the user. The default
0070      * implementation refills the active entries up to the max number
0071      * and selects a random entry from them.
0072      *
0073      * @return TestEntry* the next entry to be practiced
0074      */
0075     virtual TestEntry *nextTrainingEntry();
0076 
0077     /** Finish the currently active entry */
0078     virtual void removeCurrentEntryFromPractice();
0079 
0080     /**
0081      * Get a list of all entries in the test - used by the summary dialog
0082      */
0083     QList<TestEntry *> allTestEntries() const;
0084 
0085     /**
0086      * The number of entries available for the practice session.
0087      * This is used for statistics at the end of the session.
0088      * @return
0089      */
0090     int allEntryCount() const;
0091 
0092     /**
0093      * The number of entries that are still to be practiced
0094      * @return
0095      */
0096     int activeEntryCount();
0097 
0098     /**
0099      * Get a list of all unanswered entries in the test
0100      */
0101     QList<TestEntry *> allUnansweredTestEntries();
0102 
0103     // ----------------------------------------------------------------
0104     // Statistics
0105     int statisticTotalCorrectFirstAttempt();
0106     int statisticTotalWrong();
0107     int statisticTotalUnanswered();
0108 
0109     /**
0110      * Puts some grades on the shell
0111      */
0112     void printStatistics();
0113 
0114     QStringList multipleChoiceAnswers(int numberChoices);
0115 
0116     // QString currentConjugationTense();
0117 
0118 protected: // methods
0119     /**
0120      * Find out if the given expression can be used as a multiple choice answer for the current entry
0121      * (i.e. if it's not the answer itself, not a synonym and has a different text)
0122      */
0123     bool isValidMultipleChoiceAnswer(KEduVocExpression *e);
0124 
0125 protected: // data
0126     KEduVocDocument *m_doc{nullptr};
0127     QWidget *m_parent{nullptr};
0128     int m_learningLanguageIndex{0};
0129     int m_knownLanguageIndex{1};
0130     int m_testType{0};
0131 
0132     // ----------------------------------------------------------------
0133     // The following entries define the training
0134 
0135     /// All entries available in the document that fulfill the
0136     /// requirements set in the configuration and the grades in the
0137     /// entries themselves.
0138     QList<TestEntry *> m_allTestEntries;
0139 
0140     /// All entries that have not been entered into the active set.
0141     QList<TestEntry *> m_notAskedTestEntries;
0142 
0143     /// The list of entries that are being asked. If one of these is
0144     /// done, it can be deleted and an new one from
0145     /// m_notAskedTestEntries taken.
0146     QList<TestEntry *> m_currentEntries;
0147 
0148     // The index of the current entry in m_currentEntries.
0149     int m_currentEntry{-1};
0150 
0151     QElapsedTimer m_time;
0152     int m_totalTime{0};
0153 };
0154 
0155 }
0156 
0157 #endif // kvtquery_included