summaryrefslogtreecommitdiff
path: root/src/main-view/AppModel.h
blob: bf1ddd256fc4353fd3638dae43593910fbcfdaed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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