webView
[mdictionary] / src / mdictionary / gui / DictManagerModel.h
1 #ifndef DICTMANAGERMODEL_H
2 #define DICTMANAGERMODEL_H
3
4 #include <QAbstractListModel>
5 #include <QHash>
6 #include "../../include/GUIInterface.h"
7
8 /*!
9   Contains a list of installed dictionaries.
10   Data source for qml list view.
11 */
12 class DictManagerModel : public QAbstractListModel
13 {
14     Q_OBJECT
15 public:
16     enum DictTypeRoles
17     {
18         NameRole = Qt::UserRole + 1,
19         IconPathRole,
20         IsSelectedRole,
21         NumberRole
22     };
23
24     //! Constructor
25     /*!
26       \param dictionaries list of dictionaries
27       \param parent parent of this class.
28     */
29     explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
30
31     int rowCount(const QModelIndex & parent = QModelIndex()) const;
32
33     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
34     bool setData(const QModelIndex &index, const QVariant &value, int role);
35
36     Qt::ItemFlags flags(const QModelIndex &index) const;
37     void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
38     QHash<CommonDictInterface*, bool> dictionaries();
39     QList<CommonDictInterface*> dictList();
40
41     void clear();
42
43 public Q_SLOTS:
44     void setModelProperty(int index, const QVariant value, QString role);
45
46 Q_SIGNALS:
47     void itemChanged();
48
49 private:
50     QHash<CommonDictInterface*, bool> _dictionaries;
51     QList<CommonDictInterface*> _dictList;
52
53     int setDataPriv(int index, const QVariant &value, int role);
54     void addDictionary(CommonDictInterface* dictionary, bool isActive);
55 };
56
57 #endif // DICTMANAGERMODEL_H