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
45 if ((match = m_backend->matchList().at(index.row())) == NULL) {
46 return QVariant(QVariant::Invalid);
51 case Qt::BackgroundRole:
52 return QBrush(QColor(0, 0, 0, 100));
54 case Qt::DecorationRole:
55 switch (index.column()) {
57 i = match->awayEmblem().pixmap(25,25);
60 i = match->homeEmblem().pixmap(25,25);
63 i = QIcon(":/Icons/Application/football.png").pixmap(20,20);
70 switch (index.column()) {
72 return match->awayEmblem();
75 return match->awayTeam();
78 if (match->state() == Match::NotStarted) {
81 return match->awayScore();
85 return match->homeEmblem();
88 return match->homeTeam();
91 if (match->state() == Match::NotStarted) {
94 return match->homeScore();
98 return match->date().toString("ddd hh mm");
101 return QVariant(QVariant::Invalid);
106 case Qt::SizeHintRole:
108 switch (index.column()) {
134 return QVariant(QVariant::Invalid);
140 case Qt::TextAlignmentRole:
141 if (index.column() < 3) {
142 return 0x0002 | 0x0080;
143 } else if (index.column() > 3) {
144 return 0x0001 | 0x0080;
146 return Qt::AlignCenter;
155 return QVariant(QVariant::Invalid);
158 return QVariant(QVariant::Invalid);
163 void MatchDayModel::onMatchListChanged(void)
166 qDebug() << "beginRemoveRows: " << 0 << ", " << rowCount(QModelIndex()) - 1;
167 beginRemoveRows(QModelIndex(),
173 qDebug() << "beginInsertRows: " << 0 << ", " << m_backend->matchList().count() - 1;
174 beginInsertRows(QModelIndex(),
176 m_backend->matchList().count() - 1);
179 m_lastRowCount = m_backend->matchList().count() - 1;
181 // invalidate complete data
182 qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
183 emit dataChanged(index(0, 0),
184 index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));