Pass comic and comicInfo to the QML context when the current index is updated, so the ComicInfo view becomes functional.

This commit is contained in:
Luis Ángel San Martín 2016-04-12 22:37:52 +02:00
parent 1612402456
commit 939a52dd6e
2 changed files with 14 additions and 1 deletions

View File

@ -8,9 +8,10 @@
#include "QsLog.h"
InfoComicsView::InfoComicsView(QWidget *parent)
:ComicsView(parent)
:ComicsView(parent), comicDB(0)
{
qmlRegisterType<ComicModel>("com.yacreader.ComicModel",1,0,"ComicModel");
qmlRegisterType<ComicDB>("com.yacreader.ComicDB",1,0,"ComicDB");
qmlRegisterType<ComicInfo>("com.yacreader.ComicInfo",1,0,"ComicInfo");
view = new QQuickView();
@ -80,7 +81,10 @@ void InfoComicsView::setModel(ComicModel *model)
updateBackgroundConfig();*/
if(model->rowCount()>0)
{
setCurrentIndex(model->index(0,0));
updateInfoForIndex(0);
}
}
void InfoComicsView::setCurrentIndex(const QModelIndex &index)
@ -91,6 +95,14 @@ void InfoComicsView::setCurrentIndex(const QModelIndex &index)
void InfoComicsView::updateInfoForIndex(int index)
{
QQmlContext *ctxt = view->rootContext();
if(comicDB) delete comicDB;
comicDB = new ComicDB(model->getComic(this->model->index(index, 0)));
ComicInfo *comicInfo = &(comicDB->info);
ctxt->setContextProperty("comic", comicDB);
ctxt->setContextProperty("comicInfo", comicInfo);
int FIXME;
}

View File

@ -36,6 +36,7 @@ protected:
QWidget *container;
QObject *flow;
QObject *list;
ComicDB *comicDB;
};
#endif // INFOCOMICSVIEW_H