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