1 /*******************************************************************************
3 This file is part of mDictionary.
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.
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.
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/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 /*! \file DictManagerModel.h
23 \brief Contains dictionaries data for qml UI
25 \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
28 #ifndef DICTMANAGERMODEL_H
29 #define DICTMANAGERMODEL_H
31 #include <QAbstractListModel>
33 #include "../../include/GUIInterface.h"
36 Contains a list of installed dictionaries.
37 Data source for qml list view.
39 class DictManagerModel : public QAbstractListModel
45 NameRole = Qt::UserRole + 1,
53 \param dictionaries hash set (dictionary, is active) with dictionaries
54 \param parent parent of this class.
56 explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
58 int rowCount(const QModelIndex & parent = QModelIndex()) const;
60 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;
61 bool setData(const QModelIndex &index, const QVariant &value, int role);
63 Qt::ItemFlags flags(const QModelIndex &index) const;
65 //! Replace model data and refresh ui.
67 \param dictionaries hash set (dictionary, is active) with dictionaries
69 void setDictionaries(QHash<CommonDictInterface*, bool> dictionaries);
71 //! Get dictionary hash set
72 QHash<CommonDictInterface*, bool> dictionaries();
74 //! Get dictionary list
75 QList<CommonDictInterface*> dictList();
77 //! Clear model data and refresh UI
79 //! Get current selected dictionary
80 CommonDictInterface* currentDict();
81 //! Get true if current selected dictionary was active. Otherwise return false.
82 bool isCurrentDictSelected();
85 //! Set value at role in index row of data.
87 \param index dictionary position in data list
88 \param value new value for role
91 void setModelProperty(int index, const QVariant value, QString role);
92 //! Set index of current selected dictionary
94 \param index dictionary position in data list
96 void itemSelected(int index);
99 //! emits when user changed data
103 QHash<CommonDictInterface*, bool> _dictionaries;
104 QList<CommonDictInterface*> _dictList;
107 int setDataPriv(int index, const QVariant &value, int role);
108 void addDictionary(CommonDictInterface* dictionary, bool isActive);
111 #endif // DICTMANAGERMODEL_H