/***************************************************************************
 *   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(ATHLETELOGTREE__H)

#define ATHLETELOGTREE__H

#include "core/athletelog.h"

#include <QTreeView>

#include <qglobal.h>

class AthleteLogModel;
class Profile;

class AthleteLogTree : public QTreeView
{
	Q_OBJECT

	public:
		enum AthleteLogCols
		{
			dateCol = 0,
			weightCol = 1,
			bodyFatPercentCol = 2,
			bmiCol = 3,
			restingHRCol = 4,
			maxHRCol = 5,
			bloodPressureCol = 6,
			energyConsCol = 7,
			sleepDurationCol = 8,

			lastAthleteLogCol
		};

	public:
		AthleteLogTree(QWidget* parent = NULL);

	signals:
		void selectedAthleteLogChanged();
		void athleteLogChanged(AthleteLog*, int);

	public:
		void setProfile(const Profile* profile);

		AthleteLogs selectedAthleteLogs();

		void clear();

		void add(AthleteLog* a);
		void remove(AthleteLog* a);

		void setCurrentAthleteLog(AthleteLog* athleteLog);
		void selectFirstAthleteLog();

		bool isEditing(const QModelIndex& index) const;

	public slots:
		void onSelectionChanged(const QItemSelection&, const QItemSelection&);
		void updateEntry(AthleteLog* a);
		void onDataChanged(const QModelIndex& from, const QModelIndex&);

	protected:
		AthleteLogModel* sourceModel();
		const AthleteLogModel* sourceModel() const;
};

#endif
