#include "blogsearchlistmodel.h"

#include <QPixmap>
#include <QImageReader>
#include <QDebug>
#include <QUrl>

blogSearchListModel::blogSearchListModel(const QStringList &nameString, const QStringList &nameEnString, const QStringList &addressString, const QStringList &countString, const QPixmap p[], QObject *parent) :
        QAbstractListModel(parent), nameString(nameString), nameEnString(nameEnString), addressString(addressString), countString(countString)
{

    for(int i=0;i<151;i++){_p[i]=p[i];}

}

int blogSearchListModel::rowCount(const QModelIndex &parent) const
{
    return nameString.count();
}

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


    if(role == Qt::UserRole)
    {
        return nameString.at(index.row());
    }
    else if( role == Qt::UserRole+1)
    {

        return _p[index.row()];
    }
    else if( role == Qt::UserRole+2)
    {
        QImageReader reader;
        reader.setFileName(":/new/prefix1/Image/arrow_right.png");
        QSize imageSize = reader.size();
        imageSize.scale(QSize(20,20), Qt::KeepAspectRatio);
        reader.setScaledSize(imageSize);
        QImage image = reader.read();
        QPixmap pixmap = QPixmap::fromImage(image);

        return pixmap;
    }
    else if( role == Qt::UserRole+3)
    {
        return nameEnString.at(index.row());
    }
    else if( role == Qt::UserRole+4)
    {

        return addressString.at(index.row());
    }
    else if( role == Qt::UserRole+5)
    {


       return countString.at(index.row());
    }

    return QVariant();
}



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

