code clean
[mdictionary] / src / mdictionary / gui / WordListModel.h
1 #ifndef WORDLISTMODEL_H
2 #define WORDLISTMODEL_H
3
4 #include <QAbstractListModel>
5 //#include "../../include/GUIInterface.h"
6 #include "../../include/translation.h"
7
8 class WordListModel : public QAbstractListModel
9 {
10     Q_OBJECT
11 public:
12
13     enum DictTypeRoles
14     {
15         WordRole = Qt::UserRole + 1,
16         IsBookmarkedRole,
17         NumberRole
18     };
19
20     explicit WordListModel(QObject *parent = 0);
21
22     int rowCount(const QModelIndex & parent = QModelIndex()) const;
23     void setBookmarkModeActive(bool mode);
24
25     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
26     bool setData(const QModelIndex &index, const QVariant &value, int role);
27
28     Qt::ItemFlags flags(const QModelIndex &index) const;
29
30     //! Replace model data and refresh ui.
31     /*!
32       \param dictionaries hash set (dictionary, is active) with dictionaries
33     */
34     void setTranslations(QHash<QString, QList<Translation*> > translations, QHash<QString, bool> wordsInBookmarks);
35     //! Clear model data and refresh UI
36     void clear();
37
38     QString wordOnPosition(int index);
39
40     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
41
42 signals:
43
44     void addToBookmarks(QString word);
45
46     void removeFromBookmarks(QString word);
47
48 public slots:
49
50     //! Set value at role in index row of data.
51     /*!
52       \param index word position in data list
53       \param value new value for role
54       \param role role name
55       */
56     void setModelProperty(int index, const QVariant value, QString role);
57
58     //! Reverse value at role in index row of data.
59     /*!
60       \param index word position in data list
61       \param role role name
62       */
63     void setModelPropertyByIndex(int index, QString role);
64
65 private:
66     int setDataPriv(int index, const QVariant &value, int role);
67     void addWord(QString word, QList<Translation*> translations, bool isBookmarked);
68
69     QHash<QString, QList<Translation*> > _translations;
70     QHash<QString, bool > _wordInBookmarks;
71     QList<QString> _wordList;
72
73     bool _isBookmarkModeActive;
74
75 };
76
77 #endif // WORDLISTMODEL_H