diff options
author | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
---|---|---|
committer | Jedidiah Barber <contact@jedbarber.id.au> | 2021-07-14 11:49:10 +1200 |
commit | d24f813f3f2a05c112e803e4256b53535895fc98 (patch) | |
tree | 601e6ae9a1cd44bcfdcf91739a5ca36aedd827c9 /src/main-view/AppModel.h |
Diffstat (limited to 'src/main-view/AppModel.h')
-rw-r--r-- | src/main-view/AppModel.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main-view/AppModel.h b/src/main-view/AppModel.h new file mode 100644 index 0000000..bf1ddd2 --- /dev/null +++ b/src/main-view/AppModel.h @@ -0,0 +1,64 @@ +#ifndef APPMODEL_H +#define APPMODEL_H + +#include <QList> +#include <QPair> +#include <QFile> +#include <QAbstractItemModel> + +class Dictionary; +class DictTableModel; +class CardPack; +class IStudyModel; + +class AppModel: public QObject +{ +Q_OBJECT + +public: + enum StudyType + { + WordDrill, + SpacedRepetition, + StudyTypesNum + }; + +public: + AppModel(); + ~AppModel(); + + bool openDictionary( const QString& filePath ); + void addDictionary( Dictionary* aDict ); + Dictionary* newDictionary(); + Dictionary* curDictionary(); + int getCurDictIndex() const { return curDictIndex; } + DictTableModel* curDictModel(); + int dictionariesNum() const { return dictionaries.size(); } + Dictionary* dictionary(int aIndex) const; + int indexOfDictionary( Dictionary* aDic ) const; + int indexOfDictionary( const QString& aFilePath ) const; + // TODO: Synchronize this with the pack tree view selection + int curCardPackIx() const { return curCardPackIndex; } + CardPack* curCardPack(); + QString getErrorMessage() const { return errorMessage; } + +public slots: + /** @return true, if the dictionary was successfully set. false, if there are no dictionaries, or the index is out of range. + * If the index is out of range, the last dictionary from the list is set. + */ + bool setCurDictionary(int index); + bool removeDictionary(int aIndex); + void removeDictModel(QAbstractItemModel* aDictModel); + IStudyModel* createStudyModel(int studyType, int cardPackIndex); + +private: + void fixupCurDictIx(); + +private: + QList< QPair<Dictionary*, DictTableModel*> > dictionaries; + QString errorMessage; + int curDictIndex; + int curCardPackIndex; +}; + +#endif |