From 0d60e1cdc1f7cd62b3b162b2cb1002711408ddd1 Mon Sep 17 00:00:00 2001 From: jakub Date: Tue, 1 Feb 2011 14:56:03 +0100 Subject: [PATCH] add some file --- src/plugins/xdxf/DictsListModel.cpp | 93 +++++++++++++++++++++++++++++++++++ src/plugins/xdxf/DictsListModel.h | 38 ++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/plugins/xdxf/DictsListModel.cpp create mode 100644 src/plugins/xdxf/DictsListModel.h diff --git a/src/plugins/xdxf/DictsListModel.cpp b/src/plugins/xdxf/DictsListModel.cpp new file mode 100644 index 0000000..f4b5b99 --- /dev/null +++ b/src/plugins/xdxf/DictsListModel.cpp @@ -0,0 +1,93 @@ +#include "DictsListModel.h" + + +DictsListModel::DictsListModel(QList dicts, QObject *parent) : + QAbstractListModel(parent) { + + _currentIndex = 0; + QHash 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 DictsListModel::dictionaries() { + return dicts; +} diff --git a/src/plugins/xdxf/DictsListModel.h b/src/plugins/xdxf/DictsListModel.h new file mode 100644 index 0000000..84ff859 --- /dev/null +++ b/src/plugins/xdxf/DictsListModel.h @@ -0,0 +1,38 @@ +#ifndef DICTSLISTMODEL_H +#define DICTSLISTMODEL_H + +#include +#include +#include "DownloadDict.h" + + +class DictsListModel : public QAbstractListModel +{ + Q_OBJECT +public: + enum DictTypeRoles { + NumberRole=Qt::UserRole + 1, + FromRole, + ToRole, + NameRole, + SizeRole, + LinkRole + }; + explicit DictsListModel(QList 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 dictionaries(); + +public Q_SLOTS: + void itemSelected(int index); + + +private: + QList dicts; + int _currentIndex; +}; + +#endif // DICTSLISTMODEL_H -- 1.7.9.5