Fix random error when remove word from bookmark. Fix show all bookmark feature.
[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     void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
39
40 signals:
41
42     void addToBookmarks(QString word);
43
44     void removeFromBookmarks(QString word);
45
46 public slots:
47
48     //! Set value at role in index row of data.
49     /*!
50       \param index word position in data list
51       \param value new value for role
52       \param role role name
53       */
54     void setModelProperty(int index, const QVariant value, QString role);
55
56 private:
57     int setDataPriv(int index, const QVariant &value, int role);
58     void addWord(QString word, QList<Translation*> translations, bool isBookmarked);
59
60     QHash<QString, QList<Translation*> > _translations;
61     QHash<QString, bool > _wordInBookmarks;
62     QList<QString> _wordList;
63
64     bool isBookmarkModeActive;
65
66 };
67
68 #endif // WORDLISTMODEL_H