2 #include <QFontMetrics>
7 #include "matchdaymodel.h"
10 MatchDayModel::MatchDayModel(QObject *parent) :
11 QAbstractTableModel(parent)
13 m_backend = new BackendKicker(this);
15 connect(m_backend, SIGNAL(matchListChanged()),
16 this, SLOT(onMatchListChanged()));
20 int MatchDayModel::rowCount(const QModelIndex&) const
22 int count = m_backend->matchList().count();
27 int MatchDayModel::columnCount(const QModelIndex&) const
32 QVariant MatchDayModel::data(const QModelIndex& index, int role) const
41 if ((match = m_backend->matchList().at(index.row())) == NULL) {
42 return QVariant(QVariant::Invalid);
47 case Qt::DecorationRole:
48 switch (index.column()) {
50 i = match->awayEmblem().pixmap(25,25);
53 i = match->homeEmblem().pixmap(25,25);
56 i = QIcon(":/Icons/Application/football.png").pixmap(20,20);
63 switch (index.column()) {
65 return match->awayEmblem();
68 return match->awayTeam();
71 if (match->state() == Match::NotStarted) {
74 return match->awayScore();
78 return match->homeEmblem();
81 return match->homeTeam();
84 if (match->state() == Match::NotStarted) {
87 return match->homeScore();
91 return match->date().toString("ddd hh mm");
94 return QVariant(QVariant::Invalid);
99 case Qt::SizeHintRole:
101 switch (index.column()) {
127 return QVariant(QVariant::Invalid);
133 case Qt::BackgroundRole:
134 return QColor(0, 0, 0, 120);
137 case Qt::TextAlignmentRole:
138 if (index.column() < 3) {
139 return 0x0002 | 0x0080;
140 } else if (index.column() > 3) {
141 return 0x0001 | 0x0080;
143 return Qt::AlignCenter;
152 return QVariant(QVariant::Invalid);
155 return QVariant(QVariant::Invalid);
160 void MatchDayModel::onMatchListChanged(void)
162 beginInsertRows(QModelIndex(),
163 rowCount(QModelIndex()),
164 rowCount(QModelIndex()));
167 // invalidate complete data
168 emit dataChanged(index(0, 0),
169 index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));
173 void MatchDayModel::update(void)
175 QSettings settings("David Solbach", "BuliScores");
177 this->m_backend->setLeague(settings.value("League", "1. Bundesliga").toString());
178 this->m_backend->update();