mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
minor changes in ComicVineDialog (model)
This commit is contained in:
parent
5ef8df423b
commit
6a6c902803
@ -81,6 +81,7 @@ void ComicVineDialog::doStackedWidgets()
|
||||
content->addWidget(searchSingleComic = new SearchSingleComic);
|
||||
content->addWidget(searchVolume = new SearchVolume);
|
||||
content->addWidget(selectVolume = new SelectVolume);
|
||||
content->addWidget(selectComic = new SelectComic);
|
||||
}
|
||||
|
||||
void ComicVineDialog::doConnections()
|
||||
@ -189,13 +190,13 @@ void ComicVineDialog::debugClientResults(const QString & string)
|
||||
if(p.getNumResults() == 0)
|
||||
showSearchSingleComic();
|
||||
else
|
||||
showSelectComic();
|
||||
showSelectComic(string);
|
||||
break;
|
||||
case Volume:
|
||||
if(p.getNumResults() == 0)
|
||||
showSearchVolume();
|
||||
else
|
||||
showSelectVolume();
|
||||
showSelectVolume(string);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -238,14 +239,16 @@ void ComicVineDialog::showSearchVolume()
|
||||
skipButton->setHidden(true);
|
||||
}
|
||||
|
||||
void ComicVineDialog::showSelectVolume()
|
||||
void ComicVineDialog::showSelectVolume(const QString & json)
|
||||
{
|
||||
content->setCurrentWidget(selectVolume);
|
||||
selectVolume->load(json);
|
||||
}
|
||||
|
||||
void ComicVineDialog::showSelectComic()
|
||||
void ComicVineDialog::showSelectComic(const QString &json)
|
||||
{
|
||||
|
||||
content->setCurrentWidget(selectComic);
|
||||
selectComic->load(json);
|
||||
}
|
||||
|
||||
void ComicVineDialog::showLoading()
|
||||
|
@ -43,8 +43,8 @@ protected slots:
|
||||
void search();
|
||||
void launchSearchVolume();
|
||||
void launchSearchComic();
|
||||
void showSelectVolume();
|
||||
void showSelectComic();
|
||||
void showSelectVolume(const QString & json);
|
||||
void showSelectComic(const QString & json);
|
||||
private:
|
||||
|
||||
enum ScrapperMode
|
||||
@ -94,6 +94,7 @@ private:
|
||||
SearchSingleComic * searchSingleComic;
|
||||
SearchVolume * searchVolume;
|
||||
SelectVolume * selectVolume;
|
||||
SelectComic * selectComic;
|
||||
};
|
||||
|
||||
#endif // COMIC_VINE_DIALOG_H
|
||||
|
@ -8,6 +8,7 @@ class JSONModel : public QAbstractItemModel
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit JSONModel(QObject *parent = 0);
|
||||
virtual void load(const QString & json) = 0 ;
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -27,7 +27,6 @@ void ResponseParser::loadJSONResponse(const QString &response)
|
||||
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||
{
|
||||
error = true;
|
||||
numResults = -2;
|
||||
qDebug("Error detected");
|
||||
}
|
||||
else
|
||||
@ -36,7 +35,6 @@ void ResponseParser::loadJSONResponse(const QString &response)
|
||||
if(sc.property("number_of_total_results").isValid())
|
||||
numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
||||
else
|
||||
numResults = -3;
|
||||
qDebug() << sc.property("number_of_total_results").toString();
|
||||
qDebug() << sc.property("oops").toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,110 @@
|
||||
#include "volumes_model.h"
|
||||
|
||||
#include <QtScript>
|
||||
|
||||
|
||||
VolumesModel::VolumesModel(QObject *parent) :
|
||||
JSONModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void VolumesModel::load(const QString &json)
|
||||
{
|
||||
QScriptEngine engine;
|
||||
QScriptValue sc;
|
||||
sc = engine.evaluate("(" + json + ")");
|
||||
|
||||
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||
{
|
||||
qDebug("Error detected");
|
||||
}
|
||||
else
|
||||
{
|
||||
QScriptValueIterator it(sc.property("results"));
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
qDebug("Nick %s",it.value().property("nick").toString().toStdString().c_str());
|
||||
}
|
||||
/*
|
||||
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();*/
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndex VolumesModel::parent(const QModelIndex &index) const
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
return QModelIndex(); //no parent
|
||||
}
|
||||
|
||||
int VolumesModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
return _data.count();
|
||||
}
|
||||
|
||||
int VolumesModel::columnCount(const QModelIndex &parent) const
|
||||
{
|
||||
Q_UNUSED(parent)
|
||||
if(_data.isEmpty())
|
||||
return 0;
|
||||
else
|
||||
return _data.at(0).count();
|
||||
}
|
||||
|
||||
QVariant VolumesModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role != Qt::DisplayRole)
|
||||
return QVariant();
|
||||
|
||||
int row = index.row();
|
||||
int column = index.column();
|
||||
return _data[row][column];
|
||||
}
|
||||
|
||||
Qt::ItemFlags VolumesModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid())
|
||||
return 0;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVariant VolumesModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
|
||||
{
|
||||
switch(section)//TODO obtener esto de la query
|
||||
{
|
||||
case SERIES:
|
||||
return QVariant(QString("series"));
|
||||
case YEAR:
|
||||
return QVariant(QString(tr("year")));
|
||||
case ISSUES:
|
||||
return QVariant(QString(tr("issues")));
|
||||
case PUBLISHER:
|
||||
return QVariant(QString(tr("publisher")));
|
||||
}
|
||||
}
|
||||
|
||||
if (orientation == Qt::Horizontal && role == Qt::TextAlignmentRole)
|
||||
{
|
||||
switch(section)//TODO obtener esto de la query
|
||||
{
|
||||
case YEAR:
|
||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||
case ISSUES:
|
||||
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent) const
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
|
@ -8,11 +8,32 @@ class VolumesModel : public JSONModel
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VolumesModel(QObject *parent = 0);
|
||||
//receive a valid json with a list of volumes
|
||||
void load(const QString & json);
|
||||
|
||||
//QAbstractItemModel methods
|
||||
QModelIndex parent(const QModelIndex &index) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant headerData(int section, Qt::Orientation orientation,
|
||||
int role = Qt::DisplayRole) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QList <QList <QString> > _data;
|
||||
|
||||
enum Column {
|
||||
SERIES,
|
||||
YEAR,
|
||||
ISSUES,
|
||||
PUBLISHER
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif // VOLUMES_MODEL_H
|
||||
|
@ -3,6 +3,13 @@
|
||||
|
||||
SelectComic::SelectComic(QWidget *parent)
|
||||
:QWidget(parent)
|
||||
{}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SelectComic::load(const QString &json)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SelectComic::~SelectComic() {}
|
||||
|
@ -8,6 +8,7 @@ class SelectComic : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
SelectComic(QWidget * parent = 0);
|
||||
void load(const QString & json);
|
||||
virtual ~SelectComic();
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
#include "volumes_model.h"
|
||||
|
||||
SelectVolume::SelectVolume(QWidget *parent)
|
||||
:QWidget(parent)
|
||||
:QWidget(parent),model(0)
|
||||
{
|
||||
QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}";
|
||||
QString tableStylesheet = ""
|
||||
@ -68,5 +68,15 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
setContentsMargins(0,0,0,0);
|
||||
}
|
||||
|
||||
void SelectVolume::load(const QString & json)
|
||||
{
|
||||
if(model != 0)
|
||||
delete model;
|
||||
else
|
||||
model = new VolumesModel();
|
||||
|
||||
model->load(json);
|
||||
}
|
||||
|
||||
|
||||
SelectVolume::~SelectVolume() {}
|
||||
|
@ -12,6 +12,7 @@ class SelectVolume : public QWidget
|
||||
Q_OBJECT
|
||||
public:
|
||||
SelectVolume(QWidget * parent = 0);
|
||||
void load(const QString & json);
|
||||
virtual ~SelectVolume();
|
||||
private:
|
||||
QLabel * cover;
|
||||
|
Loading…
Reference in New Issue
Block a user