Clean and order documentation in source files. Source ready to beta 2 release
[mdictionary] / src / plugins / xdxf / DictsModel.cpp
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 DictsModel.cpp
23     \brief Item model for informations about xdxf dictionaries.
24
25     \author Mateusz Półrola <mateusz.polrola@comarch.pl>
26 */
27
28 #include "DictsModel.h"
29
30 DictsModel::DictsModel(QList<DownloadDict> dicts, QObject *parent) :
31                        QAbstractItemModel(parent) {
32     this->dicts = dicts;
33     qSort(this->dicts);
34 }
35
36
37 int DictsModel::rowCount(const QModelIndex &) const {
38     return dicts.count();
39 }
40
41
42 int DictsModel::columnCount(const QModelIndex &) const {
43     return 4;
44 }
45
46
47 QVariant DictsModel::data(const QModelIndex &index, int role) const {
48     if (!index.isValid())
49         return QVariant();
50
51     if (index.row() >= dicts.count())
52         return QVariant();
53
54     if (role == Qt::DisplayRole) {
55         switch(index.column()) {
56             case 0:
57                 return dicts.at(index.row()).fromLang();
58             case 1:
59                 return dicts.at(index.row()).toLang();
60             case 2:
61                 return dicts.at(index.row()).title();
62             case 3:
63                 return QString::number(dicts.at(index.row()).size(), 'g', 2) +
64                        QString (" MB");
65         }
66     }
67
68     if (role == Qt::UserRole) {
69         return dicts.at(index.row()).link();
70     }
71     return QVariant();
72 }
73
74
75 QVariant DictsModel::headerData(int section, Qt::Orientation orientation,
76                                       int role) const {
77     if (role != Qt::DisplayRole)
78         return QVariant();
79
80     if (orientation == Qt::Horizontal) {
81         switch(section) {
82             case 0:
83                 return tr("From");
84             case 1:
85                 return tr("To");
86             case 2:
87                 return tr("Name");
88             case 3:
89                 return tr("Size");
90         }
91     }
92     return QVariant();
93 }
94
95
96 QModelIndex DictsModel::index(int row, int column, const QModelIndex &) const {
97     return createIndex(row, column, row);
98 }
99
100
101 QModelIndex DictsModel::parent(const QModelIndex &) const {
102     return QModelIndex();
103 }