mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Added Season support via xml file.
Using seasons.xml, support now for a season name, start date and end date. Fixed some memory leaks.
This commit is contained in:
committed by
Sean Rhea
parent
5acf35d542
commit
c630d281d3
@@ -88,21 +88,6 @@ bool DBAccess::createMetricsTable()
|
||||
|
||||
}
|
||||
|
||||
bool DBAccess::createSeasonsTable()
|
||||
{
|
||||
QSqlQuery query;
|
||||
bool rc = query.exec("CREATE TABLE seasons(id integer primary key autoincrement,"
|
||||
"start_date date,"
|
||||
"end_date date,"
|
||||
"name varchar)");
|
||||
|
||||
if(!rc)
|
||||
qDebug() << query.lastError();
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
bool DBAccess::createDatabase()
|
||||
{
|
||||
|
||||
@@ -116,12 +101,7 @@ bool DBAccess::createDatabase()
|
||||
rc = createIndex();
|
||||
if(!rc)
|
||||
return rc;
|
||||
|
||||
//Check to see if the table already exists..
|
||||
QStringList tableList = db.tables(QSql::Tables);
|
||||
if(!tableList.contains("seasons"))
|
||||
return createSeasonsTable();
|
||||
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
@@ -232,44 +212,6 @@ QList<SummaryMetrics> DBAccess::getAllMetricsFor(QDateTime start, QDateTime end)
|
||||
return metrics;
|
||||
}
|
||||
|
||||
bool DBAccess::createSeason(Season season)
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("INSERT INTO season (start_date, end_date, name) values (?,?,?)");
|
||||
|
||||
|
||||
query.addBindValue(season.getStart());
|
||||
query.addBindValue(season.getEnd());
|
||||
query.addBindValue(season.getName());
|
||||
|
||||
bool rc = query.exec();
|
||||
|
||||
if(!rc)
|
||||
qDebug() << query.lastError();
|
||||
|
||||
return rc;
|
||||
|
||||
}
|
||||
|
||||
QList<Season> DBAccess::getAllSeasons()
|
||||
{
|
||||
QSqlQuery query("SELECT start_date, end_date, name from season");
|
||||
QList<Season> seasons;
|
||||
|
||||
while(query.next())
|
||||
{
|
||||
Season season;
|
||||
season.setStart(query.value(0).toDateTime());
|
||||
season.setEnd(query.value(1).toDateTime());
|
||||
season.setName(query.value(2).toString());
|
||||
seasons << season;
|
||||
|
||||
}
|
||||
return seasons;
|
||||
|
||||
}
|
||||
|
||||
bool DBAccess::dropMetricTable()
|
||||
{
|
||||
|
||||
|
||||
@@ -43,15 +43,10 @@ class DBAccess
|
||||
void closeConnection();
|
||||
QList<QDateTime> getAllDates();
|
||||
QList<SummaryMetrics> getAllMetricsFor(QDateTime start, QDateTime end);
|
||||
bool createSeasonsTable();
|
||||
bool createMetricsTable();
|
||||
bool createSeason(Season season);
|
||||
QList<Season> getAllSeasons();
|
||||
bool dropMetricTable();
|
||||
//bool deleteSeason(Season season);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
QSqlDatabase db;
|
||||
bool createIndex();
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
|
||||
#include "Season.h"
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
#include <QXmlInputSource>
|
||||
#include "SeasonParser.h"
|
||||
#include <QXmlSimpleReader>
|
||||
|
||||
Season::Season()
|
||||
{
|
||||
@@ -29,22 +33,22 @@ QString Season::getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
QDateTime Season::getStart()
|
||||
QDate Season::getStart()
|
||||
{
|
||||
return start;
|
||||
}
|
||||
|
||||
QDateTime Season::getEnd()
|
||||
QDate Season::getEnd()
|
||||
{
|
||||
return end;
|
||||
}
|
||||
|
||||
void Season::setEnd(QDateTime _end)
|
||||
void Season::setEnd(QDate _end)
|
||||
{
|
||||
end = _end;
|
||||
}
|
||||
|
||||
void Season::setStart(QDateTime _start)
|
||||
void Season::setStart(QDate _start)
|
||||
{
|
||||
start = _start;
|
||||
}
|
||||
@@ -52,4 +56,4 @@ void Season::setStart(QDateTime _start)
|
||||
void Season::setName(QString _name)
|
||||
{
|
||||
name = _name;
|
||||
}
|
||||
}
|
||||
|
||||
22
src/Season.h
22
src/Season.h
@@ -20,26 +20,24 @@
|
||||
#define SEASON_H_
|
||||
|
||||
#include <QString>
|
||||
#include <QDateTime>
|
||||
#include <QDate>
|
||||
#include <QFile>
|
||||
|
||||
class Season
|
||||
{
|
||||
{
|
||||
public:
|
||||
Season();
|
||||
QDateTime getStart();
|
||||
QDateTime getEnd();
|
||||
QDate getStart();
|
||||
QDate getEnd();
|
||||
QString getName();
|
||||
|
||||
void setStart(QDateTime _start);
|
||||
void setEnd(QDateTime _end);
|
||||
void setStart(QDate _start);
|
||||
void setEnd(QDate _end);
|
||||
void setName(QString _name);
|
||||
|
||||
private:
|
||||
QDateTime start;
|
||||
QDateTime end;
|
||||
QDate start;
|
||||
QDate end;
|
||||
QString name;
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
#endif /* SEASON_H_ */
|
||||
|
||||
87
src/SeasonParser.cpp
Normal file
87
src/SeasonParser.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Justin F. Knotzke (jknotzke@shampoo.ca)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <SeasonParser.h>
|
||||
#include <QDate>
|
||||
#include <QDebug>
|
||||
|
||||
bool SeasonParser::startDocument()
|
||||
{
|
||||
buffer.clear();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool SeasonParser::endElement( const QString&, const QString&, const QString &qName )
|
||||
{
|
||||
if(qName == "name")
|
||||
season.setName(buffer.trimmed());
|
||||
else if(qName == "startdate")
|
||||
season.setStart(seasonDateToDate(buffer.trimmed()));
|
||||
else if(qName == "season")
|
||||
{
|
||||
if(seasons.size() >= 1)
|
||||
seasons[seasons.size()-1].setEnd(season.getStart());
|
||||
seasons.append(season);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool SeasonParser::startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs )
|
||||
{
|
||||
buffer.clear();
|
||||
if(name == "season")
|
||||
season = Season();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool SeasonParser::characters( const QString& str )
|
||||
{
|
||||
buffer += str;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
QList<Season> SeasonParser::getSeasons()
|
||||
{
|
||||
return seasons;
|
||||
}
|
||||
|
||||
QDate SeasonParser::seasonDateToDate(QString seasonDate)
|
||||
{
|
||||
QRegExp rx(".*([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9]$)");
|
||||
if (rx.exactMatch(seasonDate)) {
|
||||
assert(rx.numCaptures() == 3);
|
||||
QDate date = QDate(
|
||||
rx.cap(1).toInt(),
|
||||
rx.cap(2).toInt(),
|
||||
rx.cap(3).toInt()
|
||||
);
|
||||
|
||||
if (! date.isValid()) {
|
||||
return QDate();
|
||||
}
|
||||
else
|
||||
return date;
|
||||
}
|
||||
else
|
||||
return QDate(); // return value was 1 Jan: changed to null
|
||||
}
|
||||
bool SeasonParser::endDocument()
|
||||
{
|
||||
seasons[seasons.size()-1].setEnd(QDate::currentDate().addYears(10)); //Go 10 years into the future (GC's version of infinity).
|
||||
}
|
||||
43
src/SeasonParser.h
Normal file
43
src/SeasonParser.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2009 Justin F. Knotzke (jknotzke@shampoo.ca)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., 51
|
||||
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef _seasonparser_h
|
||||
#define _seasonparser_h
|
||||
|
||||
#include <QXmlDefaultHandler>
|
||||
#include "Season.h"
|
||||
|
||||
class SeasonParser : public QXmlDefaultHandler
|
||||
{
|
||||
|
||||
public:
|
||||
bool startDocument();
|
||||
bool endDocument();
|
||||
bool endElement( const QString&, const QString&, const QString &qName );
|
||||
bool startElement( const QString&, const QString&, const QString &name, const QXmlAttributes &attrs );
|
||||
bool characters( const QString& str );
|
||||
QList<Season> getSeasons();
|
||||
|
||||
protected:
|
||||
QString buffer;
|
||||
QDate seasonDateToDate(QString);
|
||||
Season season;
|
||||
QList<Season> seasons;
|
||||
|
||||
};
|
||||
#endif //SeasonParser
|
||||
@@ -82,6 +82,7 @@ HEADERS += \
|
||||
RideItem.h \
|
||||
RideMetric.h \
|
||||
Season.h \
|
||||
SeasonParser.h \
|
||||
Settings.h \
|
||||
SplitRideDialog.h \
|
||||
SrmRideFile.h \
|
||||
@@ -139,6 +140,7 @@ SOURCES += \
|
||||
RideItem.cpp \
|
||||
RideMetric.cpp \
|
||||
Season.cpp \
|
||||
SeasonParser.cpp \
|
||||
SplitRideDialog.cpp \
|
||||
SrmRideFile.cpp \
|
||||
StressCalculator.cpp \
|
||||
|
||||
Reference in New Issue
Block a user