Add model class (DictManagerModel) to manage loaded dictionaries data and settings...
[mdictionary] / src / mdictionary / gui / DictManagerModel.h
diff --git a/src/mdictionary/gui/DictManagerModel.h b/src/mdictionary/gui/DictManagerModel.h
new file mode 100644 (file)
index 0000000..c722b2e
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef DICTMANAGERMODEL_H
+#define DICTMANAGERMODEL_H
+
+#include <QAbstractListModel>
+#include <QHash>
+#include "../../include/GUIInterface.h"
+
+/*!
+  Contains a list of installed dictionaries.
+  Data source for qml list view.
+*/
+class DictManagerModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum DictTypeRoles
+    {
+        NameRole = Qt::UserRole + 1,
+        IconPathRole,
+        IsSelectedRole,
+        NumberRole
+    };
+
+    //! Constructor
+    /*!
+      \param dictionaries list of dictionaries
+      \param parent parent of this class.
+    */
+    explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
+
+    int rowCount(const QModelIndex & parent = QModelIndex()) const;
+
+    QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
+    bool setData(const QModelIndex &index, const QVariant &value, int role);
+
+    Qt::ItemFlags flags(const QModelIndex &index) const;
+    void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
+
+    void clear();
+
+private:
+    QHash<CommonDictInterface*, bool> _dictionaries;
+    QList<CommonDictInterface*> _dictList;
+
+    void addDictionary(CommonDictInterface* dictionary, bool isActive);
+};
+
+#endif // DICTMANAGERMODEL_H