--- /dev/null
+#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;
+}
--- /dev/null
+#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