- better size calculation
[buliscores] / src / matchdaymodel.cpp
index 89f24d3..c280271 100644 (file)
@@ -1,3 +1,4 @@
+#include <QDebug>
 #include <QColor>
 #include <QFontMetrics>
 #include <QFont>
@@ -8,8 +9,11 @@
 #include "match.h"
 
 MatchDayModel::MatchDayModel(QObject *parent) :
-    QAbstractTableModel(parent)
+    QAbstractTableModel(parent),
+    m_lastRowCount(0),
+    m_settings("David Solbach", "BuliScores")
 {
+
     m_backend = new BackendKicker(this);
 
     connect(m_backend, SIGNAL(matchListChanged()),
@@ -121,7 +125,7 @@ QVariant MatchDayModel::data(const QModelIndex& index, int role) const
             s.setWidth(3);
             break;
         case Date:
-            s.setWidth(110);
+            s.setWidth(75);
             break;
         default:
             return QVariant(QVariant::Invalid);
@@ -159,12 +163,25 @@ QVariant MatchDayModel::data(const QModelIndex& index, int role) const
 // 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));
 
@@ -172,8 +189,6 @@ void MatchDayModel::onMatchListChanged(void)
 
 void MatchDayModel::update(void)
 {
-    QSettings settings("David Solbach", "BuliScores");
-
-    this->m_backend->setLeague(settings.value("League", "1. Bundesliga").toString());
+    this->m_backend->setLeague(m_settings.value("League", "1. Bundesliga").toString());
     this->m_backend->update();
 }