mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
VolumesModel JSON load complete
SelectVolume table style is done
This commit is contained in:
parent
b1d3bbb584
commit
95612284ac
@ -179,7 +179,7 @@ void ComicVineDialog::debugClientResults(const QString & string)
|
|||||||
{
|
{
|
||||||
ResponseParser p;
|
ResponseParser p;
|
||||||
p.loadJSONResponse(string);
|
p.loadJSONResponse(string);
|
||||||
QMessageBox::information(0,"Result", QString("Number of results : %1").arg(p.getNumResults()));
|
//QMessageBox::information(0,"Result", QString("Number of results : %1").arg(p.getNumResults()));
|
||||||
if(p.responseError())
|
if(p.responseError())
|
||||||
QMessageBox::critical(0,"Error from ComicVine", "-");
|
QMessageBox::critical(0,"Error from ComicVine", "-");
|
||||||
else
|
else
|
||||||
|
@ -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)
|
void VolumesModel::load(const QString &json)
|
||||||
{
|
{
|
||||||
QScriptEngine engine;
|
QScriptEngine engine;
|
||||||
@ -20,16 +25,20 @@ void VolumesModel::load(const QString &json)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int numResults = sc.property("number_of_total_results").toString().toInt(); //fix to weird behaviour using hasNext
|
||||||
QScriptValueIterator it(sc.property("results"));
|
QScriptValueIterator it(sc.property("results"));
|
||||||
while (it.hasNext()) {
|
while (numResults > 0) {
|
||||||
it.next();
|
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())
|
if(_data.isEmpty())
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
return _data.at(0).count();
|
return 4;//_data.at(0)->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant VolumesModel::data(const QModelIndex &index, int role) const
|
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();
|
return QVariant();
|
||||||
|
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
int column = index.column();
|
int column = index.column();
|
||||||
return _data[row][column];
|
return _data[row]->at(column);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::ItemFlags VolumesModel::flags(const QModelIndex &index) const
|
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
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ class VolumesModel : public JSONModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit VolumesModel(QObject *parent = 0);
|
explicit VolumesModel(QObject *parent = 0);
|
||||||
|
virtual ~VolumesModel();
|
||||||
//receive a valid json with a list of volumes
|
//receive a valid json with a list of volumes
|
||||||
void load(const QString & json);
|
void load(const QString & json);
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList <QList <QString> > _data;
|
QList <QList <QString> * > _data;
|
||||||
|
|
||||||
enum Column {
|
enum Column {
|
||||||
SERIES,
|
SERIES,
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
#include <QTableView>
|
#include <QTableView>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QScrollBar>
|
||||||
|
|
||||||
#include "volumes_model.h"
|
#include "volumes_model.h"
|
||||||
|
|
||||||
@ -11,28 +13,22 @@ SelectVolume::SelectVolume(QWidget *parent)
|
|||||||
:QWidget(parent),model(0)
|
: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 = "QTableView {color:white; border:0px;alternate-background-color: #2E2E2E;background-color: #2B2B2B; outline: 0px;}"
|
||||||
"QTableView {alternate-background-color: #333333;background-color: #2B2B2B; outline: 0px;}"// border: 1px solid #999999; border-right:none; border-bottom:none;}"
|
"QTableView::item {outline: 0px; border: 0px; color:#FFFFFF;}"
|
||||||
"QTableCornerButton::section {background-color:#F5F5F5; border:none; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4);}"
|
"QTableView::item:selected {outline: 0px; background-color: #555555; }"
|
||||||
"QTableView::item {outline: 0px; border: 0px color:#FFFFFF;}"
|
"QHeaderView::section:horizontal {background-color:#292929; border-bottom:1px solid #1F1F1F; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #292929, stop: 1 #1F1F1F); border-left:none; border-top:none; padding:4px; color:#ebebeb;}"
|
||||||
"QTableView {border-top:1px solid #B8B8B8;border-bottom:none;border-left:1px solid #B8B8B8;border-right:none;}"
|
|
||||||
"QTableView::item:selected {outline: 0px; border-bottom: 1px solid #D4D4D4;border-top: 1px solid #D4D4D4; padding-bottom:1px; background-color: #D4D4D4; }"
|
|
||||||
"QHeaderView::section:horizontal {background-color:#F5F5F5; border-bottom:1px solid #B8BDC4; border-right:1px solid qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #D1D1D1, stop: 1 #B8BDC4); border-left:none; border-top:none; padding:4px; color:#313232;}"
|
|
||||||
"QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}"
|
"QHeaderView::section:vertical {border-bottom: 1px solid #DFDFDF;border-top: 1px solid #FEFEFE;}"
|
||||||
//"QTableView::item:hover {border-bottom: 1px solid #A3A3A3;border-top: 1px solid #A3A3A3; padding-bottom:1px; background-color: #A3A3A3; color: #FFFFFF; }"
|
"QScrollBar:vertical { border: none; background: #2B2B2B; width: 3px; margin: 0; }"
|
||||||
|
"QScrollBar:horizontal { border: none; background: #2B2B2B; height: 3px; margin: 0; }"
|
||||||
//scrollbar
|
|
||||||
|
|
||||||
"QScrollBar:vertical { border: none; background: #404040; width: 3px; margin: 0; }"
|
|
||||||
"QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }"
|
"QScrollBar::handle:vertical { background: #DDDDDD; width: 7px; min-height: 20px; }"
|
||||||
|
"QScrollBar::handle:horizontal { background: #DDDDDD; width: 7px; min-height: 20px; }"
|
||||||
"QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
"QScrollBar::add-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
||||||
|
|
||||||
"QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
"QScrollBar::sub-line:vertical { border: none; background: #404040; height: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 3px 0 0;}"
|
||||||
|
"QScrollBar::add-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: bottom; subcontrol-origin: margin; margin: 0 0 3px 0;}"
|
||||||
|
"QScrollBar::sub-line:horizontal { border: none; background: #404040; width: 10px; subcontrol-position: top; subcontrol-origin: margin; margin: 0 0 3px 0;}"
|
||||||
"QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}"
|
"QScrollBar::up-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-up.png') center top no-repeat;}"
|
||||||
"QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}"
|
"QScrollBar::down-arrow:vertical {border:none;width: 9px;height: 6px;background: url(':/images/folders_view/line-down.png') center top no-repeat;}"
|
||||||
|
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {background: none; }";
|
||||||
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical {background: none; }"
|
|
||||||
"";
|
|
||||||
|
|
||||||
QLabel * label = new QLabel(tr("Please, select the right series for your comic."));
|
QLabel * label = new QLabel(tr("Please, select the right series for your comic."));
|
||||||
label->setStyleSheet(labelStylesheet);
|
label->setStyleSheet(labelStylesheet);
|
||||||
@ -49,6 +45,39 @@ SelectVolume::SelectVolume(QWidget *parent)
|
|||||||
tableVolumes = new QTableView();
|
tableVolumes = new QTableView();
|
||||||
tableVolumes->setStyleSheet(tableStylesheet);
|
tableVolumes->setStyleSheet(tableStylesheet);
|
||||||
|
|
||||||
|
tableVolumes->setShowGrid(false);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
tableVolumes->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
|
||||||
|
#else
|
||||||
|
tableVolumes->verticalHeader()->setResizeMode(QHeaderView::Fixed);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//comicView->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
tableVolumes->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
tableVolumes->horizontalHeader()->setSectionsClickable(false);
|
||||||
|
#else
|
||||||
|
tableVolumes->horizontalHeader()->setClickable(false);
|
||||||
|
#endif
|
||||||
|
//comicView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||||
|
tableVolumes->verticalHeader()->setDefaultSectionSize(24);
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
tableVolumes->verticalHeader()->setSectionsClickable(false); //TODO comportamiento anómalo
|
||||||
|
#else
|
||||||
|
tableVolumes->verticalHeader()->setClickable(false); //TODO comportamiento anómalo
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tableVolumes->setCornerButtonEnabled(false);
|
||||||
|
|
||||||
|
tableVolumes->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
tableVolumes->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||||
|
|
||||||
|
tableVolumes->setAlternatingRowColors(true);
|
||||||
|
|
||||||
|
tableVolumes->verticalHeader()->hide();
|
||||||
|
|
||||||
|
tableVolumes->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
|
|
||||||
left->addWidget(cover);
|
left->addWidget(cover);
|
||||||
left->addWidget(detailLabel);
|
left->addWidget(detailLabel);
|
||||||
left->addStretch();
|
left->addStretch();
|
||||||
@ -56,7 +85,7 @@ SelectVolume::SelectVolume(QWidget *parent)
|
|||||||
leftWidget->setLayout(left);
|
leftWidget->setLayout(left);
|
||||||
|
|
||||||
content->addWidget(leftWidget);
|
content->addWidget(leftWidget);
|
||||||
content->addWidget(tableVolumes);
|
content->addWidget(tableVolumes,0,Qt::AlignRight);
|
||||||
|
|
||||||
l->addSpacing(15);
|
l->addSpacing(15);
|
||||||
l->addWidget(label);
|
l->addWidget(label);
|
||||||
@ -70,12 +99,18 @@ SelectVolume::SelectVolume(QWidget *parent)
|
|||||||
|
|
||||||
void SelectVolume::load(const QString & json)
|
void SelectVolume::load(const QString & json)
|
||||||
{
|
{
|
||||||
|
VolumesModel * tempM = new VolumesModel();;
|
||||||
|
tempM->load(json);
|
||||||
|
tableVolumes->setModel(tempM);
|
||||||
|
|
||||||
|
tableVolumes->resizeColumnsToContents();
|
||||||
|
|
||||||
|
tableVolumes->setFixedSize(419,341);
|
||||||
|
|
||||||
if(model != 0)
|
if(model != 0)
|
||||||
delete model;
|
delete model;
|
||||||
else
|
else
|
||||||
model = new VolumesModel();
|
model = tempM;
|
||||||
|
|
||||||
model->load(json);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user