fix bug with empty dictionary list. Add first version of WordListView (qml)
[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(/*QHash<QString, QList<Translation*> > translations, QHash<QString, bool> wordsInBookmarks, */QObject *parent = 0);
21
22     int rowCount(const QModelIndex & parent = QModelIndex()) const;
23
24     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
25     bool setData(const QModelIndex &index, const QVariant &value, int role);
26
27     Qt::ItemFlags flags(const QModelIndex &index) const;
28
29     //! Replace model data and refresh ui.
30     /*!
31       \param dictionaries hash set (dictionary, is active) with dictionaries
32     */
33     void setTranslations(QHash<QString, QList<Translation*> > translations, QHash<QString, bool> wordsInBookmarks);
34     //! Clear model data and refresh UI
35     void clear();
36
37 signals:
38
39 //    //! Set index of current selected word
40 //    /*!
41 //      \param index word position in data list
42 //      */
43 //    void itemSelected(int index);
44
45     void addToBookmarks(QString word);
46
47     void removeFromBookmarks(QString word);
48
49 public slots:
50
51     //! Set value at role in index row of data.
52     /*!
53       \param index word position in data list
54       \param value new value for role
55       \param role role name
56       */
57     void setModelProperty(int index, const QVariant value, QString role);
58
59 private:
60     int setDataPriv(int index, const QVariant &value, int role);
61     void addWord(QString word, QList<Translation*> translations, bool isBookmarked);
62
63     QHash<QString, QList<Translation*> > _translations;
64     QHash<QString, bool > _wordInBookmarks;
65     QList<QString> _wordList;
66
67 };
68
69 #endif // WORDLISTMODEL_H