From 285c753fe579cb6376764cb77f6ce2820313d9d6 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 14 Dec 2009 23:16:30 +0000 Subject: [PATCH] 2009-12-14 10:01 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt.h * contrib/hbqt/hbqt_hbqtableview.cpp * contrib/hbqt/qtgui/QTableView.cpp * contrib/hbqt/qtgui/TQTableView.prg * contrib/hbqt/qth/QTableView.qth * contrib/hbxbp/xbpbrowse.prg + Implemented GC collectible pointers for HBTableView() class. --- harbour/ChangeLog | 9 +++ harbour/contrib/hbqt/hbqt.h | 3 +- harbour/contrib/hbqt/hbqt_hbqtableview.cpp | 78 ++++++++++++++++++++-- harbour/contrib/hbqt/qtgui/QTableView.cpp | 35 +++++----- harbour/contrib/hbqt/qtgui/TQTableView.prg | 4 -- harbour/contrib/hbqt/qth/QTableView.qth | 20 ------ harbour/contrib/hbxbp/xbpbrowse.prg | 6 +- 7 files changed, 99 insertions(+), 56 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 4799670acf..82657d9181 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,15 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-14 10:01 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) + * contrib/hbqt/hbqt.h + * contrib/hbqt/hbqt_hbqtableview.cpp + * contrib/hbqt/qtgui/QTableView.cpp + * contrib/hbqt/qtgui/TQTableView.prg + * contrib/hbqt/qth/QTableView.qth + * contrib/hbxbp/xbpbrowse.prg + + Implemented GC collectible pointers for HBTableView() class. + 2009-12-14 10:01 UTC-0800 Pritpal Bedi (pritpal@vouchcac.com) * contrib/hbqt/hbqt.h * contrib/hbqt/hbqt_hbdbfmodel.cpp diff --git a/harbour/contrib/hbqt/hbqt.h b/harbour/contrib/hbqt/hbqt.h index 743991c889..a4e17ea365 100644 --- a/harbour/contrib/hbqt/hbqt.h +++ b/harbour/contrib/hbqt/hbqt.h @@ -379,8 +379,7 @@ extern int hbqt_getmemused( void ); #define hbqt_par_HBDbfModel( n ) ( ( HBDbfModel * ) hbqt_gcpointer( n ) ) #define hbqt_par_HBQMainWindow( n ) ( ( HBQMainWindow * ) hbqt_gcpointer( n ) ) - -#define hbqt_par_HBQTableView( n ) ( ( HBQTableView* ) hb_parptr( n ) ) +#define hbqt_par_HBQTableView( n ) ( ( HBQTableView * ) hbqt_gcpointer( n ) ) #define hbqt_par_QString( n ) ( ( QString ) hb_parcx( n ) ) #define hbqt_par_QRgb( n ) ( hb_parnint( n ) ) diff --git a/harbour/contrib/hbqt/hbqt_hbqtableview.cpp b/harbour/contrib/hbqt/hbqt_hbqtableview.cpp index 8608f6d730..2e63df4a85 100644 --- a/harbour/contrib/hbqt/hbqt_hbqtableview.cpp +++ b/harbour/contrib/hbqt/hbqt_hbqtableview.cpp @@ -59,6 +59,7 @@ #if QT_VERSION >= 0x040500 +#include #include "hbqt_hbqtableview.h" HBQTableView::HBQTableView( QWidget * parent ) : QTableView( parent ) @@ -67,11 +68,6 @@ HBQTableView::HBQTableView( QWidget * parent ) : QTableView( parent ) HBQTableView::~HBQTableView() { - HB_TRACE( HB_TR_DEBUG, ( "HBQTableView::~HBQTableView: BEGIN %i %i", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); - - destroy(); - - HB_TRACE( HB_TR_DEBUG, ( "HBQTableView::~HBQTableView: END %i %i", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); } void HBQTableView::keyPressEvent( QKeyEvent * event ) @@ -112,8 +108,6 @@ void HBQTableView::resizeEvent( QResizeEvent * event ) QModelIndex HBQTableView::moveCursor( HBQTableView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers ) { // HB_TRACE( HB_TR_DEBUG, ( "HBQTableView::moveCursor( action=%i %i )", cursorAction, QAbstractItemView::MoveDown ) ); - - //emit sg_moveCursor( cursorAction, modifiers ); return QTableView::moveCursor( cursorAction, modifiers ); } @@ -134,4 +128,74 @@ void HBQTableView::scrollTo( const QModelIndex & index, QAbstractItemView::Scrol QTableView::scrollTo( index, hint ); } +typedef struct +{ + void * ph; + QT_G_FUNC_PTR func; + QPointer< HBQTableView > pq; +} QGC_POINTER_HBQTableView; + +QT_G_FUNC( release_HBQTableView ) +{ + QGC_POINTER_HBQTableView * p = ( QGC_POINTER_HBQTableView * ) Cargo; + + HB_TRACE( HB_TR_DEBUG, ( "release_HBQTableView p=%p", p)); + HB_TRACE( HB_TR_DEBUG, ( "release_HBQTableView ph=%p pq=%p", p->ph, (void *)(p->pq))); + + if( p && p->ph && p->pq ) + { + const QMetaObject * m = ( ( QObject * ) p->ph )->metaObject(); + if( ( QString ) m->className() != ( QString ) "QObject" ) + { + switch( hbqt_get_object_release_method() ) + { + case HBQT_RELEASE_WITH_DELETE: + delete ( ( HBQTableView * ) p->ph ); + break; + case HBQT_RELEASE_WITH_DESTRUTOR: + ( ( HBQTableView * ) p->ph )->~HBQTableView(); + break; + case HBQT_RELEASE_WITH_DELETE_LATER: + ( ( HBQTableView * ) p->ph )->deleteLater(); + break; + } + p->ph = NULL; + HB_TRACE( HB_TR_DEBUG, ( "release_HBQTableView Object deleted! %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); + } + else + { + HB_TRACE( HB_TR_DEBUG, ( "NO release_HBQTableView Object Name Missing!" ) ); + } + } + else + { + HB_TRACE( HB_TR_DEBUG, ( "DEL release_HBQTableView Object Already deleted!" ) ); + } +} + +void * gcAllocate_HBQTableView( void * pObj ) +{ + QGC_POINTER_HBQTableView * p = ( QGC_POINTER_HBQTableView * ) hb_gcAllocate( sizeof( QGC_POINTER_HBQTableView ), gcFuncs() ); + + p->ph = pObj; + p->func = release_HBQTableView; + new( & p->pq ) QPointer< HBQTableView >( ( HBQTableView * ) pObj ); + HB_TRACE( HB_TR_DEBUG, ( " new_HBQTableView %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); + return( p ); +} + +HB_FUNC( QT_HBQTABLEVIEW ) +{ + void * pObj = NULL; + + pObj = ( HBQTableView* ) new HBQTableView( hbqt_par_QWidget( 1 ) ) ; + + hb_retptrGC( gcAllocate_HBQTableView( pObj ) ); +} + +HB_FUNC( QT_HBQTABLEVIEW_NAVIGATE ) +{ + hb_retptr( new QModelIndex( hbqt_par_HBQTableView( 1 )->navigate( hb_parni( 2 ) ) ) ); +} + #endif diff --git a/harbour/contrib/hbqt/qtgui/QTableView.cpp b/harbour/contrib/hbqt/qtgui/QTableView.cpp index 9bd846d951..eabd78ce10 100644 --- a/harbour/contrib/hbqt/qtgui/QTableView.cpp +++ b/harbour/contrib/hbqt/qtgui/QTableView.cpp @@ -77,22 +77,6 @@ * ~QTableView () */ -HB_FUNC( QT_HBQTABLEVIEW ) -{ - hb_retptr( new HBQTableView( hbqt_par_QWidget( 1 ) ) ); -} - -HB_FUNC( QT_HBQTABLEVIEW_NAVIGATE ) -{ - hb_retptr( new QModelIndex( hbqt_par_HBQTableView( 1 )->navigate( hb_parni( 2 ) ) ) ); -} - -/* TOFIX: Leak if .prg code doesn't call this explicitly. */ -HB_FUNC( QT_HBQTABLEVIEW_DESTROY ) -{ - hbqt_par_HBQTableView( 1 )->~HBQTableView(); -} - typedef struct { @@ -126,16 +110,25 @@ QT_G_FUNC( release_QTableView ) break; } p->ph = NULL; - HB_TRACE( HB_TR_DEBUG, ( "release_QTableView Object deleted! %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); + HB_TRACE( HB_TR_DEBUG, ( "release_QTableView Object deleted!" ) ); + #if defined( __HB_DEBUG__ ) + hbqt_debug( " YES release_QTableView %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ); + #endif } else { - HB_TRACE( HB_TR_DEBUG, ( "NO release_QTableView Object Name Missing!" ) ); + HB_TRACE( HB_TR_DEBUG, ( "release_QTableView Object Name Missing!" ) ); + #if defined( __HB_DEBUG__ ) + hbqt_debug( " NO release_QTableView" ); + #endif } } else { - HB_TRACE( HB_TR_DEBUG, ( "DEL release_QTableView Object Already deleted!" ) ); + HB_TRACE( HB_TR_DEBUG, ( "release_QTableView Object Allready deleted!" ) ); + #if defined( __HB_DEBUG__ ) + hbqt_debug( " DEL release_QTableView" ); + #endif } } @@ -146,7 +139,9 @@ void * gcAllocate_QTableView( void * pObj ) p->ph = pObj; p->func = release_QTableView; new( & p->pq ) QPointer< QTableView >( ( QTableView * ) pObj ); - HB_TRACE( HB_TR_DEBUG, ( " new_QTableView %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ) ); + #if defined( __HB_DEBUG__ ) + hbqt_debug( " new_QTableView %i B %i KB", ( int ) hb_xquery( 1001 ), hbqt_getmemused() ); + #endif return( p ); } diff --git a/harbour/contrib/hbqt/qtgui/TQTableView.prg b/harbour/contrib/hbqt/qtgui/TQTableView.prg index a13114bcec..bcf844071a 100644 --- a/harbour/contrib/hbqt/qtgui/TQTableView.prg +++ b/harbour/contrib/hbqt/qtgui/TQTableView.prg @@ -304,7 +304,6 @@ CREATE CLASS HBQTableView INHERIT QTableView METHOD new( pParent ) METHOD navigate( nCursorAction, nModifiers ) - METHOD destroy() ENDCLASS @@ -315,7 +314,4 @@ METHOD HBQTableView:new( pParent ) METHOD HBQTableView:navigate( nCursorAction, nModifiers ) RETURN Qt_HBQTableView_navigate( ::pPtr, nCursorAction, nModifiers ) -METHOD HBQTableView:destroy() - RETURN Qt_HBQTableView_destroy( ::pPtr ) - diff --git a/harbour/contrib/hbqt/qth/QTableView.qth b/harbour/contrib/hbqt/qth/QTableView.qth index e8bea2f106..569d6d95e2 100644 --- a/harbour/contrib/hbqt/qth/QTableView.qth +++ b/harbour/contrib/hbqt/qth/QTableView.qth @@ -64,7 +64,6 @@ CREATE CLASS HBQTableView INHERIT QTableView METHOD new( pParent ) METHOD navigate( nCursorAction, nModifiers ) - METHOD destroy() ENDCLASS @@ -75,9 +74,6 @@ METHOD HBQTableView:new( pParent ) METHOD HBQTableView:navigate( nCursorAction, nModifiers ) RETURN Qt_HBQTableView_navigate( ::pPtr, nCursorAction, nModifiers ) -METHOD HBQTableView:destroy() - RETURN Qt_HBQTableView_destroy( ::pPtr ) - @@ -94,22 +90,6 @@ HB_FUNC( QT_QTABLEVIEW ) hb_retptr( ( QTableView* ) new QTableView( hbqt_par_QWidget( 1 ) ) ); } -HB_FUNC( QT_HBQTABLEVIEW ) -{ - hb_retptr( new HBQTableView( hbqt_par_QWidget( 1 ) ) ); -} - -HB_FUNC( QT_HBQTABLEVIEW_NAVIGATE ) -{ - hb_retptr( new QModelIndex( hbqt_par_HBQTableView( 1 )->navigate( hb_parni( 2 ) ) ) ); -} - -/* TOFIX: Leak if .prg code doesn't call this explicitly. */ -HB_FUNC( QT_HBQTABLEVIEW_DESTROY ) -{ - hbqt_par_HBQTableView( 1 )->~HBQTableView(); -} - diff --git a/harbour/contrib/hbxbp/xbpbrowse.prg b/harbour/contrib/hbxbp/xbpbrowse.prg index d7b3d5c699..93fcf168e8 100644 --- a/harbour/contrib/hbxbp/xbpbrowse.prg +++ b/harbour/contrib/hbxbp/xbpbrowse.prg @@ -718,20 +718,20 @@ METHOD XbpBrowse:destroy() ::oHScrollBar:pPtr := 0 ::oVScrollBar:pPtr := 0 - ::oLeftView:destroy() + ::oLeftView:pPtr := 0 ::oLeftDbfModel:pPtr := 0 ::oLeftVHeaderView:pPtr := 0 ::oLeftHeaderView:pPtr := 0 ::oLeftFooterView:pPtr := 0 ::oLeftFooterModel:pPtr := 0 - ::oRightView:destroy() + ::oRightView:pPtr := 0 ::oRightHeaderView:pPtr := 0 ::oRightDbfModel:pPtr := 0 ::oRightFooterView:pPtr := 0 ::oRightFooterModel:pPtr := 0 - ::oTableView:destroy() + ::oTableView:pPtr := 0 ::oVHeaderView:pPtr := 0 ::oDbfModel:pPtr := 0