mirror of
https://github.com/YACReader/yacreader
synced 2025-06-03 00:58:32 -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(searchSingleComic = new SearchSingleComic);
|
||||||
content->addWidget(searchVolume = new SearchVolume);
|
content->addWidget(searchVolume = new SearchVolume);
|
||||||
content->addWidget(selectVolume = new SelectVolume);
|
content->addWidget(selectVolume = new SelectVolume);
|
||||||
|
content->addWidget(selectComic = new SelectComic);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicVineDialog::doConnections()
|
void ComicVineDialog::doConnections()
|
||||||
@ -189,13 +190,13 @@ void ComicVineDialog::debugClientResults(const QString & string)
|
|||||||
if(p.getNumResults() == 0)
|
if(p.getNumResults() == 0)
|
||||||
showSearchSingleComic();
|
showSearchSingleComic();
|
||||||
else
|
else
|
||||||
showSelectComic();
|
showSelectComic(string);
|
||||||
break;
|
break;
|
||||||
case Volume:
|
case Volume:
|
||||||
if(p.getNumResults() == 0)
|
if(p.getNumResults() == 0)
|
||||||
showSearchVolume();
|
showSearchVolume();
|
||||||
else
|
else
|
||||||
showSelectVolume();
|
showSelectVolume(string);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,14 +239,16 @@ void ComicVineDialog::showSearchVolume()
|
|||||||
skipButton->setHidden(true);
|
skipButton->setHidden(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicVineDialog::showSelectVolume()
|
void ComicVineDialog::showSelectVolume(const QString & json)
|
||||||
{
|
{
|
||||||
content->setCurrentWidget(selectVolume);
|
content->setCurrentWidget(selectVolume);
|
||||||
|
selectVolume->load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicVineDialog::showSelectComic()
|
void ComicVineDialog::showSelectComic(const QString &json)
|
||||||
{
|
{
|
||||||
|
content->setCurrentWidget(selectComic);
|
||||||
|
selectComic->load(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ComicVineDialog::showLoading()
|
void ComicVineDialog::showLoading()
|
||||||
|
@ -43,8 +43,8 @@ protected slots:
|
|||||||
void search();
|
void search();
|
||||||
void launchSearchVolume();
|
void launchSearchVolume();
|
||||||
void launchSearchComic();
|
void launchSearchComic();
|
||||||
void showSelectVolume();
|
void showSelectVolume(const QString & json);
|
||||||
void showSelectComic();
|
void showSelectComic(const QString & json);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
enum ScrapperMode
|
enum ScrapperMode
|
||||||
@ -94,6 +94,7 @@ private:
|
|||||||
SearchSingleComic * searchSingleComic;
|
SearchSingleComic * searchSingleComic;
|
||||||
SearchVolume * searchVolume;
|
SearchVolume * searchVolume;
|
||||||
SelectVolume * selectVolume;
|
SelectVolume * selectVolume;
|
||||||
|
SelectComic * selectComic;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COMIC_VINE_DIALOG_H
|
#endif // COMIC_VINE_DIALOG_H
|
||||||
|
@ -8,6 +8,7 @@ class JSONModel : public QAbstractItemModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit JSONModel(QObject *parent = 0);
|
explicit JSONModel(QObject *parent = 0);
|
||||||
|
virtual void load(const QString & json) = 0 ;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ void ResponseParser::loadJSONResponse(const QString &response)
|
|||||||
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
if (!sc.property("error").isValid() && sc.property("error").toString() != "OK")
|
||||||
{
|
{
|
||||||
error = true;
|
error = true;
|
||||||
numResults = -2;
|
|
||||||
qDebug("Error detected");
|
qDebug("Error detected");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -36,7 +35,6 @@ void ResponseParser::loadJSONResponse(const QString &response)
|
|||||||
if(sc.property("number_of_total_results").isValid())
|
if(sc.property("number_of_total_results").isValid())
|
||||||
numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
numResults = sc.property("number_of_total_results").toString().toInt();// sc.property("number_of_total_results").toInt32();
|
||||||
else
|
else
|
||||||
numResults = -3;
|
qDebug() << sc.property("oops").toString();
|
||||||
qDebug() << sc.property("number_of_total_results").toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,110 @@
|
|||||||
#include "volumes_model.h"
|
#include "volumes_model.h"
|
||||||
|
|
||||||
|
#include <QtScript>
|
||||||
|
|
||||||
|
|
||||||
VolumesModel::VolumesModel(QObject *parent) :
|
VolumesModel::VolumesModel(QObject *parent) :
|
||||||
JSONModel(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
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VolumesModel(QObject *parent = 0);
|
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:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList <QList <QString> > _data;
|
||||||
|
|
||||||
|
enum Column {
|
||||||
|
SERIES,
|
||||||
|
YEAR,
|
||||||
|
ISSUES,
|
||||||
|
PUBLISHER
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VOLUMES_MODEL_H
|
#endif // VOLUMES_MODEL_H
|
||||||
|
@ -3,6 +3,13 @@
|
|||||||
|
|
||||||
SelectComic::SelectComic(QWidget *parent)
|
SelectComic::SelectComic(QWidget *parent)
|
||||||
:QWidget(parent)
|
:QWidget(parent)
|
||||||
{}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SelectComic::load(const QString &json)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SelectComic::~SelectComic() {}
|
SelectComic::~SelectComic() {}
|
||||||
|
@ -8,6 +8,7 @@ class SelectComic : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SelectComic(QWidget * parent = 0);
|
SelectComic(QWidget * parent = 0);
|
||||||
|
void load(const QString & json);
|
||||||
virtual ~SelectComic();
|
virtual ~SelectComic();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include "volumes_model.h"
|
#include "volumes_model.h"
|
||||||
|
|
||||||
SelectVolume::SelectVolume(QWidget *parent)
|
SelectVolume::SelectVolume(QWidget *parent)
|
||||||
:QWidget(parent)
|
:QWidget(parent),model(0)
|
||||||
{
|
{
|
||||||
QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}";
|
QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}";
|
||||||
QString tableStylesheet = ""
|
QString tableStylesheet = ""
|
||||||
@ -68,5 +68,15 @@ SelectVolume::SelectVolume(QWidget *parent)
|
|||||||
setContentsMargins(0,0,0,0);
|
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() {}
|
SelectVolume::~SelectVolume() {}
|
||||||
|
@ -12,6 +12,7 @@ class SelectVolume : public QWidget
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SelectVolume(QWidget * parent = 0);
|
SelectVolume(QWidget * parent = 0);
|
||||||
|
void load(const QString & json);
|
||||||
virtual ~SelectVolume();
|
virtual ~SelectVolume();
|
||||||
private:
|
private:
|
||||||
QLabel * cover;
|
QLabel * cover;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user