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;
|
||||
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())
|
||||
QMessageBox::critical(0,"Error from ComicVine", "-");
|
||||
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)
|
||||
{
|
||||
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]);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ class VolumesModel : public JSONModel
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit VolumesModel(QObject *parent = 0);
|
||||
virtual ~VolumesModel();
|
||||
//receive a valid json with a list of volumes
|
||||
void load(const QString & json);
|
||||
|
||||
@ -25,7 +26,7 @@ signals:
|
||||
public slots:
|
||||
|
||||
private:
|
||||
QList <QList <QString> > _data;
|
||||
QList <QList <QString> * > _data;
|
||||
|
||||
enum Column {
|
||||
SERIES,
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <QTableView>
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHeaderView>
|
||||
#include <QScrollBar>
|
||||
|
||||
#include "volumes_model.h"
|
||||
|
||||
@ -11,28 +13,22 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
:QWidget(parent),model(0)
|
||||
{
|
||||
QString labelStylesheet = "QLabel {color:white; font-size:12px;font-family:Arial;}";
|
||||
QString tableStylesheet = ""
|
||||
"QTableView {alternate-background-color: #333333;background-color: #2B2B2B; outline: 0px;}"// border: 1px solid #999999; border-right:none; border-bottom:none;}"
|
||||
"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 {outline: 0px; border: 0px color:#FFFFFF;}"
|
||||
"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;}"
|
||||
QString tableStylesheet = "QTableView {color:white; border:0px;alternate-background-color: #2E2E2E;background-color: #2B2B2B; outline: 0px;}"
|
||||
"QTableView::item {outline: 0px; border: 0px; color:#FFFFFF;}"
|
||||
"QTableView::item:selected {outline: 0px; background-color: #555555; }"
|
||||
"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;}"
|
||||
"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; }"
|
||||
|
||||
//scrollbar
|
||||
|
||||
"QScrollBar:vertical { border: none; background: #404040; width: 3px; margin: 0; }"
|
||||
"QScrollBar:vertical { border: none; background: #2B2B2B; width: 3px; margin: 0; }"
|
||||
"QScrollBar:horizontal { border: none; background: #2B2B2B; height: 3px; margin: 0; }"
|
||||
"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::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::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 {background: none; }"
|
||||
"";
|
||||
"QScrollBar::add-page:vertical, QScrollBar::sub-page:vertical, QScrollBar::add-page:horizontal, QScrollBar::sub-page:horizontal {background: none; }";
|
||||
|
||||
QLabel * label = new QLabel(tr("Please, select the right series for your comic."));
|
||||
label->setStyleSheet(labelStylesheet);
|
||||
@ -49,6 +45,39 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
tableVolumes = new QTableView();
|
||||
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(detailLabel);
|
||||
left->addStretch();
|
||||
@ -56,7 +85,7 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
leftWidget->setLayout(left);
|
||||
|
||||
content->addWidget(leftWidget);
|
||||
content->addWidget(tableVolumes);
|
||||
content->addWidget(tableVolumes,0,Qt::AlignRight);
|
||||
|
||||
l->addSpacing(15);
|
||||
l->addWidget(label);
|
||||
@ -70,12 +99,18 @@ SelectVolume::SelectVolume(QWidget *parent)
|
||||
|
||||
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)
|
||||
delete model;
|
||||
else
|
||||
model = new VolumesModel();
|
||||
|
||||
model->load(json);
|
||||
model = tempM;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user