1 #include "DictsListModel.h"
4 DictsListModel::DictsListModel(QList<DownloadDict> dicts, QObject *parent) :
5 QAbstractListModel(parent) {
8 QHash<int, QByteArray> roles;
9 roles[NumberRole] = "number";
10 roles[FromRole] = "from";
12 roles[NameRole] = "name";
13 roles[SizeRole] = "size";
14 roles[LinkRole] = "link";
20 // connect(this, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SIGNAL(itemChanged()));
24 int DictsListModel::rowCount(const QModelIndex &) const {
29 QVariant DictsListModel::data(const QModelIndex & index, int role) const {
30 if (index.row() < 0 || index.row() > dicts.count())
33 DownloadDict dict = dicts[index.row()];
34 if (role == NumberRole){
37 if (role == FromRole){
38 return dict.fromLang();
43 if (role == NameRole){
46 if (role == SizeRole){
47 return QString::number(dict.size(),'g', 2) + QString (" MB");
49 if (role == LinkRole) {
56 QVariant DictsListModel::headerData(int section, Qt::Orientation orientation, int role) const{
57 qDebug()<<"tu jestem"<< role;
59 if (role == FromRole){
65 if (role == NameRole){
68 if (role == SizeRole){
75 void DictsListModel::itemSelected(int index) {
76 _currentIndex = index;
80 DownloadDict DictsListModel::currentDict() {
81 return dicts[_currentIndex];
85 Qt::ItemFlags DictsListModel::flags(const QModelIndex &index) const {
86 Qt::ItemFlags fl = QAbstractItemModel::flags(index);
87 return (fl | Qt::ItemIsEditable);
91 QList<DownloadDict> DictsListModel::dictionaries() {