MyListNode::MyListNode(NodeType type, int id, const QList<QVariant> &data, MyListNode *parent) :
m_totalRowCount(-1), fetchedRowCount(0)
{
- this->type = type;
- this->id = id;
+ m_type = type;
+ m_id = id;
parentItem = parent;
itemData = data;
- if (type != Root)
+ if (m_type != Root)
return;
- itemData << "Title" << "Episode / Version";
+ itemData << "Title" << "Episode / Version" << "Rating / Quality" << "Vote";
}
if (m_totalRowCount != -1)
return m_totalRowCount;
- if (type == File)
+ if (m_type == File)
{
m_totalRowCount = 0;
return m_totalRowCount;
bool MyListNode::canFetchMore() const
{
- if (type != File && childCount() < totalRowCount())
+ if (m_type != File && childCount() < totalRowCount())
return true;
return false;
}
int MyListNode::fetchMore()
{
- qDebug() << "fetching some more for" << id;
+ qDebug() << "fetching some more for" << m_id;
QSqlQuery q(LocalMyList::instance()->database()->connection());
- if (!q.exec("SELECT aid, title_romaji AS title, (SELECT COUNT(e.eid) FROM episode e WHERE e.aid = a.aid) FROM anime a ORDER BY title ASC "
+ if (!q.exec("SELECT aid, title_romaji AS title, (SELECT COUNT(e.eid) FROM episode e WHERE e.aid = a.aid), rating, my_vote FROM anime a ORDER BY title ASC "
"LIMIT " + QString::number(LIMIT) + " "
"OFFSET " + QString::number(childCount())))
return 0;
{
int id = q.value(0).toInt();
QVariantList data;
- data << q.value(1) << q.value(2);
+
+ data << q.value(1) << q.value(2)
+ << (q.value(3).toDouble() < 1 ? "n/a" : QString::number(q.value(3).toDouble(), 'f', 2))
+ << (q.value(4).toDouble() < 1 ? "n/a" : QString::number(q.value(4).toDouble(), 'f', 2));
childItems << new MyListAnimeNode(id, data, this);
}
return q.size();
bool MyListNode::hasChildren() const
{
- if (type == File)
+ if (m_type == File)
return false;
return true;
return "SELECT COUNT(aid) FROM anime";
}
+MyListNode::NodeType MyListNode::type() const
+{
+ return m_type;
+}
+
+int MyListNode::id() const
+{
+ return m_id;
+}
+
// ------
MyListAnimeNode::MyListAnimeNode(int id, const QList<QVariant> &data, MyListNode *parent) :
QString MyListAnimeNode::totalRowCountSql() const
{
- return "SELECT COUNT(eid) FROM episode WHERE aid = " + QString::number(id);
+ return "SELECT COUNT(eid) FROM episode WHERE aid = " + QString::number(m_id);
}
int MyListAnimeNode::fetchMore()
{
- qDebug() << "fetching some more for" << id;
+ qDebug() << "fetching some more for aid" << m_id;
QSqlQuery q(LocalMyList::instance()->database()->connection());
- if (!q.exec("SELECT eid, title_english, epno FROM episode WHERE aid = " + QString::number(id)
- + " ORDER BY epno ASC"))
+ if (!q.exec("SELECT eid, title_english, epno, rating, my_vote FROM episode WHERE aid = " + QString::number(m_id)
+ + " ORDER BY epno ASC "
+ "LIMIT " + QString::number(LIMIT) + " "
+ "OFFSET " + QString::number(childCount())))
return 0;
while (q.next())
{
int id = q.value(0).toInt();
QVariantList data;
- data << q.value(1) << q.value(2);
+ data << q.value(1) << q.value(2)
+ << (q.value(3).toDouble() < 1 ? "n/a" : QString::number(q.value(3).toDouble(), 'f', 2))
+ << (q.value(4).toDouble() < 1 ? "n/a" : QString::number(q.value(4).toDouble(), 'f', 2));
childItems << new MyListEpisodeNode(id, data, this);
}
QString MyListEpisodeNode::totalRowCountSql() const
{
- return "SELECT COUNT(fid) FROM file WHERE eid = " + QString::number(id);
+ return "SELECT COUNT(fid) FROM file WHERE eid = " + QString::number(m_id);
}
int MyListEpisodeNode::fetchMore()
{
- qDebug() << "fetching some more for" << id;
+ qDebug() << "fetching some more for eid" << m_id;
QSqlQuery q(LocalMyList::instance()->database()->connection());
- if (!q.exec("SELECT fid, group_name, version FROM file WHERE eid = " + QString::number(id)))
+ if (!q.exec("SELECT fid, group_name, version, quality FROM file WHERE eid = " + QString::number(m_id)))
return 0;
while (q.next())
{
int id = q.value(0).toInt();
QVariantList data;
- data << q.value(1) << q.value(2);
+ data << q.value(1) << "v" + q.value(2).toString() << q.value(3);
childItems << new MyListFileNode(id, data, this);
}