features of DictManagerWidget restored in qml version.
[mdictionary] / src / mdictionary / gui / DictManagerModel.h
1 /*******************************************************************************
2
3     This file is part of mDictionary.
4
5     mDictionary is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9
10     mDictionary is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
17
18     Copyright 2010 Comarch S.A.
19
20 *******************************************************************************/
21
22 /*! \file DictManagerModel.h
23     \brief Contains dictionaries data for qml UI
24
25     \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
26 */
27
28 #ifndef DICTMANAGERMODEL_H
29 #define DICTMANAGERMODEL_H
30
31 #include <QAbstractListModel>
32 #include <QHash>
33 #include "../../include/GUIInterface.h"
34
35 /*!
36   Contains a list of installed dictionaries.
37   Data source for qml list view.
38 */
39 class DictManagerModel : public QAbstractListModel
40 {
41     Q_OBJECT
42 public:
43     enum DictTypeRoles
44     {
45         NameRole = Qt::UserRole + 1,
46         IconPathRole,
47         IsSelectedRole,
48         NumberRole
49     };
50
51     //! Constructor
52     /*!
53       \param dictionaries hash set (dictionary, is active) with dictionaries
54       \param parent parent of this class.
55     */
56     explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
57
58     int rowCount(const QModelIndex & parent = QModelIndex()) const;
59
60     QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
61     bool setData(const QModelIndex &index, const QVariant &value, int role);
62
63     Qt::ItemFlags flags(const QModelIndex &index) const;
64
65     //! Replace model data and refresh ui.
66     /*!
67       \param dictionaries hash set (dictionary, is active) with dictionaries
68     */
69     void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
70
71     //! Get dictionary hash set
72     QHash<CommonDictInterface*, bool> dictionaries();
73
74     //! Get dictionary list
75     QList<CommonDictInterface*> dictList();
76
77     //! Clear model data and refresh UI
78     void clear();
79     //! Get current selected dictionary
80     CommonDictInterface* currentDict();
81     //! Get true if current selected dictionary was active. Otherwise return false.
82     bool isCurrentDictSelected();
83
84 public Q_SLOTS:
85     //! Set value at role in index row of data.
86     /*!
87       \param index dictionary position in data list
88       \param value new value for role
89       \param role role name
90       */
91     void setModelProperty(int index, const QVariant value, QString role);
92     //! Set index of current selected dictionary
93     /*!
94       \param index dictionary position in data list
95       */
96     void itemSelected(int index);
97
98 Q_SIGNALS:
99     //! emits when user changed data
100     void itemChanged();
101
102 private:
103     QHash<CommonDictInterface*, bool> _dictionaries;
104     QList<CommonDictInterface*> _dictList;
105     int _currentIndex;
106
107     int setDataPriv(int index, const QVariant &value, int role);
108     void addDictionary(CommonDictInterface* dictionary, bool isActive);
109 };
110
111 #endif // DICTMANAGERMODEL_H