/*********
*
* This file is part of BibleTime's source code, http://www.bibletime.info/.
*
* Copyright 1999-2006 by the BibleTime developers.
* The BibleTime source code is licensed under the GNU General Public License version 2.0.
*
**********/



#include "csortlistviewitem.h"

//#include <versekey.h>

namespace util {

CSortListViewItem::CSortListViewItem(TQListViewItem* parent) : TDEListViewItem(parent)
{
}

CSortListViewItem::CSortListViewItem( TQListView * parent, TQListViewItem * after )
	: TDEListViewItem ( parent, after )
{
}

CSortListViewItem::CSortListViewItem( TQListViewItem * parent, TQListViewItem * after )
	: TDEListViewItem ( parent, after )
{
}
	
CSortListViewItem::CSortListViewItem( TQListView * parent, TQString label1, TQString label2, TQString label3, TQString label4, TQString label5, TQString label6, TQString label7, TQString label8 )
	: TDEListViewItem( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
{
}

CSortListViewItem::CSortListViewItem( TQListViewItem * parent, TQString label1, TQString label2, TQString label3, TQString label4, TQString label5, TQString label6, TQString label7, TQString label8 )
	: TDEListViewItem ( parent, label1, label2, label3, label4, label5, label6, label7, label8 )
{
}

CSortListViewItem::CSortListViewItem( TQListView * parent, TQListViewItem * after, TQString label1, TQString label2, TQString label3, TQString label4, TQString label5, TQString label6, TQString label7, TQString label8 )
	: TDEListViewItem ( parent, after, label1, label2, label3, label4, label5, label6, label7, label8 )
{
}

CSortListViewItem::CSortListViewItem( TQListViewItem * parent, TQListViewItem * after, TQString label1, TQString label2, TQString label3, TQString label4, TQString label5, TQString label6, TQString label7, TQString label8 )
	: TDEListViewItem ( parent, after, label1, label2, label3, label4, label5, label6, label7, label8 )
{

}


CSortListViewItem::~CSortListViewItem() {
}

int CSortListViewItem::compare( TQListViewItem* i, int col, bool ascending ) const {
	int ret = 0;

	if ( !columnSorting.contains(col) ) {
		return TDEListViewItem::compare(i, col, ascending);
	}
	
	Type t = columnSorting[col];
	if (t == String) {
		ret = TDEListViewItem::compare(i, col, ascending);
	}
	else if (t == Number) {
		ret = (int) (text(col).toLong() - (i->text(col).toLong()));
	}
// 	else if (t == BibleKey) {
// 		//ret = (int) (text(col).toLong() - (i->text(col).toLong()));
// 		ret = sword::VerseKey(  (const char*) text(col).utf8() )._compare( sword::VerseKey( (const char*) i->text(col).utf8()) );
// 	}

	return ret;
}

void CSortListViewItem::setColumnSorting(int column, CSortListViewItem::Type type) {
	columnSorting[ column ] = type;
}

}

