added sorting and filtering in download xdxf dialog
[mdictionary] / src / plugins / xdxf / DictsModel.cpp
diff --git a/src/plugins/xdxf/DictsModel.cpp b/src/plugins/xdxf/DictsModel.cpp
new file mode 100644 (file)
index 0000000..7947874
--- /dev/null
@@ -0,0 +1,101 @@
+/*******************************************************************************
+
+    This file is part of mDictionary.
+
+    mDictionary is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    mDictionary is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with mDictionary.  If not, see <http://www.gnu.org/licenses/>.
+
+    Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+//Created by Mateusz Półrola
+
+#include "DictsModel.h"
+
+DictsModel::DictsModel(QList<DownloadDict> dicts, QObject *parent) :
+    QAbstractItemModel(parent)
+{
+    this->dicts = dicts;
+
+    qSort(this->dicts);
+}
+
+
+int DictsModel::rowCount(const QModelIndex &parent) const {
+    return dicts.count();
+}
+
+int DictsModel::columnCount(const QModelIndex &parent) const {
+    return 4;
+}
+
+QVariant DictsModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid())
+        return QVariant();
+
+    if (index.row() >= dicts.count())
+        return QVariant();
+
+    if (role == Qt::DisplayRole) {
+        switch(index.column()) {
+        case 0:
+            return dicts.at(index.row()).fromLang();
+        case 1:
+            return dicts.at(index.row()).toLang();
+        case 2:
+            return dicts.at(index.row()).title();
+        case 3:
+            return dicts.at(index.row()).size();
+        }
+    }
+
+    if (role == Qt::UserRole) {
+        return dicts.at(index.row()).link();
+    }
+    return QVariant();
+}
+
+QVariant DictsModel::headerData(int section, Qt::Orientation orientation,
+                                      int role) const
+{
+    if (role != Qt::DisplayRole)
+        return QVariant();
+
+    if (orientation == Qt::Horizontal) {
+        switch(section) {
+        case 0:
+            return tr("From");
+        case 1:
+            return tr("To");
+        case 2:
+            return tr("Name");
+        case 3:
+            return tr("Size");
+        }
+    }
+    return QVariant();
+}
+
+QModelIndex DictsModel::index(int row, int column, const QModelIndex &parent) const {
+    return createIndex(row, column, row);
+}
+
+QModelIndex DictsModel::parent(const QModelIndex &child) const {
+    return QModelIndex();
+}
+
+void DictsModel::sort(int column, Qt::SortOrder order) {
+
+}