4 #include <QFontMetrics>
8 #include <QApplication>
10 #include "matchdaymodel.h"
13 MatchDayModel::MatchDayModel(QObject *parent, MatchDayBackend *backend) :
14 QAbstractTableModel(parent),
16 m_settings(qApp->organizationName(), qApp->applicationName())
20 connect(m_backend, SIGNAL(matchListChanged()),
21 this, SLOT(onMatchListChanged()));
24 int MatchDayModel::rowCount(const QModelIndex&) const
26 int count = m_backend->matchList().count();
31 int MatchDayModel::columnCount(const QModelIndex&) const
36 QVariant MatchDayModel::data(const QModelIndex& index, int role) const
43 if ((match = m_backend->matchList().at(index.row())) == NULL) {
44 return QVariant(QVariant::Invalid);
49 case Qt::BackgroundRole:
50 return QBrush(QColor(20, 20, 20, 100));
52 case Qt::DecorationRole:
53 switch (index.column()) {
55 i = match->awayEmblem().pixmap(25,25);
58 i = match->homeEmblem().pixmap(25,25);
61 switch(match->state()) {
62 case Match::NotStarted:
63 return QIcon(":/bullet-grey").pixmap(15,15);
65 case Match::FirstHalf:
66 case Match::SecondHalf:
67 return QIcon(":/bullet-green").pixmap(15,15);
70 return QIcon(":/bullet-yellow").pixmap(15,15);
73 return QIcon(":/bullet-red").pixmap(15,15);
76 return QVariant(QVariant::Invalid);
85 switch (index.column()) {
87 return match->awayTeam();
90 if (match->state() == Match::NotStarted) {
93 return match->awayScore();
97 return match->homeTeam();
100 if (match->state() == Match::NotStarted) {
103 return match->homeScore();
110 return match->date().toString("ddd hh:mm");
114 return QVariant(QVariant::Invalid);
119 case Qt::SizeHintRole:
121 switch (index.column()) {
153 return QVariant(QVariant::Invalid);
159 case Qt::TextAlignmentRole:
160 if (index.column() < Seperator) {
161 return 0x0002 | 0x0080;
162 } else if (index.column() > Seperator) {
163 return 0x0001 | 0x0080;
165 return Qt::AlignCenter;
175 return QVariant(QVariant::Invalid);
178 return QVariant(QVariant::Invalid);
183 void MatchDayModel::onMatchListChanged(void)
186 //qDebug() << "beginRemoveRows: " << 0 << ", " << rowCount(QModelIndex()) - 1;
187 beginRemoveRows(QModelIndex(),
193 //qDebug() << "beginInsertRows: " << 0 << ", " << m_backend->matchList().count() - 1;
194 beginInsertRows(QModelIndex(),
196 m_backend->matchList().count() - 1);
199 m_lastRowCount = m_backend->matchList().count() - 1;
201 // invalidate complete data
202 //qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
203 emit dataChanged(index(0, 0),
204 index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));