TODO General:
- New score dialog should be the same as main view (f.ex showing
subtotals, totals, and score colors).
-- edit course table is selectable (chk others)
-- Settings
- Use syslog
- Year filters and maybe more, must be easy to apply
-- If course is missing the score view should show NA in par/hcp. Now
- it shows score.
+
+Settings
+ - Play/view mode: shots or points
+ - Data store: internal or external MMC
TODO Debian packaging
- install data to SD card if present
+scorecard (0.17) unstable; urgency=low
+
+ * Score sort order can be selected from settings
+ * Home Club setting is used when entering new score
+ * Score view shows how many shots you went over (or under ;)
+ * Bigger fonts (20pt)
+ * Added bug tracker link to debian pkg - ready for extras testing
+
+ -- Sakari Poussa <spoussa@gmail.com> Fri, 28 May 2010 00:00:59 +0300
+
scorecard (0.16) unstable; urgency=low
* Fixed few crashes when edit/delete score/course
Package: scorecard
Architecture: any
Depends: libqt4-gui (>= 4.6.2~git20100310)
-Description: Simple golf score card application for N900 to keep track of your golf scores
+Description: N900 application to keep track of your golf scores
.
Further Information: http://scorecard.garage.maemo.org
+XSBC-Bugtracker: https://garage.maemo.org/tracker/?group_id=622
XB-Maemo-Display-Name: ScoreCard
XB-Maemo-Icon-26:
iVBORw0KGgoAAAANSUhEUgAAABoAAAAaCAYAAACpSkzOAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A
QTableView * table = new QTableView;
table->showGrid();
table->setSelectionMode(QAbstractItemView::NoSelection);
- table->setStyleSheet(ScoreStyle::style());
+ table->setStyleSheet(defaultStyleSheet);
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
table->horizontalHeader()->hide();
table->horizontalHeader()->hide();
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
- table->setStyleSheet(ScoreStyle::style());
+ table->setStyleSheet(defaultStyleSheet);
}
void CourseDialog::init(Course *course)
Club::Club(const QXmlAttributes &attrs, bool readOnly)
: m_readOnly(readOnly)
{
+ m_homeClub = false;
name = attrs.value("name");
}
Club::Club(const QDomElement node, bool readOnly)
: m_readOnly(readOnly)
{
+ m_homeClub = false;
name = node.attribute("name", "");
}
Club::Club(QString &name, bool readOnly)
: m_readOnly(readOnly)
{
+ m_homeClub = false;
this->name = name;
}
Course *getCourse(const QString &courseName);
bool isEmpty();
bool isReadOnly();
+ void setHomeClub(bool value) { m_homeClub = value; }
+ bool isHomeClub() { return m_homeClub; }
QList <Course *> getCourseList() { return courseList; } // HACK: fixme
private:
bool m_readOnly;
+ bool m_homeClub;
QList <Course *> courseList;
QString name;
};
QString logFile("/tmp/scorecard.log");
QString titleScores("ScoreCard - Scores");
QString titleCourses("ScoreCard - Courses");
-QString settingsGroup("Settings");
-QString settingsHcp("hcp");
-QString settingsHomeClub("home-club");
-QString settingsDefaultCourses("default-courses");
bool dateLessThan(const Score *s1, const Score *s2)
{
- return (*s1) < (*s2);
+ return (*s1) < (*s2);
}
bool dateMoreThan(const Score *s1, const Score *s2)
{
- return (*s1) > (*s2);
+ return (*s1) > (*s2);
}
+
+bool scoreMoreThan(const Score *s1, const Score *s2)
+{
+ return s1->getTotal(Total) > s2->getTotal(Total);
+}
+
// Find score based on club and course name
Score *MainWindow::findScore(QString & clubName, QString & courseName)
{
}
}
+void MainWindow::markHomeClub()
+{
+ TRACE;
+ QListIterator<Club *> i(clubList);
+ Club *c;
+
+ while (i.hasNext()) {
+ c = i.next();
+ if (c->getName() == conf.homeClub)
+ c->setHomeClub(true);
+ else
+ c->setHomeClub(false);
+ }
+}
+
+void MainWindow::sortScoreList()
+{
+ if (conf.sortOrder == "Date")
+ qSort(scoreList.begin(), scoreList.end(), dateMoreThan);
+ else if (conf.sortOrder == "Score")
+ qSort(scoreList.begin(), scoreList.end(), scoreMoreThan);
+}
MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
{
- resize(800, 480);
+ resize(800, 480);
#ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5StackedWindow);
+ setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
- loadSettings();
+ loadSettings();
- centralWidget = new QWidget(this);
+ centralWidget = new QWidget(this);
- setCentralWidget(centralWidget);
+ setCentralWidget(centralWidget);
- loadScoreFile(scoreFile, scoreList);
- if (conf.defaultCourses == "Yes")
- loadClubFile(masterFile, clubList, true);
- loadClubFile(clubFile, clubList);
+ loadScoreFile(scoreFile, scoreList);
+ if (conf.defaultCourses == "Yes")
+ loadClubFile(masterFile, clubList, true);
+ loadClubFile(clubFile, clubList);
+ markHomeClub();
- // Sort the scores based on dates
- qSort(scoreList.begin(), scoreList.end(), dateMoreThan);
- createActions();
- createMenus();
+ // Sort the scores based on settings
+ sortScoreList();
- createListView(scoreList, clubList);
+ createActions();
+ createMenus();
- createLayoutList(centralWidget);
+ createListView(scoreList, clubList);
- scoreWindow = new ScoreWindow(this);
- courseWindow = new CourseWindow(this);
+ createLayoutList(centralWidget);
+
+ scoreWindow = new ScoreWindow(this);
+ courseWindow = new CourseWindow(this);
}
void MainWindow::loadSettings(void)
{
TRACE;
- bool external = false;
+ bool external = false;
- QDir mmc(mmcDir);
- if (mmc.exists())
- external = true;
+ QDir mmc(mmcDir);
+ if (mmc.exists())
+ external = true;
- // TODO: make via user option, automatic will never work
- external = false;
+ // TODO: make via user option, automatic will never work
+ external = false;
#ifndef Q_WS_MAEMO_5
- dataDir = "./" + dataDirName;
+ dataDir = "./" + dataDirName;
#else
- if (external) {
- dataDir = mmcDir + "/" + appName + "/" + dataDirName;
- }
- else {
- dataDir = topDir + "/" + appName + "/" + dataDirName;
- }
-#endif
- scoreFile = dataDir + "/" + scoreFileName;
- clubFile = dataDir + "/" + clubFileName;
- masterFile = dataDir + "/" + masterFileName;
-
- QDir dir(dataDir);
- if (!dir.exists())
- if (!dir.mkpath(dataDir)) {
- qWarning() << "Unable to create: " + dataDir;
- return;
+ if (external) {
+ dataDir = mmcDir + "/" + appName + "/" + dataDirName;
}
- qDebug() << "Data is at:" + dataDir;
+ else {
+ dataDir = topDir + "/" + appName + "/" + dataDirName;
+ }
+#endif
+ scoreFile = dataDir + "/" + scoreFileName;
+ clubFile = dataDir + "/" + clubFileName;
+ masterFile = dataDir + "/" + masterFileName;
+
+ QDir dir(dataDir);
+ if (!dir.exists())
+ if (!dir.mkpath(dataDir)) {
+ qWarning() << "Unable to create: " + dataDir;
+ return;
+ }
+ qDebug() << "Data is at:" + dataDir;
- settings.beginGroup(settingsGroup);
- conf.hcp = settings.value(settingsHcp);
- conf.homeClub = settings.value(settingsHomeClub);
- conf.defaultCourses = settings.value(settingsDefaultCourses);
- settings.endGroup();
+ settings.beginGroup(settingsGroup);
+ conf.hcp = settings.value(settingsHcp);
+ conf.homeClub = settings.value(settingsHomeClub);
+ conf.sortOrder = settings.value(settingsSortOrder);
+ conf.defaultCourses = settings.value(settingsDefaultCourses);
+ settings.endGroup();
- // Use default courses if no settings for that
- if (!conf.defaultCourses.isValid())
- conf.defaultCourses = "Yes";
+ // Use default courses if no settings for that
+ if (!conf.defaultCourses.isValid())
+ conf.defaultCourses = "Yes";
- qDebug() << "Settings: " << conf.hcp << conf.homeClub << conf.defaultCourses;
+ // Use date sort order if no settings for that
+ if (!conf.sortOrder.isValid())
+ conf.sortOrder = "Yes";
+
+ qDebug() << "Settings: " << conf.hcp << conf.homeClub << conf.sortOrder << conf.defaultCourses;
}
void MainWindow::saveSettings(void)
settings.setValue(settingsHcp, conf.hcp);
if (conf.homeClub.isValid())
settings.setValue(settingsHomeClub, conf.homeClub);
+ if (conf.sortOrder.isValid())
+ settings.setValue(settingsSortOrder, conf.sortOrder);
if (conf.defaultCourses.isValid())
settings.setValue(settingsDefaultCourses, conf.defaultCourses);
settings.endGroup();
scoreListModel = new ScoreListModel(scoreList, clubList);
courseListModel = new CourseListModel(clubList);
- list->setStyleSheet(ScoreStyle::style());
+ list->setStyleSheet(defaultStyleSheet);
list->setSelectionMode(QAbstractItemView::SingleSelection);
list->setProperty("FingerScrolling", true);
Score *score = new Score(scores, clubName, courseName, date);
scoreList << score;
- // Sort the scores based on dates
- qSort(scoreList.begin(), scoreList.end(), dateMoreThan);
+ // Sort the scores based on settings
+ sortScoreList();
// Save it
saveScoreFile(scoreFile, scoreList);
scoreListModel->update(scoreList);
void MainWindow::viewStatistics()
{
TRACE;
- QMainWindow *win = new QMainWindow(this);
- QString title = "Statistics";
- win->setWindowTitle(title);
+ QMainWindow *win = new QMainWindow(this);
+ QString title = "Statistics";
+ win->setWindowTitle(title);
#ifdef Q_WS_MAEMO_5
- win->setAttribute(Qt::WA_Maemo5StackedWindow);
+ win->setAttribute(Qt::WA_Maemo5StackedWindow);
#endif
- StatModel *model = new StatModel(clubList, scoreList);
+ StatModel *model = new StatModel(clubList, scoreList);
- QTableView *table = new QTableView;
- table->showGrid();
- table->setSelectionMode(QAbstractItemView::NoSelection);
- table->setStyleSheet(ScoreStyle::style());
- table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
- table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
- table->verticalHeader()->setAutoFillBackground(true);
- table->setModel(model);
+ QTableView *table = new QTableView;
+ table->showGrid();
+ table->setSelectionMode(QAbstractItemView::NoSelection);
+ table->setStyleSheet(statStyleSheet);
+ table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
+ table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+ table->verticalHeader()->setAutoFillBackground(true);
+ table->setModel(model);
- QWidget *central = new QWidget(win);
- win->setCentralWidget(central);
+ QWidget *central = new QWidget(win);
+ win->setCentralWidget(central);
- QTextEdit *textEdit = new QTextEdit;
+ QTextEdit *textEdit = new QTextEdit;
- textEdit->setReadOnly(true);
+ textEdit->setReadOnly(true);
- QVBoxLayout *infoLayout = new QVBoxLayout;
- infoLayout->addWidget(table);
+ QVBoxLayout *infoLayout = new QVBoxLayout;
+ infoLayout->addWidget(table);
- QHBoxLayout *mainLayout = new QHBoxLayout(central);
- mainLayout->addLayout(infoLayout);
- central->setLayout(mainLayout);
+ QHBoxLayout *mainLayout = new QHBoxLayout(central);
+ mainLayout->addLayout(infoLayout);
+ central->setLayout(mainLayout);
- win->show();
+ win->show();
}
void MainWindow::viewSettings()
QString newValue = conf.defaultCourses.toString();
saveSettings();
- qDebug() << "Settings:" << oldValue << "->" << newValue;
-
// Reload club list, or drop r/o courses from list
if (oldValue == "Yes" && newValue == "No") {
flushReadOnlyItems();
courseListModel->update(clubList);
list->update();
}
+ // TODO: do these only if needed
+ markHomeClub();
+ sortScoreList();
+ scoreListModel->update(scoreList);
+ list->update();
}
}
void MainWindow::loadScoreFile(QString &fileName, QList<Score *> &list)
{
- ScoreXmlHandler handler(list);
+ ScoreXmlHandler handler(list);
- if (handler.parse(fileName))
- qDebug() << "File loaded:" << fileName << " entries:" << list.size();
+ if (handler.parse(fileName))
+ qDebug() << "File loaded:" << fileName << " entries:" << list.size();
}
void MainWindow::saveScoreFile(QString &fileName, QList<Score *> &list)
{
- ScoreXmlHandler handler(list);
+ ScoreXmlHandler handler(list);
- if (handler.save(fileName))
- // TODO: banner
- qDebug() << "File saved:" << fileName << " entries:" << list.size();
- else
- qWarning() << "Unable to save:" << fileName;
+ if (handler.save(fileName))
+ // TODO: banner
+ qDebug() << "File saved:" << fileName << " entries:" << list.size();
+ else
+ qWarning() << "Unable to save:" << fileName;
}
void MainWindow::loadClubFile(QString &fileName, QList<Club *> &list, bool readOnly)
void MainWindow::saveClubFile(QString &fileName, QList<Club *> &list)
{
- ClubXmlHandler handler(list);
-
- if (handler.save(fileName))
- // TODO: banner
- qDebug() << "File saved:" << fileName << " entries:" << list.size();
- else
- qWarning() << "Unable to save:" << fileName;
+ ClubXmlHandler handler(list);
+ if (handler.save(fileName))
+ // TODO: banner
+ qDebug() << "File saved:" << fileName << " entries:" << list.size();
+ else
+ qWarning() << "Unable to save:" << fileName;
}
Score * currentScore();
Score * findScore(QString & clubName, QString & courseName);
void flushReadOnlyItems();
+ void markHomeClub();
+ void sortScoreList();
void showNote(QString msg);
void getStat(QTextEdit *);
#ifndef SCORE_COMMON_H
#define SCORE_COMMON_H
-#if 0
-#define SC_BLUE_THEME
-
-QColor colorHoleBg(64, 64, 64);
-QColor colorHoleFg(Qt::yellow);
-QColor colorBirdie(00, 0x99, 00);
-QColor colorPar(Qt::black);
-#ifdef SC_ORANGE_THEME
-QColor colorBogey(0xfc, 0xaf, 0x3e);
-QColor colorDoubleBogey(0xf5, 0x79, 0x00);
-QColor colorBad(0xce, 0x5c, 0x00);
-#endif
-#ifdef SC_BLUE_THEME
-QColor colorBogey(0x20, 0x4a, 0x87);
-QColor colorDoubleBogey(0x34, 0x65, 0xa4);
-QColor colorBad(0x72, 0x9f, 0xcf);
-#endif
-QColor colorSubTotal(Qt::black);
-QColor colorTotal(Qt::black);
-#endif
#include <QColor>
+static QString settingsGroup("Settings");
+static QString settingsHcp("hcp");
+static QString settingsHomeClub("home-club");
+static QString settingsSortOrder("sort-order");
+static QString settingsDefaultCourses("default-courses");
+
#ifndef WANT_DEBUG
#define TRACE
#else
#define TRACE qDebug()<<QString("[%1] %2(): %3").arg(__FILE__).arg(__func__).arg(__LINE__);
#endif
+static int fontSize = 20;
class AppSettings {
public:
QVariant hcp;
QVariant homeClub;
+ QVariant sortOrder;
QVariant defaultCourses;
};
static QColor total() { return Qt::white; }
};
-class ScoreStyle {
-public:
- static QString style()
- {
- return QString("QTableView {"
- "background-color: white;"
- "color : gray;"
- "border: solid green;"
- "font-size : 20px;"
- "font-style : italic;"
- "}"
- "QHeaderView::section {"
- "color : white;"
- "border: solid green;"
- "font: bold italic large;"
- "}");
-
+static QString statStyleSheet("QTableView {color : white;}");
+static QString defaultStyleSheet("QTableView {"
+ "background-color: white;"
+ "color : gray;"
+ "border: solid green;"
+ "}"
+ "QHeaderView::section {"
+ "color : white;"
+ "border: solid green;"
+ "}");
#if 0
- "QAbstractItemView::item[role=\"header\"]{"
- "background : orange;"
- "color : yellow;"
- "border: solid green;"
- "font-size : 16px;"
- "}"
- "QAbstractItemView::item"
- "background : orange;"
- "color : white;"
- "border: solid green;"
- "font-size : 16px;"
- "}"
- "QTableView {"
- "alternate-background-color: yellow;"
- "background-color: red;"
- "color : blue;"
- "border: solid green;"
- "gridline-color: green;"
- "}"
-
+"QAbstractItemView::item[role=\"header\"]{"
+"background : orange;"
+"color : yellow;"
+"border: solid green;"
+"font-size : 16px;"
+"}"
+"QAbstractItemView::item"
+"background : orange;"
+"color : white;"
+"border: solid green;"
+"font-size : 16px;"
+"}"
+"QTableView {"
+"alternate-background-color: yellow;"
+"background-color: red;"
+"color : blue;"
+"border: solid green;"
+"gridline-color: green;"
+"}"
#endif
- }
- static QString headerView()
- {
- return QString("QHeaderView::section { background-color : #404040 }");
- //return QString("QHeaderView { background-color : #404040 }");
- return QString("QTableView { background-color : red }");
- }
-};
-
#endif
QTableView * table = new QTableView;
table->showGrid();
table->setSelectionMode(QAbstractItemView::NoSelection);
- table->setStyleSheet(ScoreStyle::style());
+ table->setStyleSheet(defaultStyleSheet);
table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
table->horizontalHeader()->hide();
////////////////////////////////////////////////////////////////////////////////
SelectDialog::SelectDialog(QWidget *parent) : QDialog(parent)
{
- resize(800, 350);
+ resize(800, 350);
- QWidget *centralWidget = new QWidget(this);
- createLayout(centralWidget);
+ QWidget *centralWidget = new QWidget(this);
+ createLayout(centralWidget);
- setWindowTitle(tr("ScoreCard: Select Course and Date"));
+ setWindowTitle(tr("ScoreCard: Select Course and Date"));
}
void SelectDialog::createLayout(QWidget *parent)
{
- listClub = new QListWidget(parent);
- pushButtonNext = new QPushButton(tr("Next"));
+ listWidgetClub = new QListWidget(parent);
+ pushButtonNext = new QPushButton(tr("Next"));
- connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
+ connect(pushButtonNext, SIGNAL(clicked()), this, SLOT(next()));
- QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
- buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
+ QDialogButtonBox * buttonBox = new QDialogButtonBox(Qt::Vertical);
+ buttonBox->addButton(pushButtonNext, QDialogButtonBox::ActionRole);
- leftLayout = new QVBoxLayout;
- leftLayout->addWidget(listClub);
+ leftLayout = new QVBoxLayout;
+ leftLayout->addWidget(listWidgetClub);
#ifdef Q_WS_MAEMO_5
- dateButton = new QMaemo5ValueButton();
- dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText);
- dateButton->setPickSelector(new QMaemo5DatePickSelector());
- dateButton->setText(QString::fromUtf8("Date"));
- leftLayout->addWidget(dateButton);
+ dateButton = new QMaemo5ValueButton();
+ dateButton->setValueLayout(QMaemo5ValueButton::ValueUnderText);
+ dateButton->setPickSelector(new QMaemo5DatePickSelector());
+ dateButton->setText(QString::fromUtf8("Date"));
+ leftLayout->addWidget(dateButton);
#else
- QDate today(QDate::currentDate());
- lineEditDate = new QLineEdit;
- lineEditDate->setText(today.toString("yyyy-MM-dd"));
- date = new QDateEdit;
- leftLayout->addWidget(date);
- leftLayout->addWidget(lineEditDate);
+ QDate today(QDate::currentDate());
+ lineEditDate = new QLineEdit;
+ lineEditDate->setText(today.toString("yyyy-MM-dd"));
+ date = new QDateEdit;
+ leftLayout->addWidget(date);
+ leftLayout->addWidget(lineEditDate);
#endif
- rightLayout = new QVBoxLayout;
- rightLayout->addStretch();
- rightLayout->addWidget(buttonBox);
+ rightLayout = new QVBoxLayout;
+ rightLayout->addStretch();
+ rightLayout->addWidget(buttonBox);
- QHBoxLayout *mainLayout = new QHBoxLayout(parent);
- mainLayout->addLayout(leftLayout);
- mainLayout->addLayout(rightLayout);
+ QHBoxLayout *mainLayout = new QHBoxLayout(parent);
+ mainLayout->addLayout(leftLayout);
+ mainLayout->addLayout(rightLayout);
- setLayout(mainLayout);
+ setLayout(mainLayout);
}
void SelectDialog::init(QList<Club *> &list)
{
- clubList = list;
-
- QListIterator<Club *> i(clubList);
- int index = 0;
+ TRACE;
+ clubList = list;
- while (i.hasNext()) {
- Club *club = i.next();
+ QListIterator<Club *> i(clubList);
+ int index = 0;
+ bool markedFlag = false;
- QList<Course *> courseList = club->getCourseList();
+ while (i.hasNext()) {
+ Club *club = i.next();
- QListIterator<Course *> j(courseList);
- while (j.hasNext()) {
- Course *course = j.next();
+ QList<Course *> courseList = club->getCourseList();
- QListWidgetItem *newItem = new QListWidgetItem;
+ QListIterator<Course *> j(courseList);
+ while (j.hasNext()) {
+ Course *course = j.next();
- QString entry = club->getName() + ", " + course->getName();
+ QListWidgetItem *newItem = new QListWidgetItem;
+
+ QString entry = club->getName() + ", " + course->getName();
- newItem->setText(entry);
- listClub->insertItem(index, newItem);
+ newItem->setText(entry);
+ listWidgetClub->insertItem(index, newItem);
- index++;
+ if (!markedFlag & club->isHomeClub()) {
+ listWidgetClub->setCurrentRow(index);
+ // Mark the 1st course of the home club the selection
+ markedFlag = true;
+ }
+ index++;
+ }
}
- }
}
void SelectDialog::results(QString &club,
QString &course,
QString &date)
{
- QListWidgetItem *current = listClub->currentItem();
+ QListWidgetItem *current = listWidgetClub->currentItem();
- if (current) {
- QString tmp = current->text();
+ if (current) {
+ QString tmp = current->text();
- QStringList stringList = tmp.split(", ");
- club = stringList[0];
- course = stringList[1];
+ QStringList stringList = tmp.split(", ");
+ club = stringList[0];
+ course = stringList[1];
#ifdef Q_WS_MAEMO_5
- QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector();
- QDate d = sel->currentDate();
- // TODO: change to QDate
- date = d.toString(Qt::ISODate);
+ QMaemo5DatePickSelector *sel = (QMaemo5DatePickSelector *)dateButton->pickSelector();
+ QDate d = sel->currentDate();
+ // TODO: change to QDate
+ date = d.toString(Qt::ISODate);
#else
- date = lineEditDate->text();
+ date = lineEditDate->text();
#endif
- }
+ }
}
bool SelectDialog::validate(void)
{
- return true;
+ return true;
}
void SelectDialog::next(void)
{
- if (validate())
- done(1);
- else {
- qDebug() << "SelectDialog: invalid data, cancel or correct";
- }
+ if (validate())
+ done(1);
+ else {
+ qDebug() << "SelectDialog: invalid data, cancel or correct";
+ }
}
void SelectDialog::reject(void)
{
- done(0);
+ done(0);
}
////////////////////////////////////////////////////////////////////////////////
{
TRACE;
resize(800, 400);
+ QFont font;
+ font.setPointSize(fontSize);
+ setFont(font);
QWidget *centralWidget = new QWidget(this);
table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
table->horizontalHeader()->hide();
- table->setStyleSheet(ScoreStyle::style());
+ table->setStyleSheet(defaultStyleSheet);
QStringList headers;
headers << "" << "Par" << "HCP" << "Score" << "" << "Par" << "HCP" << "Score";
// Set default score to par if not set
void ScoreDialog::setDefaultScore(QTableWidget *table)
{
- int row = table->currentRow();
- int col = table->currentColumn();
+ int row = table->currentRow();
+ int col = table->currentColumn();
- if (row == ROW_SCORE)
- row = ROW_PAR;
- else if (row == ROW_SCORE_2)
- row = ROW_PAR_2;
- else {
- qDebug() << "ERROR: unknown row in default score";
- return;
- }
- QTableWidgetItem *par = table->item(row, col);
- QTableWidgetItem *score = table->item(row + 2, col);
-
- if (par && score && score->text() == "") {
- QVariant value(par->text());
- score->setData(Qt::DisplayRole, value);
- }
+ if (row == ROW_SCORE)
+ row = ROW_PAR;
+ else if (row == ROW_SCORE_2)
+ row = ROW_PAR_2;
+ else {
+ qDebug() << "ERROR: unknown row in default score";
+ return;
+ }
+ QTableWidgetItem *par = table->item(row, col);
+ QTableWidgetItem *score = table->item(row + 2, col);
+
+ if (par && score && score->text() == "") {
+ QVariant value(par->text());
+ score->setData(Qt::DisplayRole, value);
+ }
}
void ScoreDialog::up(void)
{
- QTableWidgetItem *item = table->currentItem();
+ QTableWidgetItem *item = table->currentItem();
- if (!item) {
- qWarning() << "ERROR: no current item";
- return;
- }
+ if (!item) {
+ qWarning() << "ERROR: no current item";
+ return;
+ }
- int i = (item->text()).toInt();
- QVariant value(i+1);
- item->setData(Qt::DisplayRole, value);
+ int i = (item->text()).toInt();
+ QVariant value(i+1);
+ item->setData(Qt::DisplayRole, value);
}
void ScoreDialog::down(void)
{
- QTableWidgetItem *item = table->currentItem();
+ QTableWidgetItem *item = table->currentItem();
- if (!item)
- return;
+ if (!item)
+ return;
- int i = (item->text()).toInt();
- QVariant value(i-1);
- item->setData(Qt::DisplayRole, value);
+ int i = (item->text()).toInt();
+ QVariant value(i-1);
+ item->setData(Qt::DisplayRole, value);
}
void ScoreDialog::next(void)
{
- if (table) {
- QTableWidgetItem *item = table->currentItem();
- moveToNextCell(item);
- setDefaultScore(table);
- }
+ if (table) {
+ QTableWidgetItem *item = table->currentItem();
+ moveToNextCell(item);
+ setDefaultScore(table);
+ }
}
void ScoreDialog::moveToNextCell(QTableWidgetItem *item)
{
- if (!item)
- return;
+ if (!item)
+ return;
- QTableWidget *table = item->tableWidget();
+ QTableWidget *table = item->tableWidget();
- if (!table)
- return;
+ if (!table)
+ return;
- int row = table->currentRow();
- int col = table->currentColumn();
+ int row = table->currentRow();
+ int col = table->currentColumn();
- if (col < (COLS-1)) {
- col++;
- }
- else if (col == (COLS-1)) {
- col = 0;
- row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2;
- }
- table->setCurrentCell(row, col);
+ if (col < (COLS-1)) {
+ col++;
+ }
+ else if (col == (COLS-1)) {
+ col = 0;
+ row = (row == ROW_SCORE_2) ? ROW_SCORE : ROW_SCORE_2;
+ }
+ table->setCurrentCell(row, col);
}
void ScoreDialog::results(QVector<QString> &scores)
bool ScoreDialog::validate(void)
{
- for (int i=0; i<9; i++) {
- QTableWidgetItem *frontItem = table->item(ROW_SCORE, i);
- QTableWidgetItem *backItem = table->item(ROW_SCORE_2, i);
+ for (int i=0; i<9; i++) {
+ QTableWidgetItem *frontItem = table->item(ROW_SCORE, i);
+ QTableWidgetItem *backItem = table->item(ROW_SCORE_2, i);
- if (!frontItem || !backItem)
- return false;
+ if (!frontItem || !backItem)
+ return false;
- QString str1 = frontItem->text();
- QString str2 = backItem->text();
+ QString str1 = frontItem->text();
+ QString str2 = backItem->text();
- if (str1.isEmpty() || str2.isEmpty())
- return false;
- }
- return true;
+ if (str1.isEmpty() || str2.isEmpty())
+ return false;
+ }
+ return true;
}
void ScoreDialog::finish(void)
void ScoreDialog::reject(void)
{
- done(0);
+ done(0);
}
void ScoreDialog::showNote(QString msg)
void createLayout(QWidget *parent = 0);
// Widgets
- QListWidget *listClub;
+ QListWidget *listWidgetClub;
#ifdef Q_WS_MAEMO_5
QMaemo5ValueButton *dateButton;
#else
homeClubButton->setPickSelector(listPickSelector2);
homeClubButton->setText(QString::fromUtf8("Home Club"));
+ // Sort Order
+ sortButton = new QMaemo5ValueButton();
+ sortButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+ QMaemo5ListPickSelector * listPickSelector4 = new QMaemo5ListPickSelector;
+ QStringList sortList;
+ sortList << "Date" << "Score";
+ sortModel = new QStandardItemModel(sortList.count(), 0);
+ for (int i = 0; i < sortList.count(); i++) {
+ item = new QStandardItem(QString("%0").arg(sortList.at(i)));
+ item->setTextAlignment(Qt::AlignCenter);
+ sortModel->setItem(i, item);
+ }
+ listPickSelector4->setModel(sortModel);
+ sortButton->setPickSelector(listPickSelector4);
+ sortButton->setText(QString::fromUtf8("Sort Order"));
+
// Use Default Courses
defaultCoursesButton = new QMaemo5ValueButton();
defaultCoursesButton->setValueLayout(QMaemo5ValueButton::ValueBesideText);
leftLayout->addWidget(hcpButton);
leftLayout->addWidget(homeClubButton);
+ leftLayout->addWidget(sortButton);
leftLayout->addWidget(defaultCoursesButton);
#endif
}
QListIterator<Club *> i(clubList);
-
+
while (i.hasNext()) {
Club *club = i.next();
QStandardItem *item = new QStandardItem(QString("%0").arg(club->getName()));
index++;
}
+ if (conf.sortOrder.isValid()) {
+ int index = conf.sortOrder.toString() == "Date" ? 0 : 1;
+ sel = (QMaemo5ListPickSelector *)sortButton->pickSelector();
+ sel->setCurrentIndex(index);
+ }
+
if (conf.defaultCourses.isValid()) {
int index = conf.defaultCourses.toString() == "Yes" ? 0 : 1;
sel = (QMaemo5ListPickSelector *)defaultCoursesButton->pickSelector();
item = homeClubModel->item(sel->currentIndex());
conf.homeClub = item->data(Qt::DisplayRole);
}
+ sel = (QMaemo5ListPickSelector *)sortButton->pickSelector();
+ if (sel->currentIndex() != -1) {
+ item = sortModel->item(sel->currentIndex());
+ conf.sortOrder = item->data(Qt::DisplayRole);
+ }
sel = (QMaemo5ListPickSelector *)defaultCoursesButton->pickSelector();
if (sel->currentIndex() != -1) {
item = defaultCoursesModel->item(sel->currentIndex());
private:
void createLayout(QWidget *parent);
- QStandardItemModel *homeClubModel;
QStandardItemModel *hcpModel;
+ QStandardItemModel *homeClubModel;
+ QStandardItemModel *sortModel;
QStandardItemModel *defaultCoursesModel;
QList<Club *> clubList;
#ifdef Q_WS_MAEMO_5
QMaemo5ValueButton * hcpButton;
QMaemo5ValueButton * homeClubButton;
+ QMaemo5ValueButton * sortButton;
QMaemo5ValueButton * defaultCoursesButton;
#endif
};
*/
#include <QVariant>
+#include <QFont>
+#include "score-common.h"
#include "stat-model.h"
StatModel::StatModel(QList<Club *> &cList, QList<Score *> &sList) : clubList(cList), scoreList(sList)
}
//
+ // FONT
+ //
+ if (role == Qt::FontRole) {
+ QFont font;
+ font.setPointSize(fontSize);
+ return font;
+ }
+ //
// NUMBERS
//
if (role == Qt::DisplayRole) {
{
score = 0;
course = 0;
+ handicap = -1;
}
-void ScoreTableModel::set(Score * s, Course * c)
+void ScoreTableModel::set(Score * s, Course * c, int h)
{
score = s;
course = c;
+ handicap = h;
}
int ScoreTableModel::rowCount(const QModelIndex &) const
QVariant ScoreTableModel::data(const QModelIndex &index, int role) const
{
- if (!index.isValid())
- return QVariant();
+ if (!index.isValid())
+ return QVariant();
- int row = index.row();
- int col = index.column();
+ int row = index.row();
+ int col = index.column();
- //
- // ALIGNMENT
- //
- if (role == Qt::TextAlignmentRole ) {
- return Qt::AlignCenter;
- }
+ //
+ // ALIGNMENT
+ //
+ if (role == Qt::TextAlignmentRole ) {
+ return Qt::AlignCenter;
+ }
- if (index.column() > 10)
- return QVariant();
+ if (index.column() > 10)
+ return QVariant();
- //
- // COLORS
- //
- if (role == Qt::ForegroundRole) {
- // Hole numbers 1-18. All hole nums, in, out and tot cell but not
- // the empty cell.
- if ((row == ROW_HOLE && col != 10) || row == ROW_HOLE_2) {
- QBrush brush(ScoreColor::holeBg());
- return brush;
+ //
+ // COLORS
+ //
+ if (role == Qt::ForegroundRole) {
+ // Hole numbers 1-18. All hole nums, in, out and tot cell but not
+ // the empty cell.
+ if ((row == ROW_HOLE && col != 10) || row == ROW_HOLE_2) {
+ QBrush brush(ScoreColor::holeBg());
+ return brush;
+ }
+ if (score && course && (row == ROW_SCORE || row == ROW_SCORE_2)) {
+ int par;
+ int shots;
+ if (row == ROW_SCORE) {
+ par = course->getPar(col).toInt();
+ shots = score->getScore(col).toInt();
+ }
+ else {
+ par = course->getPar(col + 9).toInt();
+ shots = score->getScore(col + 9).toInt();
+ }
+
+ if (col == (COLS+1) && row == ROW_SCORE_2) {
+ // Total score
+ QBrush brush(ScoreColor::total());
+ return brush;
+ }
+ if (col == COLS) {
+ // In and Out scores
+ QBrush brush(ScoreColor::subTotal());
+ return brush;
+ }
+ if (col < COLS) {
+ if (shots == par) {
+ // Par
+ QBrush brush(ScoreColor::par());
+ return brush;
+ }
+ if (shots == (par-1)) {
+ // Birdie
+ QBrush brush(ScoreColor::birdie());
+ return brush;
+ }
+ if (shots == (par+1)) {
+ // Bogey
+ QBrush brush(ScoreColor::bogey());
+ return brush;
+ }
+ if (shots == (par+2)) {
+ // Double Bogey
+ QBrush brush(ScoreColor::doubleBogey());
+ return brush;
+ }
+ if (shots > (par+2)) {
+ // Very bad
+ QBrush brush(ScoreColor::bad());
+ return brush;
+ }
+ }
+ }
+ return QVariant();
}
- if (score && course && (row == ROW_SCORE || row == ROW_SCORE_2)) {
- int par;
- int shots;
- if (row == ROW_SCORE) {
- par = course->getPar(col).toInt();
- shots = score->getScore(col).toInt();
- }
- else {
- par = course->getPar(col + 9).toInt();
- shots = score->getScore(col + 9).toInt();
- }
-
- if (col == (COLS+1) && row == ROW_SCORE_2) {
- // Total score
- QBrush brush(ScoreColor::total());
- return brush;
- }
- if (col == COLS) {
- // In and Out scores
- QBrush brush(ScoreColor::subTotal());
- return brush;
- }
- if (col < COLS) {
- if (shots == par) {
- // Par
- QBrush brush(ScoreColor::par());
- return brush;
- }
- if (shots == (par-1)) {
- // Birdie
- QBrush brush(ScoreColor::birdie());
- return brush;
- }
- if (shots == (par+1)) {
- // Bogey
- QBrush brush(ScoreColor::bogey());
- return brush;
- }
- if (shots == (par+2)) {
- // Double Bogey
- QBrush brush(ScoreColor::doubleBogey());
- return brush;
- }
- if (shots > (par+2)) {
- // Very bad
- QBrush brush(ScoreColor::bad());
- return brush;
- }
- }
+ //
+ // FONT
+ //
+ if (role == Qt::FontRole) {
+ QFont font;
+ if (col == (COLS+1) && row == ROW_SCORE_2) {
+ font.setBold(true);
+ font.setPointSize(fontSize+4);
+ }
+ else
+ font.setPointSize(fontSize);
+ if (row == ROW_HOLE || row == ROW_HOLE_2) {
+ font.setBold(true);
+ }
+ return font;
}
- return QVariant();
- }
- //
- // FONT
- //
- if (role == Qt::FontRole) {
- if (row == ROW_HOLE || row == ROW_HOLE_2) {
- QFont font;
- font.setBold(true);
- return font;
- }
- if (row == ROW_SCORE || row == ROW_SCORE_2) {
- QFont font;
- font.setBold(true);
- return font;
- }
- }
- //
- // NUMBERS
- //
- if (role == Qt::DisplayRole) {
-
- if (col == COLS) {
- // In/out label
- if (row == ROW_HOLE)
- return QString("Out");
- if (row == ROW_HOLE_2)
- return QString("In");
-
- // In/Out for par
- if (score && course && row == ROW_PAR)
- return course->getTotal(TotalOut);
- if (score && course && row == ROW_PAR_2)
- return course->getTotal(TotalIn);
-
- // In/Out for score
- if (score && row == ROW_SCORE)
- return score->getTotal(TotalOut);
- if (score && row == ROW_SCORE_2)
- return score->getTotal(TotalIn);
+
+ //
+ // NUMBERS
+ //
+ if (role == Qt::DisplayRole) {
+
+ if (col == COLS) {
+ // In/out label
+ if (row == ROW_HOLE)
+ return QString("Out");
+ if (row == ROW_HOLE_2)
+ return QString("In");
+
+ // In/Out for par
+ if (score && course && row == ROW_PAR)
+ return course->getTotal(TotalOut);
+ if (score && course && row == ROW_PAR_2)
+ return course->getTotal(TotalIn);
+
+ // In/Out for score
+ if (score && row == ROW_SCORE)
+ return score->getTotal(TotalOut);
+ if (score && row == ROW_SCORE_2)
+ return score->getTotal(TotalIn);
+ }
+ else if (col == (COLS+1)) {
+ // Total label
+ if (row == ROW_HOLE_2)
+ return QString("Tot");
+ // Total score
+ if (score && course && row == ROW_PAR_2)
+ return course->getTotal(Total);
+ if (score && row == ROW_SCORE_2)
+ return score->getTotal(Total);
+ // calculate net score
+ if (score && course && row == ROW_HCP_2) {
+ int scoreTotal = score->getTotal(Total).toInt();
+ int courseTotal = course->getTotal(Total).toInt();
+ int n = scoreTotal - courseTotal;
+ return QString("+%1").arg(n);
+ }
+ }
+ else {
+ // data cells
+ switch(row) {
+ case ROW_HOLE:
+ return col + 1;
+
+ case ROW_HOLE_2:
+ return col + 10;
+
+ case ROW_PAR:
+ if (course)
+ return course->getPar(col);
+ else
+ return QString("");
+
+ case ROW_PAR_2:
+ if (course)
+ return course->getPar(col + 9);
+ else
+ return QString("");
+
+ case ROW_HCP:
+ if (course)
+ return course->getHcp(col);
+ else
+ return QString("");
+
+ case ROW_HCP_2:
+ if (course)
+ return course->getHcp(col + 9);
+ else
+ return QString("");
+
+ case ROW_SCORE:
+ if (score)
+ return score->getScore(col);
+ else
+ return QString("");
+
+ case ROW_SCORE_2:
+ if (score)
+ return score->getScore(col + 9);
+ else
+ return QString("");
+ }
+ }
}
- else if (col == (COLS+1)) {
- // Total label
- if (row == ROW_HOLE_2)
- return QString("Tot");
- // Total score
- if (score && course && row == ROW_PAR_2)
- return course->getTotal(Total);
- if (score && row == ROW_SCORE_2)
- return score->getTotal(Total);
- }
- else {
- // data cells
- switch(row) {
- case ROW_HOLE:
- return col + 1;
- case ROW_HOLE_2:
- return col + 10;
- case ROW_PAR:
- if (score && course)
- return course->getPar(col);
- case ROW_PAR_2:
- if (score && course)
- return course->getPar(col + 9);
- case ROW_HCP:
- if (score && course)
- return course->getHcp(col);
- case ROW_HCP_2:
- if (score && course)
- return course->getHcp(col + 9);
- case ROW_SCORE:
- if (score)
- return score->getScore(col);
- case ROW_SCORE_2:
- if (score)
- return score->getScore(col + 9);
- }
- }
- }
- return QVariant();
+ return QVariant();
}
QVariant ScoreTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
- // Only vertical header -- horizontal is hidden
- if (orientation == Qt::Horizontal)
- return QVariant();
+ // Only vertical header -- horizontal is hidden
+ if (orientation == Qt::Horizontal)
+ return QVariant();
- if (role == Qt::DisplayRole) {
- switch(section) {
- case ROW_HOLE:
- case ROW_HOLE_2:
- return QString("Hole");
- case ROW_PAR:
- case ROW_PAR_2:
- return QString("Par");
- case ROW_HCP:
- case ROW_HCP_2:
- return QString("HCP");
- case ROW_SCORE:
- case ROW_SCORE_2:
- return QString("Score");
+ if (role == Qt::FontRole) {
+ QFont font;
+ font.setPointSize(fontSize);
+ return font;
+ }
+ if (role == Qt::DisplayRole) {
+ switch(section) {
+ case ROW_HOLE:
+ case ROW_HOLE_2:
+ return QString("Hole");
+ case ROW_PAR:
+ case ROW_PAR_2:
+ return QString("Par");
+ case ROW_HCP:
+ case ROW_HCP_2:
+ return QString("HCP");
+ case ROW_SCORE:
+ case ROW_SCORE_2:
+ return QString("Score");
+ }
+ return QVariant();
}
- return QVariant();
- }
- return QVariant();
+ return QVariant();
}
//
// FONT
//
if (role == Qt::FontRole) {
+ QFont font;
+ font.setPointSize(fontSize);
if (row == ROW_HOLE || row == ROW_HOLE_2) {
- QFont font;
font.setBold(true);
- return font;
}
+ return font;
+ }
+ //
+ // COLORS
+ //
+ if (role == Qt::ForegroundRole) {
+ // Hole numbers 1-18. All hole nums, in, out and tot cell but not
+ // the empty cell.
+ if ((row == ROW_HOLE && col != 10) || row == ROW_HOLE_2) {
+ QBrush brush(ScoreColor::holeBg());
+ return brush;
+ }
+ return QVariant();
}
- //
- // COLORS
- //
- if (role == Qt::ForegroundRole) {
- // Hole numbers 1-18. All hole nums, in, out and tot cell but not
- // the empty cell.
- if ((row == ROW_HOLE && col != 10) || row == ROW_HOLE_2) {
- QBrush brush(ScoreColor::holeBg());
- return brush;
- }
- return QVariant();
- }
//
// NUMBERS
//
case ROW_HCP_2:
if (course)
return course->getHcp(col + 9);
- }
+ }
+ }
}
- }
- return QVariant();
+ return QVariant();
}
QVariant CourseTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
- // Only vertical header -- horizontal is hidden
- if (orientation == Qt::Horizontal)
- return QVariant();
+ // Only vertical header -- horizontal is hidden
+ if (orientation == Qt::Horizontal)
+ return QVariant();
- if (role == Qt::DisplayRole) {
- switch(section) {
- case ROW_HOLE:
- case ROW_HOLE_2:
- return QString("Hole");
- case ROW_PAR:
- case ROW_PAR_2:
- return QString("Par");
- case ROW_HCP:
- case ROW_HCP_2:
- return QString("HCP");
- case ROW_LEN:
- case ROW_LEN_2:
- return QString("Len");
+ if (role == Qt::FontRole) {
+ QFont font;
+ font.setPointSize(fontSize);
+ return font;
+ }
+ if (role == Qt::DisplayRole) {
+ switch(section) {
+ case ROW_HOLE:
+ case ROW_HOLE_2:
+ return QString("Hole");
+ case ROW_PAR:
+ case ROW_PAR_2:
+ return QString("Par");
+ case ROW_HCP:
+ case ROW_HCP_2:
+ return QString("HCP");
+ case ROW_LEN:
+ case ROW_LEN_2:
+ return QString("Len");
+ }
+ return QVariant();
}
- return QVariant();
- }
- return QVariant();
+ return QVariant();
}
public:
ScoreTableModel(QObject *parent = 0);
- void set(Score *, Course *);
+ void set(Score *, Course *, int handicap = -1);
int rowCount(const QModelIndex & parent) const;
int columnCount(const QModelIndex & parent) const;
QVariant data(const QModelIndex & index, int role) const;
Score *score;
Club *club;
Course *course;
+
+ // Current handicap
+ int handicap;
};
class CourseTableModel : public QAbstractTableModel