- better size calculation
authorDavid Solbach <d@vidsolbach.de>
Tue, 12 Oct 2010 22:47:47 +0000 (00:47 +0200)
committerDavid Solbach <d@vidsolbach.de>
Tue, 12 Oct 2010 22:47:47 +0000 (00:47 +0200)
- removed some unnecessary code
- settings dialog kind of works now

src/backendkicker.cpp
src/main.cpp
src/mainwidget.cpp
src/mainwidget.h
src/matchdaymodel.cpp
src/matchdaymodel.h
src/scoretable.cpp
src/scoretable.h
src/settingsdialog.cpp
src/settingsdialog.h
src/settingsdialog.ui

index 6e685cd..e4f0dd0 100644 (file)
@@ -34,8 +34,6 @@ Match* BackendKicker::getMatch(QString hometeam, QString awayteam, QDateTime dat
     match = new Match(hometeam, awayteam, date, this);
     m_matchlist.append(match);
 
-    emit matchListChanged();
-
     return match;
 }
 
@@ -180,8 +178,6 @@ void BackendKicker::parsePage (QString htmlstr)
              }
         }
     }
-
-
 }
 
 void BackendKicker::setLeague(QString league)
@@ -193,18 +189,22 @@ void BackendKicker::setLeague(QString league)
     } else if (league == "tipp3 Bundesliga") {
         m_URL = "http://www.kicker.de/news/fussball/intligen/oesterreich/tipp3-bundesliga/2010-11/spieltag.html";
     }
+
+    // delete last data
+    this->m_matchlist.clear();
+    emit matchListChanged();
 }
 
 void BackendKicker::update()
 {
-    QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
+    //QString URL = "file:///home/david/Projects/git-buliscores/testdata/spieltag.html";
 
     QNetworkAccessManager *manager = new QNetworkAccessManager(this);
     connect(manager, SIGNAL(finished(QNetworkReply*)),
             this, SLOT(dlndFinished(QNetworkReply*)));
 
     qDebug() << "URL: " << m_URL;
-    manager->get(QNetworkRequest(QUrl(URL)));
+    manager->get(QNetworkRequest(QUrl(m_URL)));
 }
 
 void BackendKicker::dlndFinished(QNetworkReply *reply)
@@ -218,4 +218,5 @@ void BackendKicker::dlndFinished(QNetworkReply *reply)
 
     rawdata = reply->readAll();
     parsePage(rawdata);
+    emit matchListChanged();
 }
index 52792ae..9adfbef 100644 (file)
@@ -43,7 +43,6 @@
 #include "backendkicker.h"
 
 #include <QtGui>
-#include <QLabel>
 #include <src/mainwidget.h>
 
 int main(int argc, char *argv[])
index e9cdc75..3c2b110 100644 (file)
@@ -9,7 +9,8 @@
 MainWidget::MainWidget(QWidget *parent) :
     QWidget(parent),
     m_datamodel(new MatchDayModel(this)),
-    m_scoretbl(new ScoreTable(this, m_datamodel))
+    m_scoretbl(new ScoreTable(m_datamodel)),
+    m_settingsdlg(new SettingsDialog(this))
 {
     QFont f;
     QPalette palette;
@@ -17,6 +18,7 @@ MainWidget::MainWidget(QWidget *parent) :
     f.setPixelSize(14);
     palette.setColor(QPalette::Window, QColor(100, 100, 100, 127));
 
+    m_statuslbl.setAttribute(Qt::WA_TransparentForMouseEvents);
     m_statuslbl.setPalette(palette);
     m_statuslbl.setFont(f);
     m_statuslbl.setText(tr("Last Update: Never"));
@@ -26,27 +28,23 @@ MainWidget::MainWidget(QWidget *parent) :
 
     this->setLayout(&m_layout);
 
-    //m_layout.addWidget(&m_statuslbl);
+    m_layout.addWidget(&m_statuslbl);
     m_layout.addWidget(m_scoretbl);
 
-
-
     this->setAutoFillBackground(true);
+
+    connect(m_settingsdlg, SIGNAL(accepted()),
+            m_datamodel, SLOT(update()));
 }
 
-void MainWidget::mousePressEvent(QMouseEvent)
+void MainWidget::mousePressEvent(QMouseEvent* event)
 {
-    this->m_datamodel->update();
+    this->showSettingsDialog();
 }
 
 
 void MainWidget::showSettingsDialog()
 {
-    QSettings settings("David Solbach", "BuliScores");
-
-    SettingsDialog* sd = new SettingsDialog(this);
-    sd->show();
-
-    m_datamodel->update();
+    m_settingsdlg->show();
 }
 
index 0e97002..5049189 100644 (file)
@@ -6,14 +6,16 @@
 #include <QLabel>
 
 #include "scoretable.h"
+#include "settingsdialog.h"
 
 
 class MainWidget : public QWidget
 {
     Q_OBJECT
 private:
-    MatchDayModel* m_datamodel;
-    ScoreTable*    m_scoretbl;
+    MatchDayModel*  m_datamodel;
+    ScoreTable*     m_scoretbl;
+    SettingsDialog* m_settingsdlg;
 
     QVBoxLayout m_layout;
     QLabel      m_statuslbl;
@@ -21,7 +23,7 @@ private:
 public:
     explicit MainWidget(QWidget *parent = 0);
 
-    void mousePressEvent(QMouseEvent);
+    void mousePressEvent(QMouseEvent* event);
 
 signals:
 
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();
 }
index b99ef48..21fc9fc 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <QAbstractTableModel>
 #include <QFontMetrics>
+#include <QSettings>
 
 #include "backendkicker.h"
 
@@ -24,6 +25,8 @@ class MatchDayModel : public QAbstractTableModel
 private:
     QString         m_url;
     BackendKicker*  m_backend;
+    int             m_lastRowCount;
+    QSettings       m_settings;
 
 
 public:
@@ -33,15 +36,11 @@ public:
     int columnCount(const QModelIndex& index) const;
     QVariant data(const QModelIndex& index, int role) const;
 
-    void update(void);
-
-signals:
-
-
 protected slots:
     void onMatchListChanged(void);
 
 public slots:
+    void update(void);
 
 };
 
index a784b36..7b9cbf1 100644 (file)
@@ -5,15 +5,17 @@
 #include "scoretable.h"
 #include "matchdaymodel.h"
 
-ScoreTable::ScoreTable(QWidget *parent, MatchDayModel* model) :
+ScoreTable::ScoreTable(MatchDayModel* model, QWidget *parent) :
     QTableView(parent)
 {
-    this->setAttribute(Qt::WA_TranslucentBackground);
     this->setAttribute(Qt::WA_TransparentForMouseEvents);
+    this->setAttribute(Qt::WA_TranslucentBackground);
 
     this->setModel(model);
     this->setSelectionMode(QAbstractItemView::NoSelection);
 
+    this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
+
     this->verticalHeader()->hide();
     this->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
     this->verticalHeader()->setMinimumSectionSize(1);
@@ -46,41 +48,23 @@ QSize ScoreTable::sizeHint() const
     }
     // add missing few pixels (from borders mabye?)
     // TODO: find better solution!
-    s.setHeight(s.height() + 3);
+    s.setHeight(s.height() + 2);
 
     return s;
 }
 
 void ScoreTable::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 {
-    QSize s;
-
     // this will recalculate section sizes
     QTableView::dataChanged(topLeft, bottomRight);
 
-    for (int i = 0; i < horizontalHeader()->count(); i++) {
-        s.setWidth(s.width() + horizontalHeader()->sectionSize(i));
-    }
-    // add missing few pixels (from borders mabye?)
-    // TODO: find better solution!
-    s.setWidth(s.width());
-    for (int i = 0; i < verticalHeader()->count(); i++) {
-        s.setHeight(s.height() + verticalHeader()->sectionSize(i));
-    }
-    // add missing few pixels (from borders mabye?)
-    // TODO: find better solution!
-    s.setHeight(s.height() + 3);
-
-    this->resize(s);
-    this->parentWidget()->resize(s);
-
-    qDebug() << s;
+    this->updateGeometry();
+}
 
-    updateGeometry();
+void ScoreTable::mousePressEvent(QMouseEvent* event)
+{
+    MatchDayModel* m = (MatchDayModel*)this->model();
+    m->update();
 }
 
-//void ScoreTable::mousePressEvent(QMouseEvent* event)
-//{
-//    event->ignore();
-//}
 
index dca9a6b..100b8cc 100644 (file)
@@ -10,10 +10,10 @@ class ScoreTable : public QTableView
 {
     Q_OBJECT
 protected:
-    //void mousePressEvent(QMouseEvent* event);
+    void mousePressEvent(QMouseEvent*);
 
 public:
-    explicit ScoreTable(QWidget *parent, MatchDayModel* model);
+    explicit ScoreTable(MatchDayModel* model, QWidget *parent = 0);
     QSize sizeHint() const;
 
 signals:
index 132d66f..b251b9f 100644 (file)
@@ -5,9 +5,9 @@
 
 SettingsDialog::SettingsDialog(QWidget *parent) :
     QDialog(parent),
-    ui(new Ui::SettingsDialog)
+    ui(new Ui::SettingsDialog),
+    settings("David Solbach", "BuliScores")
 {
-    QSettings settings("David Solbach", "BuliScores");
     QString league;
 
     ui->setupUi(this);
@@ -17,12 +17,15 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
     if (league == "1. Bundesliga") {
         ui->rbBL1->setChecked(true);
     } else if (league == "2. Bundesliga") {
-        ui->rbBL1->setChecked(true);
+        ui->rbBL2->setChecked(true);
     } else if (league == "tipp3 Bundesliga") {
-        ui->rbBL1->setChecked(true);
+        ui->rbT3BL->setChecked(true);
     } else {
         ui->rbBL1->setChecked(true);
     }
+
+    connect(ui->buttonGroup, SIGNAL(buttonClicked(QAbstractButton*)),
+            this, SLOT(onLeagueSelected(QAbstractButton*)));
 }
 
 SettingsDialog::~SettingsDialog()
@@ -30,9 +33,8 @@ SettingsDialog::~SettingsDialog()
     delete ui;
 }
 
-void SettingsDialog::closeEvent(QCloseEvent)
+void SettingsDialog::onLeagueSelected(QAbstractButton* button)
 {
-    QSettings settings("David Solbach", "BuliScores");
-
-    settings.setValue("League", ui->buttonGroup->checkedButton()->text());
+    settings.setValue("League", button->text());
+    this->accept();
 }
index c902c28..e38f3e2 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <QDialog>
 #include <QCloseEvent>
+#include <QSettings>
+#include <QAbstractButton>
 
 namespace Ui {
     class SettingsDialog;
@@ -19,8 +21,12 @@ public:
 protected:
     void closeEvent(QCloseEvent);
 
+protected slots:
+    void onLeagueSelected(QAbstractButton* button);
+
 private:
     Ui::SettingsDialog *ui;
+    QSettings settings;
 };
 
 #endif // SETTINGSDIALOG_H
index 72267f7..968ee7d 100644 (file)
   </layout>
  </widget>
  <resources/>
- <connections>
-  <connection>
-   <sender>buttonGroup</sender>
-   <signal>buttonClicked(QAbstractButton*)</signal>
-   <receiver>SettingsDialog</receiver>
-   <slot>accept()</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>-1</x>
-     <y>-1</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>199</x>
-     <y>149</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
  <buttongroups>
   <buttongroup name="buttonGroup"/>
  </buttongroups>