added sorting and filtering in download xdxf dialog
[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 //Created by Mateusz Półrola
23
24 #include "DictsModel.h"
25
26 DictsModel::DictsModel(QList<DownloadDict> dicts, QObject *parent) :
27     QAbstractItemModel(parent)
28 {
29     this->dicts = dicts;
30
31     qSort(this->dicts);
32 }
33
34
35 int DictsModel::rowCount(const QModelIndex &parent) const {
36     return dicts.count();
37 }
38
39 int DictsModel::columnCount(const QModelIndex &parent) const {
40     return 4;
41 }
42
43 QVariant DictsModel::data(const QModelIndex &index, int role) const
44 {
45     if (!index.isValid())
46         return QVariant();
47
48     if (index.row() >= dicts.count())
49         return QVariant();
50
51     if (role == Qt::DisplayRole) {
52         switch(index.column()) {
53         case 0:
54             return dicts.at(index.row()).fromLang();
55         case 1:
56             return dicts.at(index.row()).toLang();
57         case 2:
58             return dicts.at(index.row()).title();
59         case 3:
60             return dicts.at(index.row()).size();
61         }
62     }
63
64     if (role == Qt::UserRole) {
65         return dicts.at(index.row()).link();
66     }
67     return QVariant();
68 }
69
70 QVariant DictsModel::headerData(int section, Qt::Orientation orientation,
71                                       int role) const
72 {
73     if (role != Qt::DisplayRole)
74         return QVariant();
75
76     if (orientation == Qt::Horizontal) {
77         switch(section) {
78         case 0:
79             return tr("From");
80         case 1:
81             return tr("To");
82         case 2:
83             return tr("Name");
84         case 3:
85             return tr("Size");
86         }
87     }
88     return QVariant();
89 }
90
91 QModelIndex DictsModel::index(int row, int column, const QModelIndex &parent) const {
92     return createIndex(row, column, row);
93 }
94
95 QModelIndex DictsModel::parent(const QModelIndex &child) const {
96     return QModelIndex();
97 }
98
99 void DictsModel::sort(int column, Qt::SortOrder order) {
100
101 }