mirror of
https://github.com/YACReader/yacreader
synced 2025-07-26 17:04:45 -04:00
VolumesModel JSON load complete
SelectVolume table style is done
This commit is contained in:
@ -8,6 +8,11 @@ VolumesModel::VolumesModel(QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
VolumesModel::~VolumesModel()
|
||||
{
|
||||
std::for_each(_data.begin(), _data.end(), [](QList<QString> * ptr) { delete ptr; });
|
||||
}
|
||||
|
||||
void VolumesModel::load(const QString &json)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
@ -20,16 +25,20 @@ void VolumesModel::load(const QString &json)
|
||||
}
|
||||
else
|
||||
{
|
||||
int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext
|
||||
QScriptValueIterator it(sc.property("results"));
|
||||
while (it.hasNext()) {
|
||||
while (numResults > 0) {
|
||||
it.next();
|
||||
qDebug("Nick %s",it.value().property("nick").toString().toStdString().c_str());
|
||||
QString numIssues = it.value().property("count_of_issues").toString();
|
||||
QString year = it.value().property("start_year").toString();
|
||||
QString name = it.value().property("name").toString();
|
||||
QString publisher = it.value().property("publisher").property("name").toString();
|
||||
QString url = it.value().property("image").property("screen_url").toString();
|
||||
QStringList & l = *(new QStringList);
|
||||
l << name << year << numIssues << publisher << url;
|
||||
_data.push_back(&l);
|
||||
numResults--;
|
||||
}
|
||||
/*
|
||||
if(sc.property("number_of_total_results").isValid())
|
||||
sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
||||
else
|
||||
qDebug() << sc.property("oops").toString();*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,17 +60,29 @@ int VolumesModel::columnCount(const QModelIndex &parent) const
|
||||
if(_data.isEmpty())
|
||||
return 0;
|
||||
else
|
||||
return _data.at(0).count();
|
||||
return 4;//_data.at(0)->count();
|
||||
}
|
||||
|
||||
QVariant VolumesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
if (!index.isValid())
|
||||
return QVariant();
|
||||
|
||||
if (role == Qt::DecorationRole)
|
||||
{
|
||||
return QVariant();
|
||||
}
|
||||
if (role == Qt::TextAlignmentRole)
|
||||
{
|
||||
//TODO
|
||||
}
|
||||
|
||||
if(role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
return _data[row][column];
|
||||
return _data[row]->at(column);
|
||||
}
|
||||
|
||||
Qt::ItemFlags VolumesModel::flags(const QModelIndex &index) const
|
||||
@ -105,6 +126,9 @@ QVariant VolumesModel::headerData(int section, Qt::Orientation orientation, int
|
||||
|
||||
QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
return QModelIndex();
|
||||
if (!hasIndex(row, column, parent))
|
||||
return QModelIndex();
|
||||
|
||||
return createIndex(row, column, _data[row]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user