add some file
authorjakub <jakub.jaszczynski@comarch.com>
Tue, 1 Feb 2011 13:56:03 +0000 (14:56 +0100)
committerjakub <jakub.jaszczynski@comarch.com>
Tue, 1 Feb 2011 13:56:03 +0000 (14:56 +0100)
src/plugins/xdxf/DictsListModel.cpp [new file with mode: 0644]
src/plugins/xdxf/DictsListModel.h [new file with mode: 0644]

diff --git a/src/plugins/xdxf/DictsListModel.cpp b/src/plugins/xdxf/DictsListModel.cpp
new file mode 100644 (file)
index 0000000..f4b5b99
--- /dev/null
@@ -0,0 +1,93 @@
+#include "DictsListModel.h"
+
+
+DictsListModel::DictsListModel(QList<DownloadDict> dicts, QObject *parent) :
+    QAbstractListModel(parent) {
+
+    _currentIndex = 0;
+    QHash<int, QByteArray> roles;
+    roles[NumberRole] = "number";
+    roles[FromRole] = "from";
+    roles[ToRole] = "to";
+    roles[NameRole] = "name";
+    roles[SizeRole] = "size";
+    roles[LinkRole] = "link";
+    setRoleNames(roles);
+
+    this->dicts=dicts;
+    qSort(this->dicts);
+
+//    connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(itemChanged()));
+}
+
+
+int DictsListModel::rowCount(const QModelIndex &) const {
+    return dicts.count();
+}
+
+
+QVariant DictsListModel::data(const QModelIndex & index, int role) const {
+    if (index.row() < 0 || index.row() > dicts.count())
+        return QVariant();
+
+    DownloadDict dict = dicts[index.row()];
+    if (role == NumberRole){
+        return index.row();
+    }
+    if (role == FromRole){
+        return dict.fromLang();
+    }
+    if (role == ToRole){
+        return dict.toLang();
+    }
+    if (role == NameRole){
+        return dict.title();
+    }
+    if (role == SizeRole){
+        return QString::number(dict.size(),'g', 2) + QString (" MB");
+    }
+    if (role == LinkRole) {
+        return dict.link();
+    }
+    return QVariant();
+}
+
+
+QVariant DictsListModel::headerData(int section, Qt::Orientation orientation, int role) const{
+    qDebug()<<"tu jestem"<< role;
+
+    if (role == FromRole){
+        return "From";
+    }
+    if (role == ToRole){
+        return "To";
+    }
+    if (role == NameRole){
+        return "Title";
+    }
+    if (role == SizeRole){
+        return "Size";
+    }
+    return QVariant();
+}
+
+
+void DictsListModel::itemSelected(int index) {
+    _currentIndex = index;
+}
+
+
+DownloadDict DictsListModel::currentDict() {
+    return dicts[_currentIndex];
+}
+
+
+Qt::ItemFlags DictsListModel::flags(const QModelIndex &index) const {
+    Qt::ItemFlags fl = QAbstractItemModel::flags(index);
+    return (fl | Qt::ItemIsEditable);
+}
+
+
+QList<DownloadDict> DictsListModel::dictionaries() {
+    return dicts;
+}
diff --git a/src/plugins/xdxf/DictsListModel.h b/src/plugins/xdxf/DictsListModel.h
new file mode 100644 (file)
index 0000000..84ff859
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef DICTSLISTMODEL_H
+#define DICTSLISTMODEL_H
+
+#include <QAbstractListModel>
+#include <QDebug>
+#include "DownloadDict.h"
+
+
+class DictsListModel : public QAbstractListModel
+{
+    Q_OBJECT
+public:
+    enum DictTypeRoles {
+        NumberRole=Qt::UserRole + 1,
+        FromRole,
+        ToRole,
+        NameRole,
+        SizeRole,
+        LinkRole
+    };
+    explicit DictsListModel(QList<DownloadDict> dicts, QObject *parent = 0);
+    int rowCount(const QModelIndex &) const;
+    QVariant data(const QModelIndex & index, int role) const;
+    QVariant headerData(int section, Qt::Orientation orientation, int role) const;
+    Qt::ItemFlags flags(const QModelIndex &index) const;
+    DownloadDict currentDict();
+    QList<DownloadDict> dictionaries();
+
+public Q_SLOTS:
+    void itemSelected(int index);
+
+
+private:
+    QList<DownloadDict> dicts;
+    int _currentIndex;
+};
+
+#endif // DICTSLISTMODEL_H