added SortVolumeComics widget (and models)

This commit is contained in:
Luis Ángel San Martín
2013-10-19 09:20:23 +02:00
parent 8678e5368d
commit 63636dd417
19 changed files with 411 additions and 72 deletions

View File

@ -0,0 +1,82 @@
#include "local_comic_list_model.h"
LocalComicListModel::LocalComicListModel(QObject *parent) :
QAbstractItemModel(parent)
{
}
void LocalComicListModel::load(QList<ComicDB> &comics)
{
_data = comics;
}
QModelIndex LocalComicListModel::parent(const QModelIndex &index) const
{
Q_UNUSED(index)
return QModelIndex(); //no parent
}
int LocalComicListModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return _data.count();
}
int LocalComicListModel::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
if(_data.isEmpty())
return 0;
else
return 1;//_data.at(0)->count();
}
QVariant LocalComicListModel::data(const QModelIndex &index, int role) const
{
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].getFileName();
}
Qt::ItemFlags LocalComicListModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return 0;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
}
QVariant LocalComicListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
{
return QVariant(QString(tr("file name")));
}
return QVariant();
}
QModelIndex LocalComicListModel::index(int row, int column, const QModelIndex &parent) const
{
if (!hasIndex(row, column, parent))
return QModelIndex();
return createIndex(row, column);
}

View File

@ -0,0 +1,34 @@
#ifndef LOCAL_COMIC_LIST_MODEL_H
#define LOCAL_COMIC_LIST_MODEL_H
#include <QAbstractItemModel>
#include "comic_db.h"
class LocalComicListModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit LocalComicListModel(QObject *parent = 0);
void load(QList<ComicDB> & comics);
//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<ComicDB> _data;
};
#endif // LOCAL_COMIC_LIST_MODEL_H

View File

@ -0,0 +1,11 @@
#include "volume_comics_model.h"
VolumeComicsModel::VolumeComicsModel(QObject * parent) :
JSONModel(parent)
{
}
void VolumeComicsModel::load(const QString & json)
{
}

View File

@ -0,0 +1,18 @@
#ifndef VOLUME_COMICS_MODEL_H
#define VOLUME_COMICS_MODEL_H
#include "json_model.h"
class VolumeComicsModel : public JSONModel
{
Q_OBJECT
public:
explicit VolumeComicsModel(QObject *parent = 0);
void load(const QString & json);
signals:
public slots:
};
#endif // VOLUME_COMICS_MODEL_H

View File

@ -139,3 +139,8 @@ QModelIndex VolumesModel::index(int row, int column, const QModelIndex &parent)
return createIndex(row, column, _data[row]);
}
QString VolumesModel::getVolumeId(const QModelIndex &index) const
{
return _data.at(index.row())->at(ID);
}

View File

@ -22,6 +22,8 @@ public:
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
QString getVolumeId(const QModelIndex & index) const;
signals:
public slots: