summaryrefslogtreecommitdiffstats
path: root/actorcountmodel.cpp
diff options
context:
space:
mode:
authoram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-11-09 13:53:06 +0000
committeram <am@f440f766-f032-0410-8965-dc7d17de2ca0>2009-11-09 13:53:06 +0000
commitcb507dfbef0e8401c1826a096026c005c50f9784 (patch)
treeeaeeb693c8541e975af5678e5470ffaa7588a96b /actorcountmodel.cpp
parent7e4fd320c0c74bc45e60de18ac5d2b656aa4d821 (diff)
downloadSheMov-cb507dfbef0e8401c1826a096026c005c50f9784.tar.gz
SheMov-cb507dfbef0e8401c1826a096026c005c50f9784.tar.bz2
SheMov-cb507dfbef0e8401c1826a096026c005c50f9784.zip
-changed editarchiveitemdialog to actorwidget
-added actor statistics git-svn-id: file:///var/svn/repos2/shemov/trunk@423 f440f766-f032-0410-8965-dc7d17de2ca0
Diffstat (limited to 'actorcountmodel.cpp')
-rw-r--r--actorcountmodel.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/actorcountmodel.cpp b/actorcountmodel.cpp
new file mode 100644
index 0000000..ac82f97
--- /dev/null
+++ b/actorcountmodel.cpp
@@ -0,0 +1,76 @@
+/*
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version
+ 2 of the License, or (at your option) any later version.
+*/
+
+#include <QSqlQuery>
+#include <QIcon>
+
+#include "actorcountmodel.h"
+
+ActorCountModel::ActorCountModel(QObject *parent) : QAbstractItemModel(parent) {
+ QSqlQuery query("SELECT iactorid, tactorname FROM actor ORDER BY tactorname ASC");
+ QSqlQuery countQuery;
+ countQuery.prepare("SELECT COUNT(*) FROM movieactormap WHERE iactorid = :id");
+ while(query.next()){
+ QVariant *name = new QVariant(query.value(1));
+ countQuery.bindValue(":id", query.value(0));
+ countQuery.exec();
+ QVariant *count;
+ while(countQuery.next()){
+ count = new QVariant(countQuery.value(0));
+ }
+ QList<QVariant*> l;
+ l << name << count;
+ mItems.append(l);
+ }
+ mHeaderData << tr("Model name") << tr("Movies");
+}
+
+ActorCountModel::~ActorCountModel() {
+ foreach(QList<QVariant*> l, mItems){
+ qDeleteAll(l);
+ }
+}
+
+QModelIndex ActorCountModel::index(int row, int column, const QModelIndex &parent) const {
+ if((column > 1) || (row >= mItems.size()) || (row < 0) || (parent != QModelIndex())){
+ return QModelIndex();
+ }
+ return createIndex(row, column, 0);
+}
+
+int ActorCountModel::rowCount(const QModelIndex &) const {
+ return mItems.size();
+}
+
+int ActorCountModel::columnCount(const QModelIndex &) const {
+ return 2;
+}
+
+QVariant ActorCountModel::data(const QModelIndex &idx, int role) const {
+ if(!idx.isValid() || (idx.column() > 1) || (idx.row() > mItems.size())){
+ return QVariant();
+ }
+ switch (role) {
+ case Qt::DisplayRole:
+ return *(mItems.at(idx.row()).at(idx.column()));
+ break;
+ case Qt::DecorationRole:
+ if(idx.column() == 0){
+ return QIcon(":/dildo.png");
+ }
+ break;
+ }
+ return QVariant();
+}
+
+QVariant ActorCountModel::headerData(int section, Qt::Orientation o, int role) const {
+ if((role != Qt::DisplayRole) || (o != Qt::Horizontal) || (section > 1)){
+ return QVariant();
+ }
+ return mHeaderData.at(section);
+}
+