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{
58 if (role == FromRole){
64 if (role == NameRole){
67 if (role == SizeRole){
74 void DictsListModel::itemSelected(int index) {
75 _currentIndex = index;
79 DownloadDict DictsListModel::currentDict() {
80 return dicts[_currentIndex];
84 Qt::ItemFlags DictsListModel::flags(const QModelIndex &index) const {
85 Qt::ItemFlags fl = QAbstractItemModel::flags(index);
86 return (fl | Qt::ItemIsEditable);
90 QList<DownloadDict> DictsListModel::dictionaries() {