1 /***************************************************************************
2  *   Copyright (C) 2013~2013 by CSSlayer                                   *
3  *   wengxt@gmail.com                                                      *
4  *                                                                         *
5  *  This program 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  *  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.  *
17  *                                                                         *
18  ***************************************************************************/
19 
20 #ifndef DICTMODEL_H
21 #define DICTMODEL_H
22 #include <QAbstractItemModel>
23 #include <QSet>
24 #include <QFile>
25 
26 class DictModel : public QAbstractListModel
27 {
28     Q_OBJECT
29 public:
30     explicit DictModel(QObject* parent = 0);
31     virtual ~DictModel();
32     virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
33     virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
34     virtual bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex());
35 
36     void load();
37     void load(QFile& file);
38     void defaults();
39     bool save();
40     void add(const QMap<QString, QString>& dict);
41     bool moveDown(const QModelIndex& currentIndex);
42     bool moveUp(const QModelIndex& currentIndex);
43 private:
44     QSet<QString> m_requiredKeys;
45     QList< QMap< QString, QString> > m_dicts;
46 };
47 
48 #endif // DICTMODEL_H
49