match = new Match(hometeam, awayteam, date, this);
m_matchlist.append(match);
- emit matchListChanged();
-
return match;
}
}
}
}
-
-
}
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)
rawdata = reply->readAll();
parsePage(rawdata);
+ emit matchListChanged();
}
#include "backendkicker.h"
#include <QtGui>
-#include <QLabel>
#include <src/mainwidget.h>
int main(int argc, char *argv[])
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;
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"));
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();
}
#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;
public:
explicit MainWidget(QWidget *parent = 0);
- void mousePressEvent(QMouseEvent);
+ void mousePressEvent(QMouseEvent* event);
signals:
+#include <QDebug>
#include <QColor>
#include <QFontMetrics>
#include <QFont>
#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()),
s.setWidth(3);
break;
case Date:
- s.setWidth(110);
+ s.setWidth(75);
break;
default:
return QVariant(QVariant::Invalid);
// 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));
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();
}
#include <QAbstractTableModel>
#include <QFontMetrics>
+#include <QSettings>
#include "backendkicker.h"
private:
QString m_url;
BackendKicker* m_backend;
+ int m_lastRowCount;
+ QSettings m_settings;
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);
};
#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);
}
// 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();
-//}
{
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:
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);
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()
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();
}
#include <QDialog>
#include <QCloseEvent>
+#include <QSettings>
+#include <QAbstractButton>
namespace Ui {
class SettingsDialog;
protected:
void closeEvent(QCloseEvent);
+protected slots:
+ void onLeagueSelected(QAbstractButton* button);
+
private:
Ui::SettingsDialog *ui;
+ QSettings settings;
};
#endif // SETTINGSDIALOG_H
</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>