
//  Copyright (C) 2009 by Arnaud Dupuis
//  a.dupuis@infinityperl.org
//  http://www.infinityperl.org
// 
//  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 3 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.,
//  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA

#ifndef ASSUMA_TREEWIDGET_ITEMEDITORDELEGATE
#define ASSUMA_TREEWIDGET_ITEMEDITORDELEGATE

#include <QItemDelegate>
#include <QMap>
/*! \class AssumaTreeWidgetItemEditorDelegate
* \brief The AssumaTreeWidgetItemEditorDelegate class provides display and editing facilities for items from Assuma* QTreeWidgets.
*
* The AssumaTreeWidgetItemEditorDelegate class provides display and editing facilities for items from Assuma* QTreeWidgets.
* It provides specific accessors and editors for in-place edition operations in Assuma* QTreeWidgets.
*/
class AssumaTreeWidgetItemEditorDelegate : public QItemDelegate {
	Q_OBJECT
	public slots:
		/*!
		Set the list of courses for in-place edition.
		*/
		void setCoursesList( const QStringList );
		/*!
		Set a list of licenses label for in-place edition.
		*/
		void setLicenseLabelsList( const QStringList );
		/*!
		Set the list of lessons number data. The QMap must have a course name as key and a list of course's number as value.
		*/
		void setCoursesLessonsNumberData( const QMap<QString, QStringList> );
		/*!
		Set the current activity, i.e the activity of the subscribers. It is used by AssumaMainWindow when the user is in-place editing a subscriber.
		*/
		void setCurrentActivity(const QString & );
		/*!
		Set a QMap of postal codes (to fill the list of postal codes and cities in the editors).
		The map must have cities' name as keys and postal codes as values.
		*/
		void setPostCodesMap( const QMap<QString,QString> & );
	public:
		/*!
		Constructs a new delegate.
		*/
		AssumaTreeWidgetItemEditorDelegate(QWidget * parent = 0);
		/*!
		Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.
		*/
		QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
		/*!
		Sets the data to be displayed and edited by the editor from the data model item specified by the model index.
		*/
		void setEditorData(QWidget *editor, const QModelIndex &index) const;
		/*!
		Returns the size needed by the delegate to display the item specified by index, taking into account the style information provided by option.
		*/
		QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const;
		/*!
		Gets data drom the editor widget and stores it in the specified model at the item index.
		*/
		void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
	private:
		QWidget * _parent;
		QString _dateDisplayFormat;
		QStringList _coursesList;
		QStringList _licenseLabels;
		QMap<QString, QStringList> _coursesLessonsNumber;
		QString _currentActivity;
		QMap<QString,QString> _pcMap;

};

#endif
