#include "SummaryWidget.h"


const int SummaryTable::PROPERTY_COLUMN=0;	//column 0 represents property
const int SummaryTable::VALUE_COLUMN=1;		//column 1 represents property value
const int SummaryTable::COLUMN_0_WIDTH = 200;
const char SummaryTable::PROPERTY_STR[] = "Atribut";
const char SummaryTable::VALUE_STR[] = "Hodnota";

Record::Record( string propertyName, string propertyValue )
{
	this->propertyName = propertyName;
	this->propertyValue = propertyValue;
}

SummaryTable::SummaryTable( QWidget *parent): QTableView( parent )
{
	this->rowCount = 0;

	this->model.insertColumn( PROPERTY_COLUMN );
	this->setColumnWidth(0, COLUMN_0_WIDTH );
	
	this->model.insertColumn( VALUE_COLUMN );
	this->setColumnWidth(1, this->width() - COLUMN_0_WIDTH );
}
void SummaryTable::pushHeader(void)
{
	Record header( PROPERTY_STR, VALUE_STR);
	this->pushRecord( header );
}
void SummaryTable::pushRecord( const Record& record )
{
	this->itemPtrContainer.push_back( new QStandardItem(  record.propertyName.c_str() ) );
	this->model.setItem( this->rowCount , PROPERTY_COLUMN, this->itemPtrContainer.back() );

	this->itemPtrContainer.push_back( new QStandardItem(  record.propertyValue.c_str() ) );
	this->model.setItem( this->rowCount , VALUE_COLUMN, this->itemPtrContainer.back() );

	this->setModel (&this->model );

	++this->rowCount;
}
void SummaryTable::pushRecords( const vector<Record>& records )
{
	for ( int i=0; i< records.size(); ++i)
	{
		this->pushRecord( records[i] );
	}
}
void SummaryTable::clearRecords( void )
{
	for ( int i=0; i< this->itemPtrContainer.size(); ++i)
	{
		delete this->itemPtrContainer[i];
	}
	
	this->rowCount=0;
	this->pushHeader();
}

void SummaryTable::paintEvent(QPaintEvent * QtEvent)
{
	QTableView::paintEvent( QtEvent );	

	//FIXME: it is not working!!!
	/*
	QLineF line( 0, 0, 100, 100 );
	QColor hourColor(127, 0, 127);
	QPainter painter( this );
	painter.setPen(Qt::SolidLine);
	painter.setBrush( hourColor );
	painter.drawLine(line);
	*/
}