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