-#include "matchdaymodel.h"
+#include <QDebug>
+#include <QBrush>
#include <QColor>
#include <QFontMetrics>
#include <QFont>
#include <QIcon>
+#include <QSettings>
+#include <QApplication>
+
+#include "matchdaymodel.h"
+#include "match.h"
-MatchDayModel::MatchDayModel(QObject *parent) :
- QAbstractTableModel(parent)
+MatchDayModel::MatchDayModel(QObject *parent, MatchDayBackend *backend) :
+ QAbstractTableModel(parent),
+ m_lastRowCount(0),
+ m_settings(qApp->organizationName(), qApp->applicationName())
{
- backendkicker = new BackendKicker(this);
+ m_backend = backend;
- connect(backendkicker, SIGNAL(matchListChanged()),
+ connect(m_backend, SIGNAL(matchListChanged()),
this, SLOT(onMatchListChanged()));
-
}
-int MatchDayModel::rowCount(const QModelIndex& index) const
+int MatchDayModel::rowCount(const QModelIndex&) const
{
- int count = backendkicker->matchList().count();
+ int count = m_backend->matchList().count();
return count;
}
-int MatchDayModel::columnCount(const QModelIndex& index) const
+int MatchDayModel::columnCount(const QModelIndex&) const
{
- return 7;
+ return 10;
}
QVariant MatchDayModel::data(const QModelIndex& index, int role) const
QSize s;
QIcon i;
- f.setPixelSize(14);
-
- if ((match = backendkicker->matchList().at(index.row())) == NULL) {
+ if ((match = m_backend->matchList().at(index.row())) == NULL) {
return QVariant(QVariant::Invalid);
}
// DisplayRole
switch (role) {
+ case Qt::BackgroundRole:
+ return QBrush(QColor(20, 20, 20, 100));
+ break;
case Qt::DecorationRole:
switch (index.column()) {
case AwayIcon:
case HomeIcon:
i = match->homeEmblem().pixmap(25,25);
break;
+ case MatchState:
+ switch(match->state()) {
+ case Match::NotStarted:
+ return QIcon(":/bullet-grey").pixmap(15,15);
+ break;
+ case Match::FirstHalf:
+ case Match::SecondHalf:
+ return QIcon(":/bullet-green").pixmap(15,15);
+ break;
+ case Match::HalfTime:
+ return QIcon(":/bullet-yellow").pixmap(15,15);
+ break;
+ case Match::Finished:
+ return QIcon(":/bullet-red").pixmap(15,15);
+ break;
+ default:
+ return QVariant(QVariant::Invalid);
+ }
+
+ break;
}
return i;
break;
case Qt::DisplayRole:
switch (index.column()) {
- case AwayIcon:
- return match->awayEmblem();
- break;
case AwayTeam:
- return match->awayteam();
+ return match->awayTeam();
break;
case AwayScore:
- return match->awayscore();
- break;
- case HomeIcon:
- return match->homeEmblem();
+ if (match->state() == Match::NotStarted) {
+ return "-";
+ } else {
+ return match->awayScore();
+ }
break;
case HomeTeam:
- return match->hometeam();
+ return match->homeTeam();
break;
case HomeScore:
- return match->homescore();
+ if (match->state() == Match::NotStarted) {
+ return "-";
+ } else {
+ return match->homeScore();
+ }
+ break;
+ case Seperator:
+ return ":";
break;
+ case Date:
+ return match->date().toString("ddd hh:mm");
+ break;
+
default:
return QVariant(QVariant::Invalid);
break;
case Qt::SizeHintRole:
s.setHeight(25);
switch (index.column()) {
+ case Spacer:
+ s.setWidth(3);
+ break;
+ case MatchState:
+ s.setWidth(15);
+ break;
case AwayIcon:
s.setWidth(29);
break;
s.setWidth(4);
break;
case Seperator:
- s.setWidth(3);
+ s.setWidth(5);
+ break;
+ case Date:
+ s.setWidth(75);
break;
default:
return QVariant(QVariant::Invalid);
return s;
break;
- case Qt::BackgroundRole:
- return QColor(0, 0, 0, 120);
- break;
-
case Qt::TextAlignmentRole:
- if (index.column() < 3) {
+ if (index.column() < Seperator) {
return 0x0002 | 0x0080;
- } else if (index.column() > 3) {
+ } else if (index.column() > Seperator) {
return 0x0001 | 0x0080;
} else {
return Qt::AlignCenter;
}
break;
- case Qt::FontRole:
+ case Qt::FontRole:
+ f.setPixelSize(14);
return f;
default:
return QVariant(QVariant::Invalid);
}
+
+ return QVariant(QVariant::Invalid);
}
// only adds for now
void MatchDayModel::onMatchListChanged(void)
{
+ //remove all rows
+ //qDebug() << "beginRemoveRows: " << 0 << ", " << rowCount(QModelIndex()) - 1;
+ beginRemoveRows(QModelIndex(),
+ 0,
+ m_lastRowCount);
+ endRemoveRows();
+
+ //add rows
+ //qDebug() << "beginInsertRows: " << 0 << ", " << m_backend->matchList().count() - 1;
beginInsertRows(QModelIndex(),
- rowCount(QModelIndex()),
- rowCount(QModelIndex()));
+ 0,
+ m_backend->matchList().count() - 1);
endInsertRows();
+ m_lastRowCount = m_backend->matchList().count() - 1;
+
// invalidate complete data
+ //qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
emit dataChanged(index(0, 0),
index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));