From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/study/WordDrillModel.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/study/WordDrillModel.h (limited to 'src/study/WordDrillModel.h') diff --git a/src/study/WordDrillModel.h b/src/study/WordDrillModel.h new file mode 100644 index 0000000..7db780a --- /dev/null +++ b/src/study/WordDrillModel.h @@ -0,0 +1,62 @@ +#ifndef WORDDRILLMODEL_H +#define WORDDRILLMODEL_H + +#include "IStudyModel.h" + +#include + +/** Model of Word Drill study tool. + * + * At the beginning of a test, the model generates a fresh pack of valid cards: #m_freshPack. In course of the test, + * cards one-by-one are randomly taken from the fresh pack and moved to the history pack #m_cardHistory. + * The part of history, which belongs to the current pack (recently generated new pack), is separated from older + * cards with property #m_historyCurPackStart. + * The current card can be obtained with #curCard(), it is taken from the history. When the fresh pack is finished + * and the next card required, new fresh pack is generated. + * + * All used cards over all pack iterations are saved to the history. + * The user can travel back and forth along the history with goBack() and goForward(). In this case #m_curCardNum + * increases or decreases. + */ + +class WordDrillModel: public IStudyModel +{ +Q_OBJECT + +public: + WordDrillModel( CardPack* aCardPack ); + + Card* getCurCard() const; + bool canGoBack(); + bool canGoForward(); + + int getCurCardNum() const { return curCardNum; } + int historySize() const {return m_cardHistory.size(); } + +private: + void generateFreshPack(); + void cleanHistoryFromRemovedCards(); + +public slots: + void pickNextCard(); + bool goBack(); + bool goForward(); + +private slots: + void updateStudyState(); + +private: + static const int NoCardIndex = -1; + +private: + /** Fresh cards. The cards that were not shown yet (in the current iteration). Not own.*/ + QStringList m_freshPack; + + /// List of all shown cards. Not own. + QStringList m_cardHistory; + + /// The start index of the current pack in the history + int m_historyCurPackStart; +}; + +#endif -- cgit