3 #include <QFontMetrics>
8 #include "matchdaymodel.h"
11 MatchDayModel::MatchDayModel(QObject *parent) :
12 QAbstractTableModel(parent),
14 m_settings("David Solbach", "BuliScores")
17 m_backend = new BackendKicker(this);
19 connect(m_backend, SIGNAL(matchListChanged()),
20 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::DecorationRole:
52 switch (index.column()) {
54 i = match->awayEmblem().pixmap(25,25);
57 i = match->homeEmblem().pixmap(25,25);
60 i = QIcon(":/Icons/Application/football.png").pixmap(20,20);
67 switch (index.column()) {
69 return match->awayEmblem();
72 return match->awayTeam();
75 if (match->state() == Match::NotStarted) {
78 return match->awayScore();
82 return match->homeEmblem();
85 return match->homeTeam();
88 if (match->state() == Match::NotStarted) {
91 return match->homeScore();
95 return match->date().toString("ddd hh mm");
98 return QVariant(QVariant::Invalid);
103 case Qt::SizeHintRole:
105 switch (index.column()) {
131 return QVariant(QVariant::Invalid);
137 case Qt::BackgroundRole:
138 return QColor(0, 0, 0, 120);
141 case Qt::TextAlignmentRole:
142 if (index.column() < 3) {
143 return 0x0002 | 0x0080;
144 } else if (index.column() > 3) {
145 return 0x0001 | 0x0080;
147 return Qt::AlignCenter;
156 return QVariant(QVariant::Invalid);
159 return QVariant(QVariant::Invalid);
164 void MatchDayModel::onMatchListChanged(void)
167 qDebug() << "beginRemoveRows: " << 0 << ", " << rowCount(QModelIndex()) - 1;
168 beginRemoveRows(QModelIndex(),
174 qDebug() << "beginInsertRows: " << 0 << ", " << m_backend->matchList().count() - 1;
175 beginInsertRows(QModelIndex(),
177 m_backend->matchList().count() - 1);
180 m_lastRowCount = m_backend->matchList().count() - 1;
182 // invalidate complete data
184 qDebug() << "rowCount @ emit dataChanged: " << rowCount(QModelIndex());
185 emit dataChanged(index(0, 0),
186 index(rowCount(QModelIndex()) - 1, columnCount(QModelIndex()) - 1));
190 void MatchDayModel::update(void)
192 this->m_backend->setLeague(m_settings.value("League", "1. Bundesliga").toString());
193 this->m_backend->update();