From 7cf128ef3c69fdae202936d37e65cc0ee8f98122 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 11 Jun 2012 23:27:25 +0000 Subject: [PATCH] 2012-06-11 16:08 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbqt/hbmk2_qt.hb ! Formatting: of generated sources. * contrib/hbqt/qtcore/hbqt_bind.cpp ! Minor. * contrib/hbqt/tests/browqt.prg * contrib/hbqt/tests/dbfbrowser.prg * contrib/hbqt/tests/dbfbrowserclass.prg * contrib/hbqt/tests/demoqt.prg * contrib/hbqt/tests/qtrevamp.prg * contrib/hbqt/tests/testbrow.prg * contrib/hbqt/tests/testqaim.prg ! Tweaked: to excute flawless on both protocols. --- harbour/ChangeLog | 16 +++++++ harbour/contrib/hbqt/hbmk2_qt.hb | 4 +- harbour/contrib/hbqt/qtcore/hbqt_bind.cpp | 30 ++++++------ harbour/contrib/hbqt/tests/browqt.prg | 2 +- harbour/contrib/hbqt/tests/dbfbrowser.prg | 20 ++++---- .../contrib/hbqt/tests/dbfbrowserclass.prg | 48 +++++++++++-------- harbour/contrib/hbqt/tests/demoqt.prg | 3 ++ harbour/contrib/hbqt/tests/qtrevamp.prg | 38 +++++++++------ harbour/contrib/hbqt/tests/testbrow.prg | 10 ++-- harbour/contrib/hbqt/tests/testqaim.prg | 22 ++++----- 10 files changed, 116 insertions(+), 77 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 396a60f355..416af6f2df 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,22 @@ The license applies to all entries newer than 2009-04-28. */ +2012-06-11 16:08 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbqt/hbmk2_qt.hb + ! Formatting: of generated sources. + + * contrib/hbqt/qtcore/hbqt_bind.cpp + ! Minor. + + * contrib/hbqt/tests/browqt.prg + * contrib/hbqt/tests/dbfbrowser.prg + * contrib/hbqt/tests/dbfbrowserclass.prg + * contrib/hbqt/tests/demoqt.prg + * contrib/hbqt/tests/qtrevamp.prg + * contrib/hbqt/tests/testbrow.prg + * contrib/hbqt/tests/testqaim.prg + ! Tweaked: to excute flawless on both protocols. + 2012-06-11 12:56 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + contrib/hbqt/tests/dbfbrowser.prg + contrib/hbqt/tests/dbfbrowserclass.prg diff --git a/harbour/contrib/hbqt/hbmk2_qt.hb b/harbour/contrib/hbqt/hbmk2_qt.hb index d465f08420..6e4330cc72 100644 --- a/harbour/contrib/hbqt/hbmk2_qt.hb +++ b/harbour/contrib/hbqt/hbmk2_qt.hb @@ -33,7 +33,7 @@ #include "directry.ch" #include "hbclass.ch" -//#define __HBQT_REVAMP__ +#define __HBQT_REVAMP__ #define I_( x ) hb_i18n_gettext( x ) @@ -1996,7 +1996,7 @@ METHOD HbQtSource:getConstructor() NEXT AAdd( aLine, " " ) #ifdef __HBQT_REVAMP__ - AAdd( aLine, ' hb_itemReturnRelease( hbqt_bindSetHbObject( NULL, pObj, ( "' + 'HB_' + upper( ::cQtObject ) +'" ), hbqt_del_' + ::cQtObject + ', ' + qth_get_bits( ::cQtObject, ! ::isDetached ) + ' ) );' ) + AAdd( aLine, ' hb_itemReturnRelease( hbqt_bindSetHbObject( NULL, pObj, "' + 'HB_' + upper( ::cQtObject ) +'", hbqt_del_' + ::cQtObject + ', ' + qth_get_bits( ::cQtObject, ! ::isDetached ) + ' ) );' ) #else AAdd( aLine, " hbqt_itemPushReturn( hbqt_gcAllocate_" + ::cQtObject + "( ( void * ) pObj, " + iif( ::isDetached, "false", "true" ) + " ), hb_stackSelfItem() );" ) #endif diff --git a/harbour/contrib/hbqt/qtcore/hbqt_bind.cpp b/harbour/contrib/hbqt/qtcore/hbqt_bind.cpp index d7eb24b016..277d6ce971 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_bind.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_bind.cpp @@ -77,6 +77,7 @@ typedef struct _HBQT_BIND PHBQT_DEL_FUNC pDelFunc; int iFlags; bool fDeleting; + char szClassName[ 100 ]; struct _HBQT_BIND * next; } HBQT_BIND, * PHBQT_BIND; @@ -109,10 +110,10 @@ static void hbqt_bind_init( void* cargo ) PHB_ITEM hbqt_bindGetHbObject( PHB_ITEM pItem, void * qtObject, const char * szClassName, PHBQT_DEL_FUNC pDelFunc, int iFlags ) { - #if 0 + #if 1 char * pname = ( char* ) hb_xgrab( 200 ); char * pname1 = ( char* ) hb_xgrab( 200 ); - HB_TRACE( HB_TR_DEBUG, ( ".................HARBOUR_REQUEST_BIND_OBJECT( %p, %i, %s, %s, %s ).................", qtObject, iFlags, szClassName, hb_procname( 0, pname, HB_TRUE ), hb_procname( 1, pname1, HB_TRUE ) ) ); + HB_TRACE( HB_TR_ALWAYS, ( ".................HARBOUR_REQUEST_BIND_OBJECT( %p, %i, %s, %s, %s ).................", qtObject, iFlags, szClassName, hb_procname( 0, pname, HB_TRUE ), hb_procname( 1, pname1, HB_TRUE ) ) ); hb_xfree( pname ); hb_xfree( pname1 ); #endif @@ -165,6 +166,7 @@ PHB_ITEM hbqt_bindGetHbObject( PHB_ITEM pItem, void * qtObject, const char * szC bind->pDelFunc = pDelFunc; bind->iFlags = iFlags; bind->fDeleting = false; + hb_strncpy( bind->szClassName, szClassName, 99 ); bind->next = s_hbqt_binds; s_hbqt_binds = bind; } @@ -232,6 +234,7 @@ PHB_ITEM hbqt_bindSetHbObject( PHB_ITEM pItem, void * qtObject, const char * szC bind->pDelFunc = pDelFunc; bind->iFlags = iFlags; bind->fDeleting = false; + hb_strncpy( bind->szClassName, szClassName, 99 ); bind->next = s_hbqt_binds; s_hbqt_binds = bind; @@ -326,7 +329,7 @@ void hbqt_bindDestroyHbObject( PHB_ITEM pObject ) { if( bind->hbObject == hbObject ) { - HB_TRACE( HB_TR_DEBUG, ( "..............HARBOUR_DESTROY_BEGINS( %p, %i )..............", bind->qtObject, bind->iFlags ) ); + HB_TRACE( HB_TR_ALWAYS, ( "..............HARBOUR_DESTROY_BEGINS( %p, %i ).............. %s", bind->qtObject, bind->iFlags, bind->szClassName ) ); found = HB_TRUE; bool fObject = bind->iFlags & HBQT_BIT_QOBJECT; @@ -350,9 +353,12 @@ void hbqt_bindDestroyHbObject( PHB_ITEM pObject ) if( obj->parent() == NULL ) { * bind_ptr = bind->next; - bind->fDeleting = true; - bind->pDelFunc( obj, bind->iFlags ); - bind->fDeleting = false; + if( bind->pDelFunc != NULL ) + { + bind->fDeleting = true; + bind->pDelFunc( bind->qtObject, bind->iFlags ); + bind->fDeleting = false; + } hb_xfree( bind ); HB_TRACE( HB_TR_DEBUG, ( "HARBOUR_DESTROYED_%s( %p )", classname, obj ) ); } @@ -419,21 +425,14 @@ void hbqt_bindDestroyQtObject( void * qtObject ) { if( bind->qtObject == qtObject ) { + HB_TRACE( HB_TR_ALWAYS, ( "..............QT_DESTROY_BEGINS( %p ).............. %s fDeleting = %s", qtObject, bind->szClassName, bind->fDeleting ? "YES" : "NO" ) ); + * bind_ptr = bind->next; if( ! bind->fDeleting ) { - if( bind->iFlags & HBQT_BIT_QOBJECT ) - { - HB_TRACE( HB_TR_DEBUG, ( "QT_DESTROYED_%s( %p )", ( ( QObject * ) bind->qtObject )->metaObject()->className(), bind->qtObject ) ); - } - else - { - HB_TRACE( HB_TR_DEBUG, ( "QT_DESTROYED( %p )", bind->qtObject ) ); - } hbqt_bindDelSlots( hbqt_bindGetHbObjectBYqtObject( bind->qtObject ) ); hb_xfree( bind ); } - bind->fDeleting = false; break; } bind_ptr = &bind->next; @@ -701,3 +700,4 @@ HB_CALL_ON_STARTUP_END( _hbqt_bind_init_ ) #define HB_DATASEG_BODY HB_DATASEG_FUNC( _hbqt_bind_init_ ) #include "hbiniseg.h" #endif + diff --git a/harbour/contrib/hbqt/tests/browqt.prg b/harbour/contrib/hbqt/tests/browqt.prg index 543545fa78..6d225897c7 100644 --- a/harbour/contrib/hbqt/tests/browqt.prg +++ b/harbour/contrib/hbqt/tests/browqt.prg @@ -77,7 +77,7 @@ STATIC PROCEDURE BuildADialog() RETURN STATIC PROCEDURE my_save( qWidget, nArea, aStru, nCX, nCY ) - LOCAL cData := qWidget:text() + LOCAL cData := qWidget:property( "text" ):toString() DBSelectArea( nArea ) DBGoto( nCY + 1 ) diff --git a/harbour/contrib/hbqt/tests/dbfbrowser.prg b/harbour/contrib/hbqt/tests/dbfbrowser.prg index ffdeb6dce9..73937d4191 100644 --- a/harbour/contrib/hbqt/tests/dbfbrowser.prg +++ b/harbour/contrib/hbqt/tests/dbfbrowser.prg @@ -11,8 +11,6 @@ */ #include "hbqtgui.ch" -#include "dbfbrowserclass.prg" - PROCEDURE Main() LOCAL oWid @@ -54,13 +52,17 @@ PROCEDURE Main() oWid:Show() QApplication():exec() -RETURN - + + oTable1:destroy() // Mainly to disconnect signals + + oButton1:disconnect( "clicked()" ) // The only way for GC to resolve + oButton2:disconnect( "clicked()" ) + RETURN PROCEDURE OpenDBF( oWid, oTable ) STATIC cDir := "." LOCAL cFile - + cFile := QFileDialog():getOpenFileName( oWid, "Open file", cDir, "DBF files (*.dbf);;All files (*.*)" ) IF cFile == "" @@ -74,15 +76,15 @@ PROCEDURE OpenDBF( oWid, oTable ) DBUseArea( .T., NIL, cFile, NIL, .F., .F. ) END SEQUENCE - If Used() + IF Used() oTable:attach() - End -RETURN + ENDIF + RETURN PROCEDURE CloseDBF( oTable ) oTable:detach() DBCloseArea() -RETURN + RETURN #include "dbfbrowserclass.prg" diff --git a/harbour/contrib/hbqt/tests/dbfbrowserclass.prg b/harbour/contrib/hbqt/tests/dbfbrowserclass.prg index 15149ff5be..6653839dac 100644 --- a/harbour/contrib/hbqt/tests/dbfbrowserclass.prg +++ b/harbour/contrib/hbqt/tests/dbfbrowserclass.prg @@ -10,8 +10,8 @@ * */ -#ifndef HB_QDBFBROWSER_CH_ -#define HB_QDBFBROWSER_CH_ +#ifndef HB_QDBFBROWSER_PRG_ +#define HB_QDBFBROWSER_PRG_ #include "hbclass.ch" @@ -23,41 +23,48 @@ CREATE CLASS B2QDBFBrowser INHERIT HB_QTableView FUNCTION B2_QDBFBrowser METHOD init() METHOD attach() METHOD detach() + METHOD destroy() VAR oModel VAR nArea INIT 0 VAR aStru - VAR oHack1 -ENDCLASS + VAR oItemDgt + ENDCLASS METHOD init() ::oModel := HBQAbstractItemModel( {| t, r, x, y| B2_QDBFBrowse( Self, t, r, x, y ) } ) - Self:setModel( ::oModel ) -RETURN Self + ::setModel( ::oModel ) + ::oItemDgt := ::itemDelegate() + ::oItemDgt:connect( "commitData(QWidget*)", {|oWidget| B2_QDBFCommit( Self, oWidget ) } ) + RETURN Self +METHOD B2QDBFBrowser:destroy() + ::oItemDgt:disconnect( "commitData(QWidget*)" ) + ::oModel:reset() + ::nArea := 0 + IF Select() > 0 + DbCloseArea() + ENDIF + RETURN NIL + METHOD B2QDBFBrowser:attach() - If ( ::nArea := Select() ) > 0 + IF ( ::nArea := Select() ) > 0 ::aStru := DBStruct() ::oModel:reset() - ::oHack1 := ::itemDelegate() // Intermediate variable needed to avoid destroying the :connect() - ::oHack1:connect( "commitData(QWidget*)", {|oWidget| B2_QDBFCommit( Self, oWidget ) } ) - End -RETURN NIL + ENDIF + RETURN NIL METHOD B2QDBFBrowser:detach() - ::oHack1 := ::itemDelegate() // Intermediate variable needed to avoid destroying the :connect() - ::oHack1:disconnect( "commitData(QWidget*)" ) ::nArea := 0 ::oModel:reset() -RETURN NIL - + RETURN NIL PROCEDURE B2_QDBFCommit( o, oWidget ) LOCAL oIndex := o:currentIndex() LOCAL nCX := oIndex:column() LOCAL nCY := oIndex:row() - Local nOldArea := Select() + LOCAL nOldArea := Select() LOCAL cData := oWidget:property( "text" ):toString() DBSelectArea( o:nArea ) @@ -79,16 +86,16 @@ PROCEDURE B2_QDBFCommit( o, oWidget ) ENDSWITCH DBSelectArea( nOldArea ) -RETURN + RETURN FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY ) LOCAL xRet LOCAL nOldArea := Select() - If o:nArea == 0 + IF o:nArea == 0 RETURN NIL - END + ENDIF SWITCH nT CASE HBQT_QAIM_flags @@ -149,8 +156,10 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY ) RETURN Qt_AlignVCenter + Qt_AlignLeft CASE "N" RETURN Qt_AlignVCenter + Qt_AlignRight + ENDSWITCH RETURN Qt_AlignCenter + ENDSWITCH RETURN NIL @@ -178,6 +187,7 @@ FUNCTION B2_QDBFBrowse( o, nT, nRole, nX, nY ) CASE HBQT_QAIM_columnCount RETURN Len( o:aStru ) + ENDSWITCH RETURN NIL diff --git a/harbour/contrib/hbqt/tests/demoqt.prg b/harbour/contrib/hbqt/tests/demoqt.prg index a0b5fa88b3..2051953f63 100644 --- a/harbour/contrib/hbqt/tests/demoqt.prg +++ b/harbour/contrib/hbqt/tests/demoqt.prg @@ -124,6 +124,9 @@ PROCEDURE Main() QApplication():exec() + oBtn:disconnect( "clicked()" ) + oBtn := NIL + HB_TRACE( HB_TR_DEBUG, ".............. E X I T I N G ...................", valtype( oLabel ) ) xReleaseMemory( { oBtn, oLabel, oProg, oSBar, aGrid, aList, aMenu, aTool, aTabs, oDA, oWnd } ) diff --git a/harbour/contrib/hbqt/tests/qtrevamp.prg b/harbour/contrib/hbqt/tests/qtrevamp.prg index 166bbcc396..c9c9fc9071 100644 --- a/harbour/contrib/hbqt/tests/qtrevamp.prg +++ b/harbour/contrib/hbqt/tests/qtrevamp.prg @@ -5,6 +5,11 @@ #include "hbtrace.ch" +// Why do we need these two variables in scope ? +// Because :connect needs that Harbour object must +// always be accessible. +// +STATIC oItemIns, oItemMod FUNCTION Main() LOCAL oWnd @@ -21,18 +26,19 @@ FUNCTION Main() QApplication():exec() + IF ! empty( oItemIns ) + oItemIns:disconnect( "triggered()", {|| DlgMBox( "Yes" ) } ) + ENDIF + IF ! empty( oItemMod ) + oItemMod:disconnect( "triggered()", {|| ContextMenu( oWnd ) } ) + ENDIF + RETURN NIL STATIC FUNCTION BuildMenuBar( oWnd ) LOCAL oMenu1, oMenuBar - // Why do we need these two variables in scope ? - // Because :connect needs that Harbour object must - // always be accessible. - // - STATIC oItemIns, oItemMod - oMenuBar := QMenuBar( oWnd ) // if we do not construct a widget without a parent @@ -43,14 +49,18 @@ STATIC FUNCTION BuildMenuBar( oWnd ) // oMenu1:setTitle( "&Options" ) - oItemIns := QAction( oMenu1 ) - oItemIns:setText( "&MessageBox()" ) - oItemIns:connect( "triggered()", {|| DlgMBox( "Yes" ) } ) - - oItemMod := QAction( oMenu1 ) - oItemMod:setText( "&ContextMenu()" ) - oItemMod:connect( "triggered()", {|| ContextMenu( oWnd ) } ) - + IF empty( oItemIns ) + oItemIns := QAction( oMenu1 ) + oItemIns:setText( "&MessageBox()" ) + oItemIns:connect( "triggered()", {|| DlgMBox( "Yes" ) } ) + ENDIF + + IF empty( oItemMod ) + oItemMod := QAction( oMenu1 ) + oItemMod:setText( "&ContextMenu()" ) + oItemMod:connect( "triggered()", {|| ContextMenu( oWnd ) } ) + ENDIF + oMenu1:addAction( oItemIns ) oMenu1:addAction( oItemMod ) diff --git a/harbour/contrib/hbqt/tests/testbrow.prg b/harbour/contrib/hbqt/tests/testbrow.prg index c19688b252..f0309d754b 100644 --- a/harbour/contrib/hbqt/tests/testbrow.prg +++ b/harbour/contrib/hbqt/tests/testbrow.prg @@ -62,7 +62,6 @@ PROCEDURE Main() #ifdef _method_local_ oID := tb1:itemDelegate() oID:connect( "commitData(QWidget*)", {| w | my_save( w, 1, aStru1, @nCX1, @nCY1 ) } ) - oID := NIL oSM := tb1:selectionModel() oSM:connect( "currentChanged(QModelIndex,QModelIndex)", {| n | my_select( n, @nCX1, @nCY1 ) } ) @@ -92,18 +91,19 @@ PROCEDURE Main() lay2:addWidget( bt2 ) lay2:addWidget( bt3 ) - HB_TRACE( HB_TR_DEBUG, "AAAAA" ) oWnd:Show() - HB_TRACE( HB_TR_DEBUG, "BBBBB" ) QApplication():exec() - HB_TRACE( HB_TR_DEBUG, "CCCCC" ) +#ifdef _method_local_ + oID:disconnect( "commitData(QWidget*)" ) +#endif + HB_TRACE( HB_TR_DEBUG, ( "my_select "+hb_ntos( nCX1 )+ "/"+hb_ntos( nCY1 ) ) ) RETURN STATIC PROCEDURE my_save( qWidget, nArea, aStru, nCX, nCY ) - LOCAL cData := qWidget:text() + LOCAL cData := qWidget:property( "text" ):toString() DBSelectArea( nArea ) DBGoto( nCY + 1 ) diff --git a/harbour/contrib/hbqt/tests/testqaim.prg b/harbour/contrib/hbqt/tests/testqaim.prg index 0f68d86ca6..0f2ba93c5b 100644 --- a/harbour/contrib/hbqt/tests/testqaim.prg +++ b/harbour/contrib/hbqt/tests/testqaim.prg @@ -16,13 +16,11 @@ #include "common.ch" -STATIC oWnd - -STATIC oDA, oForeColor, oAlphaColor, oBackBrush, oSize, oPixmap, oIcon, oFont - - +STATIC oForeColor, oAlphaColor, oBackBrush, oSize, oPixmap, oIcon, oFont + PROCEDURE Main() LOCAL tb1, mo1, lay1, lay2, bt1, bt2, bt3 + LOCAL oWnd, oDA oWnd := QMainWindow() oWnd:resize(600,400 ) @@ -32,17 +30,17 @@ PROCEDURE Main() lay1 := QVBoxLayout( oDA ) /* Here we define some HBQt objects to use in the callback */ - oForeColor := QColor( 0, 50, 100 ) // Solid blue - oAlphaColor := QColor( 255, 0, 0 ) // Transparent Red + oForeColor := QColor( 0, 50, 100 ) // Solid blue + oAlphaColor := QColor( 255, 0, 0 ) // Transparent Red oAlphaColor:setAlpha( 128 ) oBackBrush := QBrush( QColor( 255, 255, 100 ), Qt_BDiagPattern ) // Yellow Diagonal lines - oSize := QSize( 80, 30 ) // Default header sizes - oPixmap := QPixMap( hb_dirBase() + "harbour-icon.png" ) // Image - oIcon := QIcon( oPixMap ) // Icon (reusing the image) - oFont := QFont() // Bold Italic font + oSize := QSize( 80, 30 ) // Default header sizes + oPixmap := QPixMap( hb_dirBase() + "harbour-icon.png" ) // Image + oIcon := QIcon( oPixMap ) // Icon (reusing the image) + + oFont := QFont() // Bold Italic font oFont:setBold( .T. ) oFont:setItalic( .T. ) - /* ------------------------------------------------------- */ tb1 := QTableView()