#include "tradelistmodel.h"
#include <QPixmap>
#include <QImageReader>
#include <QDebug>
#include <QUrl>

tradeListModel::tradeListModel(const QStringList &addressString, const QStringList &dateString, const QStringList &sizeString, const QStringList &priceString, const QStringList &ppsString, const QStringList &typeString, QObject *parent) :
        QAbstractListModel(parent), addressString(addressString), dateString(dateString),
        sizeString(sizeString), priceString(priceString),ppsString(ppsString),typeString(typeString)
{
    if(addressString.size() > 0)
    {
        size = addressString.size();
    }
    else
    {
        size = sizeString.size();
    }
}

int tradeListModel::rowCount(const QModelIndex &parent) const
{

    return size;
}

QVariant tradeListModel::data(const QModelIndex &index, int role) const
{
    if ( (!index.isValid()) || (index.row() >= size))
        return QVariant();


    if(role == Qt::UserRole)
    {
        qDebug()<<"1";
        if(dateString.size() > 0)
        return dateString.at(index.row());
        else
            return "";
    }
    else if( role == Qt::UserRole+1)
    {
        qDebug()<<"2";
        if(addressString.size() > 0)
        return addressString.at(index.row());
        else
            return "";
    }
    else if( role == Qt::UserRole+2)
    {
        qDebug()<<"3";
        if(sizeString.size() > 0)
        return sizeString.at(index.row());
        else
            return "";

    }
    else if( role == Qt::UserRole+3)
    {
        qDebug()<<"4";
        if(priceString.size() > 0)
        return priceString.at(index.row());
        else
            return "";
    }
    else if( role == Qt::UserRole+4)
    {
        qDebug()<<"5";
        if(typeString.size() > 0)
        return typeString.at(index.row());
        else
            return "";
    }
    else if( role == Qt::UserRole+5)
    {
        qDebug()<<"6";
        if(ppsString.size() > 0)
        return ppsString.at(index.row());
        else
            return "";
    }

    return QVariant();
}



void tradeListModel::setStrings(const QStringList & strings)
{
    qDebug()<<"bulala";
    dateString = strings;
    reset();
}
