//-----------------------------------------------------------------------------
// File: localheadersavemodel.h
//-----------------------------------------------------------------------------
// Project: Kactus 2
// Author: Antti Kamppi
// Date: 20.02.2013
//
// Description:
// The model class to display the header files to be created from component's local memory maps.
//-----------------------------------------------------------------------------

#ifndef LOCALHEADERSAVEMODEL_H
#define LOCALHEADERSAVEMODEL_H

#include <IPXACTmodels/Component/Component.h>

#include <QSharedPointer>
#include <QAbstractTableModel>
#include <QFileInfo>
#include <QList>

class LibraryInterface;
class MemoryMapBase;

//-----------------------------------------------------------------------------
//! The model class to display the header files to be created from component's local memory maps.
//-----------------------------------------------------------------------------
class LocalHeaderSaveModel : public QAbstractTableModel
{
    Q_OBJECT

public:

	//! Contains the options to identify the local memory map and its save file path.
	struct SaveFileOptions
    {
		//! Pointer to the local memory map.
        QSharedPointer<MemoryMapBase> localMemMap_;

		//! Contains the path for the header file to be saved.
		QFileInfo fileInfo_;

		//! The name of the sw view to create the header for.
		QString swView_;
	};

	//! The column numbers for the table.
	enum Columns
    {
		SW_VIEW_NAME = 0,
		MEM_MAP_NAME,
		FILE_NAME,
		FILE_PATH,
		COLUMN_COUNT
	};

	/*!
     *  The constructor.
	 *
	 *      @param [in] handler     Pointer to the instance that manages the library.
	 *      @param [in] parent      Pointer to the owner of the model.
	 */
	LocalHeaderSaveModel(LibraryInterface* handler, QObject *parent);
	
	//! The destructor.
	virtual ~LocalHeaderSaveModel();

	/*!
     *  Set the component in which the local memory maps are displayed.
	 *
	 *      @param [in] component   The pointer to the component to create the local memory maps for.
	 */
	void setComponent(QSharedPointer<Component> component);

	/*!
     *  Get the number of rows an item contains.
	 *
	 *      @param [in] parent  Identifies the parent that's row count is requested.
	 *
	 *      @return Number of rows the item has.
	 */
	virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;

	/*!
     *  Get the number of columns the item has to be displayed.
	 *
	 *      @param [in] parent  Identifies the parent that's column count is requested.
	 *
	 *      @return The number of columns to be displayed.
	 */
	virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;

	/*!
     *  Get the item flags that defines the possible operations for the item.
	 *
	 *      @param [in] index   Model index that identifies the item.
	 *
	 *      @return Qt::ItemFlags specify the possible operations for the item.
	 */
	Qt::ItemFlags flags(const QModelIndex& index) const;

	/*!
     *  Get the header data for specified header.
	 *
	 *      @param [in] section         The section specifies the row/column number for the header.
	 *      @param [in] orientation     Specified if horizontal or vertical header is wanted.
	 *      @param [in] role            Specifies the type of the requested data.
	 *
	 *      @return QVariant Contains the requested data.
	 */
	virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;

	/*!
     *  Get the data for specified item.
	 *
	 *      @param [in] index   Specifies the item that's data is requested.
	 *      @param [in] role    The role that defines what kind of data is requested.
	 *
	 *      @return QVariant Contains the data for the item.
	 */
	virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;

	/*!
     *  Save the data to the model for specified item
	 *
	 *      @param [in] index   The model index of the item that's data is to be saved.
	 *      @param [in] value   The data that is to be saved.
	 *      @param [in] role    The role specifies what kind of data should be saved.
	 *
	 *      @return True if saving happened successfully.
	 */
	bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);

	/*!
     *  Get the options defining locations for headers to generate.
	 *
	 *      @return QList containing the save options.
	 */
	const QList<SaveFileOptions*>& getHeaderOptions() const;

private:
	
	//! No copying.
	LocalHeaderSaveModel(const LocalHeaderSaveModel& other);

	//! No assignment.
	LocalHeaderSaveModel& operator=(const LocalHeaderSaveModel& other);

    //-----------------------------------------------------------------------------
    // Data.
    //-----------------------------------------------------------------------------

	//! Pointer to the component which contains the local memory maps.
	QSharedPointer<Component> component_;

	//! Pointer to the instance that manages the library.
	LibraryInterface* handler_;

	//! Contains the local memory maps and paths to save the headers.
	QList<SaveFileOptions*> table_;
};

#endif // LOCALHEADERSAVEMODEL_H
