/***************************************************************************
 *   Copyright (C) 2010 by Volker Lanz <vl@fidra.de>                       *
 *                                                                         *
 *   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            *
 ***************************************************************************/

#if !defined(TRACKPOINT__H)

#define TRACKPOINT__H

#include "core/types.h"
#include "core/dbitem.h"
#include "core/position.h"

#include <qglobal.h>
#include <QDateTime>
#include <QList>

class QSqlQuery;

class Track;

class TrackPoint : public DbItem
{
	Q_DISABLE_COPY(TrackPoint);

	friend class Track;

	public:
		TrackPoint(Track* track, const QSqlQuery& query);
		TrackPoint();

	public:
		bool serialize();
		static bool list(Track* track, TrackPoints& result);

		const QDateTime& timeStamp() const { return m_TimeStamp; }
		const Position& position() const { return m_Position; }
		quint32 speed() const { return m_Speed; }
		qint32 altitude() const { return m_Altitude; }
		quint32 heartRate() const { return m_HeartRate; }
		quint32 cadence() const { return m_Cadence; }

		void setTimeStamp(const QDateTime& ts)  { m_TimeStamp = ts; setDirty(true); }
		void setPosition(const Position& pos) { m_Position = pos; setDirty(true); }
		void setSpeed(quint32 s) { m_Speed = s; }
		void setAltitude(qint32 alt) { m_Altitude = alt; setDirty(true); }
		void setHeartRate(quint32 hr) { m_HeartRate = hr; setDirty(true); }
		void setCadence(quint32 c) { m_Cadence = c; setDirty(true); }

	protected:
		const Track* track() const { return m_Track; }
		void setTrack(Track* t) { m_Track = t; setDirty(true); }

	private:
		Track* m_Track;
		QDateTime m_TimeStamp;
		Position m_Position;
		quint32 m_Speed; ///< in km/h * 1000
		qint32 m_Altitude; ///< in milli-meters
		quint32 m_HeartRate;
		quint32 m_Cadence;
};

#endif
