/***************************************************************************
                            QDataTable.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QDataTable.h>
#include <qtobjc/QDataTable.h>
#include <qtobjc/QColorGroup.h>
#include <qtobjc/QIconSet.h>
#include <qtobjc/QPainter.h>
#include <qtobjc/QPixmap.h>
#include <qtobjc/QRect.h>
#include <qtobjc/QSqlCursor.h>
#include <qtobjc/QSqlEditorFactory.h>
#include <qtobjc/QSqlError.h>
#include <qtobjc/QSqlField.h>
#include <qtobjc/QSqlIndex.h>
#include <qtobjc/QSqlPropertyMap.h>
#include <qtobjc/QTableItem.h>


@implementation  QDataTable


- initWithWidget: (QWidget *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataTable((qt_QWidget *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataTable(0, 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithSqlCursor: (QSqlCursor*)cursor autoPopulate: (BOOL)autoPopulate parent: (QWidget *)parent name: (NSString *)name
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataTable1((qt_QSqlCursor*) [cursor qt], (int)autoPopulate, (qt_QWidget *) [parent qt], (char*) [name cString])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithSqlCursor: (QSqlCursor*)cursor 
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataTable1((qt_QSqlCursor*) [cursor qt], 0, 0, 0)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- (void) dealloc
{
	if ([self qt] != 0L) {
		if ([self allocatedInObjcWorld] && [self parentWidget: YES] == nil) {
			qt_del_QDataTable((qt_QDataTable *)[self qt]);
		}
		[QtSupport removeQtKey: [self qt]];
		[self setQt: 0L];
	}
	[super dealloc];
}

- addColumn: (NSString *)fieldName label: (NSString *)label width: (int)width iconset: (QIconSet*)iconset
{
static qt_QString * _qstring_label = 0L;
static qt_QString * _qstring_fieldName = 0L;
	qt_QDataTable_addColumn((qt_QDataTable *)[self qt], (qt_QString *) [fieldName toQString: &_qstring_fieldName], (qt_QString *) [label toQString: &_qstring_label], (int)width, (qt_QIconSet*) [iconset qt]);
	return self;
}

- addColumn: (NSString *)fieldName 
{
static qt_QString * _qstring_fieldName = 0L;
	qt_QDataTable_addColumn((qt_QDataTable *)[self qt], (qt_QString *) [fieldName toQString: &_qstring_fieldName], qt_QString_null(), -1, 0);
	return self;
}

- removeColumn: (unsigned int)col
{
	qt_QDataTable_removeColumn((qt_QDataTable *)[self qt], (unsigned int)col);
	return self;
}

- setColumn: (unsigned int)col fieldName: (NSString *)fieldName label: (NSString *)label width: (int)width iconset: (QIconSet*)iconset
{
static qt_QString * _qstring_label = 0L;
static qt_QString * _qstring_fieldName = 0L;
	qt_QDataTable_setColumn((qt_QDataTable *)[self qt], (unsigned int)col, (qt_QString *) [fieldName toQString: &_qstring_fieldName], (qt_QString *) [label toQString: &_qstring_label], (int)width, (qt_QIconSet*) [iconset qt]);
	return self;
}

- setColumn: (unsigned int)col fieldName: (NSString *)fieldName
{
static qt_QString * _qstring_fieldName = 0L;
	qt_QDataTable_setColumn((qt_QDataTable *)[self qt], (unsigned int)col, (qt_QString *) [fieldName toQString: &_qstring_fieldName], qt_QString_null(), -1, 0);
	return self;
}

- (NSString *) nullText
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDataTable_nullText((qt_QDataTable *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) trueText
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDataTable_trueText((qt_QDataTable *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSString *) falseText
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDataTable_falseText((qt_QDataTable *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (int) dateFormat
{
	return (int) qt_QDataTable_dateFormat((qt_QDataTable *)[self qt]);
}

- (BOOL) confirmEdits
{
	return (BOOL) qt_QDataTable_confirmEdits((qt_QDataTable *)[self qt]);
}

- (BOOL) confirmInsert
{
	return (BOOL) qt_QDataTable_confirmInsert((qt_QDataTable *)[self qt]);
}

- (BOOL) confirmUpdate
{
	return (BOOL) qt_QDataTable_confirmUpdate((qt_QDataTable *)[self qt]);
}

- (BOOL) confirmDelete
{
	return (BOOL) qt_QDataTable_confirmDelete((qt_QDataTable *)[self qt]);
}

- (BOOL) confirmCancels
{
	return (BOOL) qt_QDataTable_confirmCancels((qt_QDataTable *)[self qt]);
}

- (BOOL) autoDelete
{
	return (BOOL) qt_QDataTable_autoDelete((qt_QDataTable *)[self qt]);
}

- (BOOL) autoEdit
{
	return (BOOL) qt_QDataTable_autoEdit((qt_QDataTable *)[self qt]);
}

- (NSString *) filter
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDataTable_filter((qt_QDataTable *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (NSArray *) sort
{
static qt_QStringList * _qlist = 0L;
	_qlist = qt_QDataTable_sort((qt_QDataTable *)[self qt]);
	return (NSArray *) [NSMutableArray arrayWithQStringList: _qlist];
}

- setSqlCursor: (QSqlCursor*)cursor autoPopulate: (BOOL)autoPopulate autoDelete: (BOOL)autoDelete
{
	qt_QDataTable_setSqlCursor((qt_QDataTable *)[self qt], (qt_QSqlCursor*) [cursor qt], (int)autoPopulate, (int)autoDelete);
	return self;
}

- setSqlCursor
{
	qt_QDataTable_setSqlCursor((qt_QDataTable *)[self qt], 0, 0, 0);
	return self;
}

- (QSqlCursor*) sqlCursor
{
	return (QSqlCursor*) [QtSupport objectForQtKey: qt_QDataTable_sqlCursor((qt_QDataTable *)[self qt]) withClass: [QSqlCursor class] allocatedInObjcWorld: YES];
}

- setNullText: (NSString *)nullText
{
static qt_QString * _qstring_nullText = 0L;
	qt_QDataTable_setNullText((qt_QDataTable *)[self qt], (qt_QString *) [nullText toQString: &_qstring_nullText]);
	return self;
}

- setTrueText: (NSString *)trueText
{
static qt_QString * _qstring_trueText = 0L;
	qt_QDataTable_setTrueText((qt_QDataTable *)[self qt], (qt_QString *) [trueText toQString: &_qstring_trueText]);
	return self;
}

- setFalseText: (NSString *)falseText
{
static qt_QString * _qstring_falseText = 0L;
	qt_QDataTable_setFalseText((qt_QDataTable *)[self qt], (qt_QString *) [falseText toQString: &_qstring_falseText]);
	return self;
}

- setDateFormat: (int)f
{
	qt_QDataTable_setDateFormat((qt_QDataTable *)[self qt], (int)f);
	return self;
}

- setConfirmEdits: (BOOL)confirm
{
	qt_QDataTable_setConfirmEdits((qt_QDataTable *)[self qt], (int)confirm);
	return self;
}

- setConfirmInsert: (BOOL)confirm
{
	qt_QDataTable_setConfirmInsert((qt_QDataTable *)[self qt], (int)confirm);
	return self;
}

- setConfirmUpdate: (BOOL)confirm
{
	qt_QDataTable_setConfirmUpdate((qt_QDataTable *)[self qt], (int)confirm);
	return self;
}

- setConfirmDelete: (BOOL)confirm
{
	qt_QDataTable_setConfirmDelete((qt_QDataTable *)[self qt], (int)confirm);
	return self;
}

- setConfirmCancels: (BOOL)confirm
{
	qt_QDataTable_setConfirmCancels((qt_QDataTable *)[self qt], (int)confirm);
	return self;
}

- setAutoDelete: (BOOL)enable
{
	qt_QDataTable_setAutoDelete((qt_QDataTable *)[self qt], (int)enable);
	return self;
}

- setAutoEdit: (BOOL)autoEdit
{
	qt_QDataTable_setAutoEdit((qt_QDataTable *)[self qt], (int)autoEdit);
	return self;
}

- setFilter: (NSString *)filter
{
static qt_QString * _qstring_filter = 0L;
	qt_QDataTable_setFilter((qt_QDataTable *)[self qt], (qt_QString *) [filter toQString: &_qstring_filter]);
	return self;
}

- setSortFromStringList: (NSArray *)sort
{
static qt_QStringList * _qlist_sort = 0L;
	qt_QDataTable_setSort((qt_QDataTable *)[self qt], (qt_QStringList*) [sort toQStringList: (void *)&_qlist_sort]);
	return self;
}

- setSort: (QSqlIndex*)sort
{
	qt_QDataTable_setSort1((qt_QDataTable *)[self qt], (qt_QSqlIndex*) [sort qt]);
	return self;
}

- refresh: (int)mode
{
	qt_QDataTable_refresh((qt_QDataTable *)[self qt], (int)mode);
	return self;
}

- sortColumn: (int)col ascending: (BOOL)ascending wholeRows: (BOOL)wholeRows
{
	qt_QDataTable_sortColumn((qt_QDataTable *)[self qt], (int)col, (int)ascending, (int)wholeRows);
	return self;
}

- sortColumn: (int)col 
{
	qt_QDataTable_sortColumn((qt_QDataTable *)[self qt], (int)col, 1, 0);
	return self;
}

- (NSString *) text: (int)row col: (int)col
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QDataTable_text((qt_QDataTable *)[self qt], (int)row, (int)col);
	return [NSString fromQString: _qstring];
}

- (QVariant*) value: (int)row col: (int)col
{
	return (QVariant*) [QtSupport objectForQtKey: qt_QDataTable_value((qt_QDataTable *)[self qt], (int)row, (int)col) withClass: [QVariant class] allocatedInObjcWorld: YES];
}

- (QSqlRecord*) currentRecord
{
	return (QSqlRecord*) [QtSupport objectForQtKey: qt_QDataTable_currentRecord((qt_QDataTable *)[self qt]) withClass: [QSqlRecord class] allocatedInObjcWorld: YES];
}

- installEditorFactory: (QSqlEditorFactory*)f
{
	qt_QDataTable_installEditorFactory((qt_QDataTable *)[self qt], (qt_QSqlEditorFactory*) [f qt]);
	return self;
}

- installPropertyMap: (QSqlPropertyMap*)m
{
	qt_QDataTable_installPropertyMap((qt_QDataTable *)[self qt], (qt_QSqlPropertyMap*) [m qt]);
	return self;
}

- (int) numCols
{
	return (int) qt_QDataTable_numCols((qt_QDataTable *)[self qt]);
}

- (int) numRows
{
	return (int) qt_QDataTable_numRows((qt_QDataTable *)[self qt]);
}

- setNumCols: (int)c
{
	qt_QDataTable_setNumCols((qt_QDataTable *)[self qt], (int)c);
	return self;
}

- setNumRows: (int)r
{
	qt_QDataTable_setNumRows((qt_QDataTable *)[self qt], (int)r);
	return self;
}

- (BOOL) findBuffer: (QSqlIndex*)idx atHint: (int)atHint
{
	return (BOOL) qt_QDataTable_findBuffer((qt_QDataTable *)[self qt], (qt_QSqlIndex*) [idx qt], (int)atHint);
}

- (BOOL) findBuffer: (QSqlIndex*)idx 
{
	return (BOOL) qt_QDataTable_findBuffer((qt_QDataTable *)[self qt], (qt_QSqlIndex*) [idx qt], 0);
}

- find: (NSString *)str caseSensitive: (BOOL)caseSensitive backwards: (BOOL)backwards
{
static qt_QString * _qstring_str = 0L;
	qt_QDataTable_find((qt_QDataTable *)[self qt], (qt_QString *) [str toQString: &_qstring_str], (int)caseSensitive, (int)backwards);
	return self;
}

- sortAscending: (int)col
{
	qt_QDataTable_sortAscending((qt_QDataTable *)[self qt], (int)col);
	return self;
}

- sortDescending: (int)col
{
	qt_QDataTable_sortDescending((qt_QDataTable *)[self qt], (int)col);
	return self;
}

- refresh
{
	qt_QDataTable_refresh1((qt_QDataTable *)[self qt]);
	return self;
}

- setColumnWidth: (int)col w: (int)w
{
	qt_QDataTable_setColumnWidth((qt_QDataTable *)[self qt], (int)col, (int)w);
	return self;
}

- (BOOL) insertCurrent
{
	return (BOOL) qt_QDataTable_insertCurrent((qt_QDataTable *)[self qt]);
}

- (BOOL) updateCurrent
{
	return (BOOL) qt_QDataTable_updateCurrent((qt_QDataTable *)[self qt]);
}

- (BOOL) deleteCurrent
{
	return (BOOL) qt_QDataTable_deleteCurrent((qt_QDataTable *)[self qt]);
}

- (int) confirmEdit: (int)m
{
	return (int) qt_QDataTable_confirmEdit((qt_QDataTable *)[self qt], (int)m);
}

- (int) confirmCancel: (int)m
{
	return (int) qt_QDataTable_confirmCancel((qt_QDataTable *)[self qt], (int)m);
}

- handleError: (QSqlError*)e
{
	qt_QDataTable_handleError((qt_QDataTable *)[self qt], (qt_QSqlError*) [e qt]);
	return self;
}

- (BOOL) beginInsert
{
	return (BOOL) qt_QDataTable_beginInsert((qt_QDataTable *)[self qt]);
}

- (QWidget*) beginUpdate: (int)row col: (int)col replace: (BOOL)replace
{
	return (QWidget*) [QtSupport objectForQtKey: qt_QDataTable_beginUpdate((qt_QDataTable *)[self qt], (int)row, (int)col, (int)replace) withClass: [QWidget class] allocatedInObjcWorld: YES];
}

- (BOOL) eventFilter: (QObject *)o e: (QEvent *)e
{
	return (BOOL) qt_QDataTable_eventFilter((qt_QDataTable *)[self qt], (qt_QObject *) [o qt], (qt_QEvent *) [e qt]);
}

- endEdit: (int)row col: (int)col accept: (BOOL)accept replace: (BOOL)replace
{
	qt_QDataTable_endEdit((qt_QDataTable *)[self qt], (int)row, (int)col, (int)accept, (int)replace);
	return self;
}

- (QWidget*) createEditor: (int)row col: (int)col initFromCell: (BOOL)initFromCell
{
	return (QWidget*) [QtSupport objectForQtKey: qt_QDataTable_createEditor((qt_QDataTable *)[self qt], (int)row, (int)col, (int)initFromCell) withClass: [QWidget class] allocatedInObjcWorld: YES];
}

- activateNextCell
{
	qt_QDataTable_activateNextCell((qt_QDataTable *)[self qt]);
	return self;
}

- (int) indexOf: (unsigned int)i
{
	return (int) qt_QDataTable_indexOf((qt_QDataTable *)[self qt], (unsigned int)i);
}

- reset
{
	qt_QDataTable_reset((qt_QDataTable *)[self qt]);
	return self;
}

- setSize: (QSqlCursor*)sql
{
	qt_QDataTable_setSize((qt_QDataTable *)[self qt], (qt_QSqlCursor*) [sql qt]);
	return self;
}

- repaintCell: (int)row col: (int)col
{
	qt_QDataTable_repaintCell((qt_QDataTable *)[self qt], (int)row, (int)col);
	return self;
}

- paintCell: (QPainter *)p row: (int)row col: (int)col cr: (QRect*)cr selected: (BOOL)selected cg: (QColorGroup *)cg
{
	qt_QDataTable_paintCell((qt_QDataTable *)[self qt], (qt_QPainter *) [p qt], (int)row, (int)col, (qt_QRect*) [cr qt], (int)selected, (qt_QColorGroup *) [cg qt]);
	return self;
}

- paintField: (QPainter *)p field: (QSqlField*)field cr: (QRect*)cr selected: (BOOL)selected
{
	qt_QDataTable_paintField((qt_QDataTable *)[self qt], (qt_QPainter *) [p qt], (qt_QSqlField*) [field qt], (qt_QRect*) [cr qt], (int)selected);
	return self;
}

- (int) fieldAlignment: (QSqlField*)field
{
	return (int) qt_QDataTable_fieldAlignment((qt_QDataTable *)[self qt], (qt_QSqlField*) [field qt]);
}

- columnClicked: (int)col
{
	qt_QDataTable_columnClicked((qt_QDataTable *)[self qt], (int)col);
	return self;
}

- resizeData: (int)len
{
	qt_QDataTable_resizeData((qt_QDataTable *)[self qt], (int)len);
	return self;
}

- (QTableItem*) item: (int)row col: (int)col
{
	return (QTableItem*) [QtSupport objectForQtKey: qt_QDataTable_item((qt_QDataTable *)[self qt], (int)row, (int)col) withClass: [QTableItem class] allocatedInObjcWorld: YES];
}

- setItem: (int)row col: (int)col item: (QTableItem*)item
{
	qt_QDataTable_setItem((qt_QDataTable *)[self qt], (int)row, (int)col, (qt_QTableItem*) [item qt]);
	return self;
}

- clearCell: (int)row col: (int)col
{
	qt_QDataTable_clearCell((qt_QDataTable *)[self qt], (int)row, (int)col);
	return self;
}

- setPixmap: (int)row col: (int)col pix: (QPixmap *)pix
{
	qt_QDataTable_setPixmap((qt_QDataTable *)[self qt], (int)row, (int)col, (qt_QPixmap *) [pix qt]);
	return self;
}

- takeItem: (QTableItem*)i
{
	qt_QDataTable_takeItem((qt_QDataTable *)[self qt], (qt_QTableItem*) [i qt]);
	return self;
}

+ (int) RefreshData
{
	return (int) QDATATABLE_RefreshData;
}

+ (int) RefreshColumns
{
	return (int) QDATATABLE_RefreshColumns;
}

+ (int) RefreshAll
{
	return (int) QDATATABLE_RefreshAll;
}

@end
