File indexing completed on 2024-04-21 03:50:58

0001 /*
0002     SPDX-FileCopyrightText: 2008 Frederik Gladhorn <frederik.gladhorn@kdemail.net>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef ENTRYFILTER_H
0007 #define ENTRYFILTER_H
0008 
0009 #include <QList>
0010 #include <QSet>
0011 #include <prefs.h>
0012 
0013 class KEduVocText;
0014 class KEduVocTranslation;
0015 class KEduVocExpression;
0016 class KEduVocDocument;
0017 class TestEntry;
0018 
0019 class EntryFilter : public QObject
0020 {
0021     Q_OBJECT
0022 public:
0023     EntryFilter(KEduVocDocument *doc, QObject *parent);
0024 
0025     /**
0026      * Returns the list of test entries after filtering out invalid entries
0027      * according to the settings.
0028      *
0029      * @param showDialog if true, show a dialog that lets the user slacken the
0030      *                   search parameters if there is no selected entries
0031      *                   using the current settings.
0032      *
0033      * @return list of entries to practice
0034      */
0035     QList<TestEntry *> entries(bool showDialog = true);
0036 
0037 private:
0038     void collectEntries(int setNo);
0039 
0040     /**
0041      * Called when starting a practice.
0042      * Looks if the time is up, if the work has been practiced too long ago, it will drop in grade.
0043      * Only if expiring is activated in prefs.
0044      */
0045     void expireEntries(int setNo);
0046     void setupFilteredEntries(int setNo);
0047 
0048     void lessonEntries(int setNo);
0049     void wordTypeEntries(int setNo);
0050 
0051     bool isBlocked(const KEduVocText *const grade) const;
0052     bool isConjugationBlocked(KEduVocTranslation *translation) const;
0053     void blockedEntries(int setNo);
0054     void timesWrongEntries(int setNo);
0055     void timesPracticedEntries(int setNo);
0056     void minMaxGradeEntries(int setNo);
0057 
0058     void updateCurrentSelection();
0059 
0060     /**
0061      * Remove entries that are empty or not of the right type for the specific test type
0062      */
0063     void cleanupInvalid(int setNo);
0064 
0065     /**
0066      * In conjugation practice mode, creates more than one test entry per verb if necessary.
0067      * This depends on the number of tenses and on the practice mode selected (every pronoun
0068      * separately, or grouped by tense).
0069      */
0070     QList<TestEntry *> conjugationTestEntries(bool ignoreBlocked) const;
0071 
0072     static void randomizedInsert(QList<TestEntry *> &list, TestEntry *entry);
0073 
0074 private:
0075     KEduVocDocument *m_doc;
0076 
0077     // All entries that are valid given all criteria
0078     QSet<KEduVocExpression *> m_entries[2];
0079 
0080     // Various sets of entries that are valid given only one criterium each.
0081     // These are used in the selection dialog if there are no totally valid entries.
0082     QSet<KEduVocExpression *> m_entriesLesson[2];
0083     QSet<KEduVocExpression *> m_entriesWordType[2];
0084     QSet<KEduVocExpression *> m_entriesNotBlocked[2];
0085     QSet<KEduVocExpression *> m_entriesTimesWrong[2];
0086     QSet<KEduVocExpression *> m_entriesTimesPracticed[2];
0087     QSet<KEduVocExpression *> m_entriesMinMaxGrade[2];
0088 
0089     int m_numSets;
0090     int m_fromTranslation;
0091     int m_toTranslation;
0092 
0093     // The tenses selected by the user for practice
0094     QStringList m_tenses;
0095 
0096     QSet<KEduVocExpression *> m_currentSelection[2];
0097 
0098     friend class EntryFilterDialog;
0099 };
0100 
0101 #endif