2012-06-14 14:28 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)

* contrib/hbqt/qtcore/hbqt_hbqslots.cpp
  * contrib/hbqt/qtcore/hbqt_misc.prg
  * contrib/hbqt/qtcore/hbqt_pointer.cpp
  * contrib/hbqt/qtcore/qth/filelist.hbm
  + contrib/hbqt/qtcore/qth/HBQSlots.qth
    ! Reverted: back to the version before Francesco's.
This commit is contained in:
Pritpal Bedi
2012-06-14 21:34:05 +00:00
parent 9645dd42aa
commit 2e649eeba6
6 changed files with 213 additions and 288 deletions

View File

@@ -16,6 +16,14 @@
The license applies to all entries newer than 2009-04-28.
*/
2012-06-14 14:28 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt_hbqslots.cpp
* contrib/hbqt/qtcore/hbqt_misc.prg
* contrib/hbqt/qtcore/hbqt_pointer.cpp
* contrib/hbqt/qtcore/qth/filelist.hbm
+ contrib/hbqt/qtcore/qth/HBQSlots.qth
! Reverted: back to the version before Francesco's.
2012-06-14 09:45 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com)
* contrib/hbqt/qtcore/hbqt_hbqslots.cpp
* contrib/hbqt/qtcore/hbqt_misc.prg

View File

@@ -57,21 +57,21 @@
#include "hbqt.h"
#include "hbapiitm.h"
#include "hbapierr.h"
#include "hbvm.h"
#if QT_VERSION >= 0x040500
#include "hbqt_hbqslots.h"
/*----------------------------------------------------------------------*/
#include <QtCore/QStringList>
/*----------------------------------------------------------------------*/
static QList<QByteArray> s_argCombinations;
static QList<PHBQT_SLOT_FUNC> s_pCallback;
static HBQSlots * receiverSlot = NULL;
void hbqt_slots_register_callback( QByteArray sig, PHBQT_SLOT_FUNC pCallback )
{
HB_TRACE( HB_TR_DEBUG, ( "callback %s", ( char * ) sig.data() ) );
@@ -121,53 +121,56 @@ int HBQSlots::hbConnect( PHB_ITEM pObj, char * pszSignal, PHB_ITEM bBlock )
int nResult = 1;
QObject * object = ( QObject * ) hbqt_get_ptr( pObj );
if( object )
if( true )
{
if( hb_itemType( bBlock ) & HB_IT_BLOCK )
QObject * object = ( QObject * ) hbqt_get_ptr( pObj );
if( object )
{
int i = object->property( pszSignal ).toInt();
if( i == 0 )
if( hb_itemType( bBlock ) & HB_IT_BLOCK )
{
QString signal = pszSignal;
QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() );
if( QMetaObject::checkConnectArgs( theSignal, theSignal ) )
int i = object->property( pszSignal ).toInt();
if( i == 0 )
{
int signalId = object->metaObject()->indexOfSignal( theSignal );
if( signalId != -1 )
{
int slotId = object->metaObject()->indexOfMethod( theSignal );
if( slotId != -1 )
{
if( QMetaObject::connect( object, signalId, this, slotId + QObject::staticMetaObject.methodCount(), Qt::AutoConnection ) )
{
nResult = 0;
QString signal = pszSignal;
QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() );
HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbConnect( %s ) signalId=%i, %p", pszSignal, signalId, object ) );
hbqt_bindAddSlot( pObj, signalId, bBlock );
if( QMetaObject::checkConnectArgs( theSignal, theSignal ) )
{
int signalId = object->metaObject()->indexOfSignal( theSignal );
if( signalId != -1 )
{
int slotId = object->metaObject()->indexOfMethod( theSignal );
if( slotId != -1 )
{
if( QMetaObject::connect( object, signalId, this, slotId + QObject::staticMetaObject.methodCount(), Qt::AutoConnection ) )
{
nResult = 0;
HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbConnect( %s ) signalId=%i, %p", pszSignal, signalId, object ) );
hbqt_bindAddSlot( pObj, signalId, bBlock );
}
else
nResult = 8;
}
else
nResult = 8;
nResult = 7;
}
else
nResult = 7;
nResult = 6;
}
else
nResult = 6;
nResult = 5;
}
else
nResult = 5;
}
else
{
nResult = 3;
}
}
else
{
nResult = 3;
}
nResult = 2;
}
else
nResult = 2;
HB_TRACE( HB_TR_DEBUG, ( "HBQT_SLOTS_CONNECT returns: %d", nResult ) );
return nResult;
}
@@ -188,7 +191,7 @@ int HBQSlots::hbDisconnect( PHB_ITEM pObj, char * pszSignal )
{
if( QMetaObject::disconnect( object, signalId, 0, 0 ) )
{
HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisconnect( %s ) signalId=%d", pszSignal, signalId ) );
HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisconnect( %s ) %i", pszSignal, i ) );
nResult = 0;
}
else
@@ -209,26 +212,12 @@ int HBQSlots::hbDisconnect( PHB_ITEM pObj, char * pszSignal )
return nResult;
}
int HBQSlots::hbDisconnectAll( PHB_ITEM pObj )
{
HB_TRACE( HB_TR_DEBUG, ( "DISCONNECTALL" ) );
QObject * object = ( QObject * ) hbqt_get_ptr( pObj );
if( object )
{
QObject::disconnect();
return HB_TRUE;
}
return HB_FALSE;
}
int HBQSlots::qt_metacall( QMetaObject::Call c, int id, void ** arguments )
{
id = QObject::qt_metacall( c, id, arguments );
if( id < 0 || c != QMetaObject::InvokeMetaMethod )
return id;
HB_TRACE( HB_TR_DEBUG, ( "qt_metacall" ) );
QObject * object = sender();
if( object )
{
@@ -303,173 +292,6 @@ int HBQSlots::qt_metacall( QMetaObject::Call c, int id, void ** arguments )
return -1;
}
int hbqt_QtConnect( QObject *sender, const char * pszSignal, QObject *receiver, const char * pszSlot )
{
HB_TRACE( HB_TR_DEBUG, ( "_Connect %s with slot %s", pszSignal, pszSlot ) );
int nResult = 1;
if( sender && receiver )
{
QString signal = pszSignal;
QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() );
QString slot = pszSlot;
QByteArray theSlot = QMetaObject::normalizedSignature( slot.toAscii() );
if( QMetaObject::checkConnectArgs( theSignal, theSlot ) )
{
int signalId = sender->metaObject()->indexOfSignal( theSignal );
if( signalId != -1 )
{
int slotId = receiver->metaObject()->indexOfMethod( theSlot );
if( slotId != -1 )
{
if( QMetaObject::connect( sender, signalId, receiver, slotId, Qt::AutoConnection ) )
{
nResult = 0;
HB_TRACE( HB_TR_DEBUG, ( "SIGNAL2SLOT ok" ) );
}
else
nResult = 8;
}
else
nResult = 7;
}
else
nResult = 6;
}
else
nResult = 5;
}
else
nResult = 9; // Qt objects not active
HB_TRACE( HB_TR_DEBUG, ( "_Connect returns: %d", nResult ) );
return nResult;
}
int hbqt_QtDisconnect( QObject *sender, const char * pszSignal, QObject *receiver, const char * pszSlot )
{
HB_TRACE( HB_TR_DEBUG, ( "hbqt_QtDisconnect %s with slot %s", pszSignal, pszSlot ) );
int nResult = 1;
if( sender && receiver )
{
QString signal = pszSignal;
QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() );
QString slot = pszSlot;
QByteArray theSlot = QMetaObject::normalizedSignature( slot.toAscii() );
if( QMetaObject::checkConnectArgs( theSignal, theSlot ) )
{
int signalId = sender->metaObject()->indexOfSignal( theSignal );
if( signalId != -1 )
{
int slotId = receiver->metaObject()->indexOfMethod( theSlot );
if( slotId != -1 )
{
if( QMetaObject::disconnect( sender, signalId, receiver, slotId ) )
{
nResult = 0;
HB_TRACE( HB_TR_DEBUG, ( "SIGNAL2SLOT ok" ) );
}
else
nResult = 8;
}
else
nResult = 7;
}
else
nResult = 6;
}
else
nResult = 5;
}
else
nResult = 9; // Qt objects not active
HB_TRACE( HB_TR_DEBUG, ( "hbqt_QtDisconnect returns: %d", nResult ) );
return nResult;
}
/* HBQT_CONNECT handles now two types of connection, one Qt based, one HB based:
Qt: HBQT_CONNECT( object, signal, object, string )
HB: HBQT_CONNECT( object, signal, codeblock )
*/
HB_FUNC( HBQT_CONNECT )
{
int ret = -1;
if( hb_pcount() == 4 && HB_ISCHAR( 2 ) && HB_ISCHAR( 4 ) && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) && hbqt_par_isDerivedFrom( 3, "QOBJECT" ) )
{
void * pText01 = NULL;
void * pText02 = NULL;
ret = hbqt_QtConnect( ( QObject* ) hbqt_par_ptr( 1 ), hb_parstr_utf8( 2, &pText01, NULL ), ( QObject* ) hbqt_par_ptr( 3 ), hb_parstr_utf8( 4, &pText02, NULL ) );
hb_strfree( pText01 );
hb_strfree( pText02 );
}
else if( hb_pcount() == 3 && HB_ISCHAR( 2 ) && HB_ISBLOCK( 3 ) && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) )
{
void * pText01 = NULL;
ret = receiverSlot->hbConnect( hb_param( 1, HB_IT_OBJECT ), ( char * ) hb_parstr_utf8( 2, &pText01, NULL ), hb_param( 3, HB_IT_BLOCK ) );
hb_strfree( pText01 );
}
else
{
hb_errRT_BASE( EG_ARG, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
hb_retni( ret );
}
HB_FUNC( HBQT_DISCONNECT )
{
int ret = -1;
if( hb_pcount() == 2 && HB_ISCHAR( 2 ) && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) )
{
void * pText01 = NULL;
ret = receiverSlot->hbDisconnect( hb_param( 1, HB_IT_OBJECT ), (char *) hb_parstr_utf8( 2, &pText01, NULL ) ) == 0;
hb_strfree( pText01 );
}
else
{
hb_errRT_BASE( EG_ARG, 9999, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
}
hb_retni( ret );
}
static void hbqt_lib_init( void * cargo )
{
HB_SYMBOL_UNUSED( cargo );
HB_TRACE( HB_TR_DEBUG, ( "Slots: hbqt_lib_init" ) );
if( receiverSlot == NULL )
receiverSlot = new HBQSlots;
HB_TRACE( HB_TR_DEBUG, ( "Slots: hbqt_lib_init" ) );
}
static void hbqt_lib_exit( void* cargo )
{
HB_SYMBOL_UNUSED( cargo );
HB_TRACE( HB_TR_DEBUG, ( "Exiting slots lib" ) );
if( receiverSlot )
delete receiverSlot;
}
HB_CALL_ON_STARTUP_BEGIN( _hbqtslots_init_ )
hb_vmAtInit( hbqt_lib_init, NULL );
hb_vmAtExit( hbqt_lib_exit, NULL );
HB_CALL_ON_STARTUP_END( _hbqtslots_init_ )
#if defined( HB_PRAGMA_STARTUP )
#pragma startup _hbqtslots_init_
#elif defined( HB_DATASEG_STARTUP )
#define HB_DATASEG_BODY HB_DATASEG_FUNC( _hbqtslots_init_ )
#include "hbiniseg.h"
#endif
/*----------------------------------------------------------------------*/
#endif

View File

@@ -58,25 +58,24 @@
CREATE CLASS HbQtObjectHandler
/* __pSlots removed */
/* QUESTION: _three_ different lists for events? two for slots? Is this needed? */
/* ANSWER : these variables hold the objects which capture and fire the relative signal/event */
/* __pEvents is used for event handling */
VAR __pSlots PROTECTED
VAR __pEvents PROTECTED
VAR __hEvents PROTECTED INIT { => }
/* The following two variables are PUBLIC */
VAR __Slots
VAR __Events
VAR __Slots /* TOFIX: add PROTECTED or clean this mess ANS: It is like this by design, cannot be made PROTECTED */
VAR __Events /* TOFIX: add PROTECTED or clean this mess */
METHOD connect( cnEvent, bBlock )
METHOD disconnect( cnEvent )
METHOD disconnectAll()
METHOD setSlots()
METHOD setEvents()
DESTRUCTOR __destroy()
ERROR HANDLER onError( cMsg )
ERROR HANDLER onError()
ENDCLASS
@@ -104,14 +103,10 @@ METHOD HbQtObjectHandler:setEvents()
/*----------------------------------------------------------------------*/
METHOD HbQtObjectHandler:onError( cMsg )
METHOD HbQtObjectHandler:onError()
LOCAL cMsg := __GetMessage()
LOCAL oError
LOCAL nCallStack := 1
IF ! hb_isChar( cMsg )
cMsg := __GetMessage()
nCallStack := 0
ENDIF
IF SubStr( cMsg, 1, 1 ) == "_"
cMsg := SubStr( cMsg, 2 )
ENDIF
@@ -126,7 +121,7 @@ METHOD HbQtObjectHandler:onError( cMsg )
oError:canRetry := .F.
oError:canDefault := .F.
oError:Args := hb_AParams()
oError:operation := ProcName( nCallStack )
oError:operation := ProcName()
oError:Description := cMsg
Eval( ErrorBlock(), oError )
@@ -139,7 +134,6 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock )
LOCAL nResult
IF ! __objDerivedFrom( Self, "QOBJECT" )
HB_TRACE( HB_TR_DEBUG, "REFUSED CONNECT ", Self:className() )
RETURN .f.
ENDIF
@@ -151,14 +145,18 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock )
IF HB_ISNUMERIC( ::__hEvents[ cnEvent ] )
::__pEvents:hbDisconnect( Self, cnEvent )
ELSE
hbqt_disconnect( Self, cnEvent )
::__pSlots:hbDisconnect( Self, cnEvent )
ENDIF
hb_hDel( ::__hEvents, cnEvent )
ENDIF
SWITCH ValType( cnEvent )
CASE "C"
nResult := hbqt_connect( Self, cnEvent, bBlock )
IF Empty( ::__pSlots )
::__pSlots := HBQSlots()
ENDIF
nResult := ::__pSlots:hbconnect( Self, cnEvent, bBlock )
SWITCH nResult
CASE 0
::__hEvents[ cnEvent ] := cnEvent
@@ -173,7 +171,6 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock )
::__pEvents := HBQEvents()
::__pEvents:hbInstallEventFilter( Self )
ENDIF
HB_TRACE( HB_TR_DEBUG, " _HbQtObjectHandler:connect valtype __pEvents object=", Self:className() )
nResult := ::__pEvents:hbConnect( Self, cnEvent, bBlock )
SWITCH nResult
@@ -190,72 +187,62 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock )
ENDSWITCH
HB_TRACE( HB_TR_DEBUG, "Errore in connect " + hb_ntos( nResult ) )
__hbqt_error( 1200 + nResult )
RETURN .F.
/*----------------------------------------------------------------------*/
METHOD HbQtObjectHandler:disconnectAll()
RETURN .T.
/*----------------------------------------------------------------------*/
METHOD HbQtObjectHandler:disconnect( cnEvent )
LOCAL nResult := 0
IF ! __objDerivedFrom( Self, "QOBJECT" )
RETURN .F.
RETURN .f.
ENDIF
IF ! hb_hHasKey( ::__hEvents, cnEvent )
RETURN .f.
ENDIF
IF PCOUNT() == 0
// ::disconnectAll()
RETURN .T.
ELSE
SWITCH ValType( cnEvent )
CASE "C"
nResult := hbqt_disconnect( Self, cnEvent )
SWITCH ValType( cnEvent )
CASE "C"
IF ! empty( ::__pSlots )
nResult := ::__pSlots:hbDisconnect( Self, cnEvent )
ENDIF
SWITCH nResult
CASE 0
CASE 4 /* signal not found in object */
CASE 5 /* disconnect failure */
SWITCH nResult
CASE 0
CASE 4 /* signal not found in object */
CASE 5 /* disconnect failure */
hb_hDel( ::__hEvents, cnEvent )
RETURN .T.
CASE 1 /* wrong slot container, no connect was called yet */
CASE 2 /* object has been already freed */
CASE 3 /* event not found */
RETURN .F.
ENDSWITCH
EXIT
CASE "N"
IF ! empty( ::__pEvents )
nResult := ::__pEvents:hbdisconnect( Self, cnEvent )
ENDIF
SWITCH nResult
CASE 0
hb_hDel( ::__hEvents, cnEvent )
RETURN .T.
CASE -3 /* event not found */
CASE -2 /* event not found */
CASE -1 /* event not found */
RETURN .F.
ENDSWITCH
EXIT
OTHERWISE
nResult := 99
RETURN .T.
CASE 1 /* wrong slot container, no connect was called yet */
CASE 2 /* object has been already freed */
CASE 3 /* event not found */
RETURN .F.
ENDSWITCH
ENDIF
HB_TRACE( HB_TR_DEBUG, "Errore in disconnect nResult="+str(nResult) )
EXIT
CASE "N"
IF ! empty( ::__pEvents )
nResult := ::__pEvents:hbdisconnect( Self, cnEvent )
ENDIF
SWITCH nResult
CASE 0
hb_hDel( ::__hEvents, cnEvent )
RETURN .T.
CASE -3 /* event not found */
CASE -2 /* event not found */
CASE -1 /* event not found */
RETURN .F.
ENDSWITCH
EXIT
OTHERWISE
nResult := 99
ENDSWITCH
__hbqt_error( 1300 + nResult )
RETURN .F.
@@ -263,7 +250,7 @@ METHOD HbQtObjectHandler:disconnect( cnEvent )
METHOD HbQtObjectHandler:__destroy()
HB_TRACE( HB_TR_DEBUG, " _destroy()", __objDerivedFrom( Self, "QOBJECT" ), __objGetClsName( Self ) )
HB_TRACE( HB_TR_DEBUG, " __destroy()", __objDerivedFrom( Self, "QOBJECT" ), __objGetClsName( Self ) )
__hbqt_destroy( Self )

View File

@@ -241,13 +241,67 @@ HB_BOOL hbqt_par_isDerivedFrom( int iParam, const char * pszClsName )
return HB_FALSE;
}
HB_FUNC( HBQT_REALCLASS )
int hbqt_QtConnect( QObject *sender, const char * pszSignal, QObject *receiver, const char * pszSlot )
{
void * oObject;
HB_TRACE( HB_TR_DEBUG, ( "_Connect %s with slot %s", pszSignal, pszSlot ) );
oObject = hbqt_par_ptr( 1 );
int nResult = 1;
hb_retc( ( ( QObject * ) oObject )->metaObject()->className() ) ;
if( sender && receiver )
{
QString signal = pszSignal;
QByteArray theSignal = QMetaObject::normalizedSignature( signal.toAscii() );
QString slot = pszSlot;
QByteArray theSlot = QMetaObject::normalizedSignature( slot.toAscii() );
if( QMetaObject::checkConnectArgs( theSignal, theSlot ) )
{
int signalId = sender->metaObject()->indexOfSignal( theSignal );
if( signalId != -1 )
{
int slotId = receiver->metaObject()->indexOfMethod( theSlot );
if( slotId != -1 )
{
if( QMetaObject::connect( sender, signalId, receiver, slotId, Qt::AutoConnection ) )
{
nResult = 0;
HB_TRACE( HB_TR_DEBUG, ( "SIGNAL2SLOT ok" ) );
}
else
nResult = 8;
}
else
nResult = 7;
}
else
nResult = 6;
}
else
nResult = 5;
}
else
nResult = 9; // Qt objects not active
HB_TRACE( HB_TR_DEBUG, ( "_Connect returns: %d", nResult ) );
return nResult;
}
HB_FUNC( HBQT_CONNECT )
{
HB_BOOL ret = HB_FALSE;
if( hb_pcount() == 4 && HB_ISCHAR( 2 ) && HB_ISCHAR( 4 ) && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) && hbqt_par_isDerivedFrom( 3, "QOBJECT" ) )
{
void * pText01 = NULL;
void * pText02 = NULL;
if( hbqt_QtConnect( ( QObject* ) hbqt_par_ptr( 1 ), hb_parstr_utf8( 2, &pText01, NULL ), ( QObject* ) hbqt_par_ptr( 3 ), hb_parstr_utf8( 4, &pText02, NULL ) ) == 0 )
{
ret = HB_TRUE;
}
hb_strfree( pText01 );
hb_strfree( pText02 );
}
hb_retl( ret );
}
/*----------------------------------------------------------------------*/

View File

@@ -0,0 +1,53 @@
/*
* $Id$
*/
/*
* Harbour Qt wrapper generator control file
*
* Copyright 2009-2012 Pritpal Bedi <bedipritpal@hotmail.com>
* www - http://www.harbour-project.org
*
* See COPYING for licensing terms.
*/
<CLASS>
QObject =
Inherit = QObject
Type =
New =
</CLASS>
<SUBCLASS>
</SUBCLASS>
<DOC>
</DOC>
<CODE>
#include <QtCore/QObject>
#include "hbqt_hbqslots.h"
/*
* HBQSlots ()
* ~HBQSlots ()
*/
HB_FUNC( QT_HBQSLOTS )
{
__HB_RETPTRGC__( new HBQSlots() );
}
</CODE>
<ENUMS>
</ENUMS>
<PROTOS>
int hbConnect( PHB_ITEM obj, char * event, PHB_ITEM block )
int hbDisconnect( PHB_ITEM obj, char * event )
</PROTOS>
<SLOTS>
</SLOTS>
<SIGNALS>
</SIGNALS>

View File

@@ -7,6 +7,7 @@
-pflag=-qthdocdir=../doc/
HBQEvents.qth
HBQSlots.qth
HBQString.qth
# QAbstractEventDispatcher.qth