From c3198f612855f8a48a8898e89293e87740c54539 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Wed, 13 Jun 2012 21:09:44 +0000 Subject: [PATCH] 2012-06-13 13:59 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) - contrib/hbqt/qtcore/hbqt_obj.prg - Deleted: hbQT already has a super class HBQTOBJECTHANDELLER and concerned protocol is embedded into that. * contrib/hbqt/qtcore/hbqt_hbqevents.cpp * contrib/hbqt/qtcore/hbqt_hbqevents.h ! Changed: constructor without a parent. In certain situations under current protocol, this had a overhead where destructor on this object was not being called at appropriate time. * contrib/hbqt/qtcore/hbqt_hbqslots.cpp * contrib/hbqt/qtcore/hbqt_hbqslots.h ! Formatting. * contrib/hbqt/qtcore/hbqt_misc.prg * contrib/hbqt/qtcore/hbqtcore.hbm * contrib/hbqt/qtcore/hbqtcore.hbx - Deleted: hbqt_obj.prg * contrib/hbqt/qtcore/qth/HBQEvents.qth - Deleted: un-used variables. --- harbour/ChangeLog | 25 +++ .../contrib/hbqt/qtcore/hbqt_hbqevents.cpp | 18 ++- harbour/contrib/hbqt/qtcore/hbqt_hbqevents.h | 4 +- harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp | 150 +++++++++--------- harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h | 1 - harbour/contrib/hbqt/qtcore/hbqt_misc.prg | 39 ++--- harbour/contrib/hbqt/qtcore/hbqt_obj.prg | 66 -------- harbour/contrib/hbqt/qtcore/hbqtcore.hbm | 1 - harbour/contrib/hbqt/qtcore/hbqtcore.hbx | 3 - harbour/contrib/hbqt/qtcore/qth/HBQEvents.qth | 10 +- 10 files changed, 131 insertions(+), 186 deletions(-) delete mode 100644 harbour/contrib/hbqt/qtcore/hbqt_obj.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b9ee6a2dbd..b5ef885dc5 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,31 @@ The license applies to all entries newer than 2009-04-28. */ +2012-06-13 13:59 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + - contrib/hbqt/qtcore/hbqt_obj.prg + - Deleted: hbQT already has a super class HBQTOBJECTHANDELLER + and concerned protocol is embedded into that. + + * contrib/hbqt/qtcore/hbqt_hbqevents.cpp + * contrib/hbqt/qtcore/hbqt_hbqevents.h + ! Changed: constructor without a parent. + In certain situations under current protocol, this had + a overhead where destructor on this object was not being + called at appropriate time. + + * contrib/hbqt/qtcore/hbqt_hbqslots.cpp + * contrib/hbqt/qtcore/hbqt_hbqslots.h + ! Formatting. + + * contrib/hbqt/qtcore/hbqt_misc.prg + + * contrib/hbqt/qtcore/hbqtcore.hbm + * contrib/hbqt/qtcore/hbqtcore.hbx + - Deleted: hbqt_obj.prg + + * contrib/hbqt/qtcore/qth/HBQEvents.qth + - Deleted: un-used variables. + 2012-06-13 22:55 UTC+0200 Viktor Szakats (harbour syenar.net) - contrib/hbamf/hbref.c * contrib/hbamf/amfdec.c diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp index 6e81fa0a52..b3cda455da 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.cpp @@ -107,18 +107,26 @@ void hbqt_events_unregister_createobj( QEvent::Type eventtype ) /*----------------------------------------------------------------------*/ -HBQEvents::HBQEvents( QObject * object ) : QObject() +HBQEvents::HBQEvents() : QObject() { - if( object ) - { - object->installEventFilter( this ); - } } HBQEvents::~HBQEvents() { } +void HBQEvents::hbInstallEventFilter( PHB_ITEM pObj ) +{ + if( hb_itemType( pObj ) & HB_IT_OBJECT ) + { + QObject * object = ( QObject * ) hbqt_get_ptr( pObj ); + if( object ) + { + object->installEventFilter( this ); + } + } +} + int HBQEvents::hbConnect( PHB_ITEM pObj, int event, PHB_ITEM bBlock ) { HB_TRACE( HB_TR_DEBUG, ( "HBQEvents::hbConnect( %i )", event ) ); diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.h b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.h index 23add62b63..8e5cb8489c 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.h +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqevents.h @@ -68,12 +68,12 @@ class HBQEvents: public QObject Q_OBJECT public: - HBQEvents( QObject * parent = 0 ); + HBQEvents(); ~HBQEvents(); - QList listBlock; int hbConnect( PHB_ITEM pObj, int iEvent, PHB_ITEM bBlock ); int hbDisconnect( PHB_ITEM pObj, int iEvent ); + void hbInstallEventFilter( PHB_ITEM pObj ); protected: bool eventFilter( QObject * obj, QEvent * event ); diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp index e97e43c7bb..2031084ff1 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp @@ -106,14 +106,13 @@ void hbqt_slots_unregister_callback( QByteArray sig ) /*----------------------------------------------------------------------*/ -// HBQSlots::HBQSlots( PHB_ITEM pObj ) : QObject() HBQSlots::HBQSlots() : QObject() { } HBQSlots::~HBQSlots() { - HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::~HBQSlots()" ) ); + HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::~HBQSlots()" ) ); } int HBQSlots::hbConnect( PHB_ITEM pObj, char * pszSignal, PHB_ITEM bBlock ) @@ -184,29 +183,28 @@ int HBQSlots::hbDisconnect( PHB_ITEM pObj, char * pszSignal ) QObject * object = ( QObject * ) hbqt_get_ptr( pObj ); if( object ) { + QString signal = pszSignal; + QByteArray theSignal = signal.toAscii(); - QString signal = pszSignal; - QByteArray theSignal = signal.toAscii(); - - int signalId = object->metaObject()->indexOfSignal( QMetaObject::normalizedSignature( theSignal ) ); - if( signalId != -1 ) + int signalId = object->metaObject()->indexOfSignal( QMetaObject::normalizedSignature( theSignal ) ); + if( signalId != -1 ) + { + if( QMetaObject::disconnect( object, signalId, 0, 0 ) ) { - if( QMetaObject::disconnect( object, signalId, 0, 0 ) ) - { - HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisconnect( %s ) %i", pszSignal, i ) ); - nResult = 0; - } - else - nResult = 5; + HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisconnect( %s ) %i", pszSignal, i ) ); + nResult = 0; } else - nResult = 4; + nResult = 5; + } + else + nResult = 4; - if( nResult == 0 ) - { - HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisConnect( %s ) signalId=%i, %p", pszSignal, signalId, object ) ); - hbqt_bindDelSlot( pObj, signalId, NULL ); - } + if( nResult == 0 ) + { + HB_TRACE( HB_TR_DEBUG, ( "HBQSlots::hbDisConnect( %s ) signalId=%i, %p", pszSignal, signalId, object ) ); + hbqt_bindDelSlot( pObj, signalId, NULL ); + } } else nResult = 2; @@ -223,73 +221,73 @@ int HBQSlots::qt_metacall( QMetaObject::Call c, int id, void ** arguments ) QObject * object = sender(); if( object ) { - QByteArray paramString; - const QMetaMethod meta = object->metaObject()->method( id ); - QList arrayOfTypes = meta.parameterTypes(); - int parameterCount = arrayOfTypes.size(); - QStringList pList; + QByteArray paramString; + const QMetaMethod meta = object->metaObject()->method( id ); + QList arrayOfTypes = meta.parameterTypes(); + int parameterCount = arrayOfTypes.size(); + QStringList pList; - if( parameterCount > 0 ) + if( parameterCount > 0 ) + { + char szParams[ 20 ]; + hb_snprintf( szParams, sizeof( szParams ), "PARAM_%d", id ); + paramString = object->property( szParams ).toByteArray(); + + char szPList[ 20 ]; + hb_snprintf( szPList, sizeof( szPList ), "PLIST_%d", id ); + pList = object->property( szPList ).toStringList(); + + if( paramString.isNull() ) { - char szParams[ 20 ]; - hb_snprintf( szParams, sizeof( szParams ), "PARAM_%d", id ); - paramString = object->property( szParams ).toByteArray(); + QStringList parList; + HB_TRACE( HB_TR_DEBUG, ( "SlotsProxy signature %s", meta.signature() ) ); - char szPList[ 20 ]; - hb_snprintf( szPList, sizeof( szPList ), "PLIST_%d", id ); - pList = object->property( szPList ).toStringList(); - - if( paramString.isNull() ) + for( int i = 0; i < parameterCount; i++ ) { - QStringList parList; - HB_TRACE( HB_TR_DEBUG, ( "SlotsProxy signature %s", meta.signature() ) ); - - for( int i = 0; i < parameterCount; i++ ) + if( arrayOfTypes.at( i ).contains( "::" ) ) { - if( arrayOfTypes.at( i ).contains( "::" ) ) - { - parList += "int"; - pList += "int"; - } - else - { - parList += arrayOfTypes.at( i ).trimmed() ; - pList += arrayOfTypes.at( i ).trimmed().toUpper(); - } - } - paramString = parList.join( "$" ).toAscii(); - object->setProperty( szParams, paramString ); - - object->setProperty( szPList, pList ); - - HB_TRACE( HB_TR_DEBUG, ( " SlotsProxy parList %s ", ( char * ) paramString.data() ) ); - } - } - - if( hb_vmRequestReenter() ) - { - PHB_ITEM hbObject = hbqt_bindGetHbObjectByQtObject( object ); - PHB_ITEM p = hbqt_bindGetSlots( hbObject, id ); - hb_itemRelease( hbObject ); - if( p ) - { - if( parameterCount == 0 ) - { - hb_evalBlock0( hb_arrayGetItemPtr( p, 1 ) ); + parList += "int"; + pList += "int"; } else { - int paramId = s_argCombinations.indexOf( paramString ); - PHBQT_SLOT_FUNC pCallback = s_pCallback.at( paramId ); - if( pCallback ) - { - pCallback( ( PHB_ITEM * ) hb_arrayGetItemPtr( p, 1 ), arguments, pList ); - } + parList += arrayOfTypes.at( i ).trimmed() ; + pList += arrayOfTypes.at( i ).trimmed().toUpper(); } - hb_itemRelease( p ); } - hb_vmRequestRestore(); + paramString = parList.join( "$" ).toAscii(); + object->setProperty( szParams, paramString ); + + object->setProperty( szPList, pList ); + + HB_TRACE( HB_TR_DEBUG, ( " SlotsProxy parList %s ", ( char * ) paramString.data() ) ); } + } + + if( hb_vmRequestReenter() ) + { + PHB_ITEM hbObject = hbqt_bindGetHbObjectByQtObject( object ); + PHB_ITEM p = hbqt_bindGetSlots( hbObject, id ); + hb_itemRelease( hbObject ); + if( p ) + { + if( parameterCount == 0 ) + { + hb_evalBlock0( hb_arrayGetItemPtr( p, 1 ) ); + } + else + { + int paramId = s_argCombinations.indexOf( paramString ); + PHBQT_SLOT_FUNC pCallback = s_pCallback.at( paramId ); + if( pCallback ) + { + pCallback( ( PHB_ITEM * ) hb_arrayGetItemPtr( p, 1 ), arguments, pList ); + } + } + hb_itemRelease( p ); + } + hb_vmRequestRestore(); + } } return -1; } diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h index 61012d990f..a6ee711346 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h @@ -73,7 +73,6 @@ public: HBQSlots( ); ~HBQSlots(); - QList listBlock; int hbConnect( PHB_ITEM obj, char * pszSignal, PHB_ITEM block ); int hbDisconnect( PHB_ITEM obj, char * pszSignal ); diff --git a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg index b86ee68b63..b892e9bb7e 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_misc.prg +++ b/harbour/contrib/hbqt/qtcore/hbqt_misc.prg @@ -54,20 +54,19 @@ #include "error.ch" #include "hbtrace.ch" -#define QEvent_Paint 12 - /*----------------------------------------------------------------------*/ CREATE CLASS HbQtObjectHandler /* 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 */ VAR __pSlots PROTECTED VAR __pEvents PROTECTED VAR __hEvents PROTECTED INIT { => } - VAR __Slots /* TOFIX: add PROTECTED or clean this mess */ + 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 ) @@ -154,7 +153,7 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock ) SWITCH ValType( cnEvent ) CASE "C" IF Empty( ::__pSlots ) - ::__pSlots := HBQSlots( Self ) + ::__pSlots := HBQSlots() ENDIF nResult := ::__pSlots:hbconnect( Self, cnEvent, bBlock ) @@ -168,27 +167,19 @@ METHOD HbQtObjectHandler:connect( cnEvent, bBlock ) EXIT CASE "N" - IF cnEvent == QEvent_Paint - IF __objHasMethod( Self, "HBSETEVENTBLOCK" ) - ::hbSetEventBlock( QEvent_Paint, bBlock ) - RETURN .T. - ELSE - RETURN .F. - ENDIF - ELSE - IF Empty( ::__pEvents ) - ::__pEvents := HBQEvents( Self ) - ENDIF - nResult := ::__pEvents:hbConnect( Self, cnEvent, bBlock ) - - SWITCH nResult - CASE 0 - ::__hEvents[ cnEvent ] := cnEvent - RETURN .T. - CASE -3 /* bBlock not supplied */ - RETURN .F. - ENDSWITCH + IF Empty( ::__pEvents ) + ::__pEvents := HBQEvents() + ::__pEvents:hbInstallEventFilter( Self ) ENDIF + nResult := ::__pEvents:hbConnect( Self, cnEvent, bBlock ) + + SWITCH nResult + CASE 0 + ::__hEvents[ cnEvent ] := cnEvent + RETURN .T. + CASE -3 /* bBlock not supplied */ + RETURN .F. + ENDSWITCH EXIT OTHERWISE diff --git a/harbour/contrib/hbqt/qtcore/hbqt_obj.prg b/harbour/contrib/hbqt/qtcore/hbqt_obj.prg deleted file mode 100644 index e714a87558..0000000000 --- a/harbour/contrib/hbqt/qtcore/hbqt_obj.prg +++ /dev/null @@ -1,66 +0,0 @@ -/* - * $Id$ - */ - -/* - * Harbour Project source code: - * QT wrapper source code - * - * Copyright 2012 Przemyslaw Czerpak (druzus/at/poczta.onet.pl) - * www - http://harbour-project.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this software; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, - * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). - * - * As a special exception, the Harbour Project gives permission for - * additional uses of the text contained in its release of Harbour. - * - * The exception is that, if you link the Harbour libraries with other - * files to produce an executable, this does not by itself cause the - * resulting executable to be covered by the GNU General Public License. - * Your use of that executable is in no way restricted on account of - * linking the Harbour library code into it. - * - * This exception does not however invalidate any other reasons why - * the executable file might be covered by the GNU General Public License. - * - * This exception applies only to the code released by the Harbour - * Project under the name Harbour. If you copy code from other - * Harbour Project or Free Software Foundation releases into a copy of - * Harbour, as the General Public License permits, the exception does - * not apply to the code that you add in this way. To avoid misleading - * anyone as to the status of such modified files, you must delete - * this exception notice from them. - * - * If you write modifications of your own for Harbour, it is your choice - * whether to permit this exception to apply to your modifications. - * If you do not wish that, delete this exception notice. - * - */ -/*----------------------------------------------------------------------*/ - -#include "hbclass.ch" - -CREATE CLASS HBQT_BASEOBJECT - VAR __Childs INIT {} - VAR __Slots - METHOD Init() -ENDCLASS - -METHOD Init() - ::__Slots := {=>} - hb_HDefault( ::__Slots, {} ) -RETURN Self - diff --git a/harbour/contrib/hbqt/qtcore/hbqtcore.hbm b/harbour/contrib/hbqt/qtcore/hbqtcore.hbm index 24d8ca246a..e2f7b785e3 100644 --- a/harbour/contrib/hbqt/qtcore/hbqtcore.hbm +++ b/harbour/contrib/hbqt/qtcore/hbqtcore.hbm @@ -20,7 +20,6 @@ hbqt_bind.cpp hbqt_destroyer.cpp hbqt_misc.prg -hbqt_obj.prg hbqt_hbqevents.h hbqt_destroyer.h diff --git a/harbour/contrib/hbqt/qtcore/hbqtcore.hbx b/harbour/contrib/hbqt/qtcore/hbqtcore.hbx index 94e5f52a75..07c30770f8 100644 --- a/harbour/contrib/hbqt/qtcore/hbqtcore.hbx +++ b/harbour/contrib/hbqt/qtcore/hbqtcore.hbx @@ -29,11 +29,8 @@ DYNAMIC HBQEVENTS DYNAMIC HBQSLOTS DYNAMIC HBQSTRING DYNAMIC HBQTOBJECTHANDLER -DYNAMIC HBQT_BASEOBJECT DYNAMIC HBQT_CONNECT DYNAMIC HBQT_ISEQUAL -DYNAMIC HBQT_ISOBJECT -DYNAMIC HBQT_PROMOTEWIDGET DYNAMIC HB_HBQEVENTS DYNAMIC HB_HBQSLOTS DYNAMIC HB_HBQSTRING diff --git a/harbour/contrib/hbqt/qtcore/qth/HBQEvents.qth b/harbour/contrib/hbqt/qtcore/qth/HBQEvents.qth index 10dabcf918..6c42e8861e 100644 --- a/harbour/contrib/hbqt/qtcore/qth/HBQEvents.qth +++ b/harbour/contrib/hbqt/qtcore/qth/HBQEvents.qth @@ -36,14 +36,7 @@ New = */ HB_FUNC( QT_HBQEVENTS ) { - if( hb_pcount() == 1 && hbqt_par_isDerivedFrom( 1, "QOBJECT" ) ) - { - __HB_RETPTRGC__( new HBQEvents( hbqt_par_QObject( 1 ) ) ); - } - else - { - __HB_RETPTRGC__( new HBQEvents() ); - } + __HB_RETPTRGC__( new HBQEvents() ); } @@ -54,6 +47,7 @@ HB_FUNC( QT_HBQEVENTS ) int hbConnect( PHB_ITEM obj, int event, PHB_ITEM block ) int hbDisconnect( PHB_ITEM obj, int event ) +void hbInstallEventFilter( PHB_ITEM obj )