/*
Copyright © 2015 Gluzskiy Alexandr (sss)
This file is part of Unknown Download Manager (UDM).
UDM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
UDM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with UDM. If not, see .
*/
#include "downloads_model.h"
downloads_model::downloads_model(std::vector &downloads_, QObject */*parent*/) : downloads(downloads_)
{
}
int downloads_model::rowCount(const QModelIndex &/*parent*/) const
{
return downloads.size();
}
QVariant downloads_model::data(const QModelIndex &index, int role) const
{
if(!index.isValid())
return QVariant();
if((unsigned)index.row() >= downloads.size())
return QVariant();
//TODO: support for dynamic columnt count
if(role == Qt::DisplayRole)
{
switch(index.column())
{
case 0:
return QString(" ") + QString::fromUtf8(downloads[index.row()].name().c_str());
break;
//TODO: human readable size
case 1:
return (qint64) downloads[index.row()].size();
break;
case 2:
return (qint64)downloads[index.row()].downloaded();
break;
//
case 3:
return (qint64)((double)downloads[index.row()].downloaded() / (double)downloads[index.row()].size()) * 100.0;
break;
case 4:
return downloads[index.row()].module_name().c_str();
break;
case 5: //TODO:
return QVariant();
break;
case 6: //TODO:
return QVariant();
break;
}
}
return QVariant();
}
QVariant downloads_model::headerData(int section, Qt::Orientation orientation, int role) const
{
//TODO: support for dynamic columnt count
if(role == Qt::DisplayRole)
{
if(orientation == Qt::Horizontal)
{
switch(section)
{
case 0:
return QString(tr("Name"));
break;
case 1:
return QString(tr("Size"));
break;
case 2:
return QString(tr("Downloaded"));
break;
case 3:
return QString(tr("Progress"));
break;
case 4:
return QString(tr("Module name"));
break;
case 5:
return QString(tr("Down Speed"));
break;
case 6:
return QString(tr("ETA"));
break;
}
}
}
return QVariant();
}
int downloads_model::columnCount ( const QModelIndex & /*parent*/) const
{
//TODO: support for dynamic columnt count
return 7;
}
bool downloads_model::insertRows(int position, int rows, const QModelIndex &/*index*/)
{
beginInsertRows(QModelIndex(), position, position+rows-1);
endInsertRows();
return true;
}
bool downloads_model::removeRows(int position, int rows, const QModelIndex &/*index*/)
{
beginRemoveRows(QModelIndex(), position, position+rows-1);
endRemoveRows();
return true;
}
void downloads_model::sort ( int /*column*/, Qt::SortOrder /*order*/)
{
//TODO:
}