From 339e9685583cdcdc4ca42dd3b90d3f5661d3766f Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Mon, 4 Oct 2010 16:21:49 +0000 Subject: [PATCH] 2010-10-04 08:57 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbxbp/xbplistbox.prg ! Changed: the way context menu was being fired. * contrib/hbqt/qtcore/hbqt_hbqslots.cpp * contrib/hbqt/qtcore/hbqt_hbqslots.h + Added: Francesco Perillo's new SIGNAL/SLOT mechanism. It is guarded against #ifdef __PRITPAL__ which is defined by default in hbqt_hbqslots.h. To switch over to new mechanism, simply comment out #define __PRITPAL__ and recompile hbQT. Once all slots will be working, sections covered under __PRITPAL__ will be removed. This way we can test new protocol whosoever wants to investigate insides. --- harbour/ChangeLog | 15 + harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp | 694 +++++++++++++++++- harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h | 25 + harbour/contrib/hbxbp/xbplistbox.prg | 47 +- 4 files changed, 766 insertions(+), 15 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 628c05fad5..ce2da7e799 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2010-10-04 08:57 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbxbp/xbplistbox.prg + ! Changed: the way context menu was being fired. + + * contrib/hbqt/qtcore/hbqt_hbqslots.cpp + * contrib/hbqt/qtcore/hbqt_hbqslots.h + + Added: Francesco Perillo's new SIGNAL/SLOT mechanism. + It is guarded against #ifdef __PRITPAL__ which is defined + by default in hbqt_hbqslots.h. To switch over to new + mechanism, simply comment out #define __PRITPAL__ and + recompile hbQT. Once all slots will be working, sections + covered under __PRITPAL__ will be removed. This way + we can test new protocol whosoever wants to investigate + insides. + 2010-10-04 13:22 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/fstemp.c * disabled using tmpnam() in OS2 builds diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp index 2a2be28fbc..62484e02ca 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.cpp @@ -58,6 +58,7 @@ #include "hbapiitm.h" #include "hbstack.h" #include "hbvm.h" +#include "hbapierr.h" #if QT_VERSION >= 0x040500 @@ -66,6 +67,7 @@ #include /*----------------------------------------------------------------------*/ +#ifdef __PRITPAL__ static bool connect_signal( QString signal, QObject * object, HBQSlots * t_slots ) { @@ -238,7 +240,7 @@ static bool connect_signal( QString signal, QObject * object, HBQSlots * t_slots if( signal == ( QString ) "subWindowActivated(QMdiSubWindow)" ) return object->connect( object, SIGNAL( subWindowActivated( QMdiSubWindow * ) ), t_slots, SLOT( subWindowActivated( QMdiSubWindow * ) ), Qt::AutoConnection ); /* QMdiSubWindow */ if( signal == ( QString ) "aboutToActivate()" ) return object->connect( object, SIGNAL( aboutToActivate() ), t_slots, SLOT( aboutToActivate() ), Qt::AutoConnection ); - if( signal == ( QString ) "windowStateChanged(Qt::WindowStates,Qt::WindowStates)" ) return object->connect( object, SIGNAL( windowStateChanged( Qt::WindowStates, Qt::WindowStates ) ), t_slots, SLOT( windowStateChanged( Qt::WindowStates, Qt::WindowStates ) ), Qt::AutoConnection ); + if( signal == ( QString ) "windowStateChanged(Qt::WindowStates,Qt::WindowStates)" ) return object->connect( object, SIGNAL( windowStateChanged( Qt::WindowStates, Qt::WindowStates ) ), t_slots, SLOT( windowStateChanged( int, int ) ), Qt::AutoConnection ); /* QAbstractItemDelegate */ if( signal == ( QString ) "closeEditor(QWidget,int)" ) return object->connect( object, SIGNAL( closeEditor( QWidget *, QAbstractItemDelegate::EndEditHint ) ), t_slots, SLOT( closeEditor( QWidget *, QAbstractItemDelegate::EndEditHint ) ), Qt::AutoConnection ); if( signal == ( QString ) "commitData(QWidget)" ) return object->connect( object, SIGNAL( commitData( QWidget * ) ), t_slots, SLOT( commitData( QWidget * ) ), Qt::AutoConnection ); @@ -1237,4 +1239,694 @@ HB_FUNC( QT_SLOTS_NEW ) hb_retptrGC( hbqt_gcAllocate_HBQSlots( pObj, true ) ); } +/*----------------------------------------------------------------------*/ +#else //__PRITPAL__ +/*----------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +static void hbqt_SlotsExecBool( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutL( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 1 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 1 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecIntInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 1 ] ) ) ); + PHB_ITEM p2 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 2 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 2, p1, p2 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); +} + +static void hbqt_SlotsExecIntIntInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 1 ] ) ) ); + PHB_ITEM p2 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 2 ] ) ) ); + PHB_ITEM p3 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 3 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 3, p1, p2, p3 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); + hb_itemRelease( p3 ); +} + +static void hbqt_SlotsExecIntIntIntInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 1 ] ) ) ); + PHB_ITEM p2 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 2 ] ) ) ); + PHB_ITEM p3 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 3 ] ) ) ); + PHB_ITEM p4 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 4 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 4, p1, p2, p3, p4 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); + hb_itemRelease( p3 ); + hb_itemRelease( p4 ); +} + +static void hbqt_SlotsExecQRectInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QRect( (*reinterpret_cast< QRect(*)>(arguments[1])) ) ); + PHB_ITEM p2 = hb_itemPutNI( NULL, (*reinterpret_cast< int(*)>(arguments[2])) ); + hb_vmEvalBlockV( codeBlock, 2, p1, p2 ); + delete ( ( QRect * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); +} + +static void hbqt_SlotsExecString( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM pString = hb_itemPutC( NULL, ( *reinterpret_cast< QString(*)>(arguments[1])).toAscii().data() ); + hb_vmEvalBlockV( codeBlock, 1, pString ); + hb_itemRelease( pString ); +} + +#include + +static void hbqt_SlotsExecModel( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM pState = hb_itemPutPtr( NULL, new QModelIndex( ( *reinterpret_cast< QModelIndex( * ) >( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, pState ); + delete ( ( QModelIndex * ) hb_itemGetPtr( pState ) ); + hb_itemRelease( pState ); +} + +static void hbqt_SlotsExecModelModel( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM pState1 = hb_itemPutPtr( NULL, new QModelIndex( ( *reinterpret_cast< QModelIndex( * ) >( arguments[ 1 ] ) ) ) ); + PHB_ITEM pState2 = hb_itemPutPtr( NULL, new QModelIndex( ( *reinterpret_cast< QModelIndex( * ) >( arguments[ 2 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 2, pState1, pState2 ); + delete ( ( QModelIndex * ) hb_itemGetPtr( pState1 ) ); + delete ( ( QModelIndex * ) hb_itemGetPtr( pState2 ) ); + hb_itemRelease( pState1 ); + hb_itemRelease( pState2 ); +} + +#include + +static void hbqt_SlotsExecItemSelItemSel( PHB_ITEM * codeBlock, void ** arguments) +{ + PHB_ITEM pState1 = hb_itemPutPtr( NULL, new QItemSelection( ( *reinterpret_cast< QItemSelection( * )>( arguments[ 1 ] ) ) ) ); + PHB_ITEM pState2 = hb_itemPutPtr( NULL, new QItemSelection( ( *reinterpret_cast< QItemSelection( * )>( arguments[ 2 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 2, pState1, pState2 ); + delete ( ( QItemSelection * ) hb_itemGetPtr( pState1 ) ); + delete ( ( QItemSelection * ) hb_itemGetPtr( pState2 ) ); + hb_itemRelease( pState1 ); + hb_itemRelease( pState2 ); +} + +#include + +static void hbqt_SlotsExecTextCharFormat( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QTextCharFormat( ( *reinterpret_cast( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QTextCharFormat * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecFont( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QFont( ( *reinterpret_cast< QFont( * )>( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QFont * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecQTextCursor( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QTextCursor( ( *reinterpret_cast< QTextCursor( * )>( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QTextCursor * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecStringList( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QStringList( ( *reinterpret_cast( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QStringList * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecPointer( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, ( *reinterpret_cast< void*( * )>( arguments[ 1 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecPointerInt( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, ( *reinterpret_cast< void*( * ) >( arguments[ 1 ] ) ) ); + PHB_ITEM p2 = hb_itemPutNI( NULL, ( *reinterpret_cast< int( * ) >( arguments[ 2 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 2, p1, p2 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); +} + +static void hbqt_SlotsExecPointerPointer( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, ( *reinterpret_cast< void*( * )>( arguments[ 1 ] ) ) ); + PHB_ITEM p2 = hb_itemPutPtr( NULL, ( *reinterpret_cast< void*( * )>( arguments[ 2 ] ) ) ); + hb_vmEvalBlockV( codeBlock, 2, p1, p2 ); + hb_itemRelease( p1 ); + hb_itemRelease( p2 ); +} + +static void hbqt_SlotsExecQPoint( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QPoint( ( * reinterpret_cast< QPoint( * )>( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QPoint * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + + +static void hbqt_SlotsExecQRectF( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QRectF( ( *reinterpret_cast< QRectF( * )>( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QRectF * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecQUrl( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QUrl( ( *reinterpret_cast< QUrl( * )>( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QUrl * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecQDate( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QDate( ( *reinterpret_cast< QDate( * ) >( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QDate * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecQDateTime( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QDateTime( ( *reinterpret_cast< QDateTime( * ) >( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QDateTime * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +static void hbqt_SlotsExecQTime( PHB_ITEM * codeBlock, void ** arguments ) +{ + PHB_ITEM p1 = hb_itemPutPtr( NULL, new QTime( ( *reinterpret_cast< QTime( * ) >( arguments[ 1 ] ) ) ) ); + hb_vmEvalBlockV( codeBlock, 1, p1 ); + delete ( ( QTime * ) hb_itemGetPtr( p1 ) ); + hb_itemRelease( p1 ); +} + +/*----------------------------------------------------------------------*/ + +static int connect_signal( QString signal, QObject * object, HBQSlots * t_slots ) +{ + HB_TRACE( HB_TR_DEBUG, ( "connect_signal: %s", ( char * ) signal.toAscii().data() ) ); + + QByteArray theSignal = signal.toAscii() + .replace( "QWidget" , "QWidget *" ) + .replace( "QPrinter" , "QPrinter *" ) + .replace( "QLWItem" , "QListWidgetItem *" ) + .replace( "QTWItem" , "QTreeWidgetItem *" ) + .replace( "QTblWItem" , "QTableWidgetItem *" ) + .replace( "QMdiSubWindow", "QMdiSubWindow *" ); + + theSignal = QMetaObject::normalizedSignature( theSignal ); + + HB_TRACE( HB_TR_DEBUG, ( " normalized: %s", ( char * ) theSignal.data() ) ); + + if( ! QMetaObject::checkConnectArgs( theSignal, theSignal ) ) + { + return -1; + } + + int signalId = object->metaObject()->indexOfSignal( theSignal ); + if( signalId == -1 ) + { + return -1; + } + // HB_TRACE( HB_TR_DEBUG, ( " signalId %d", signalId ) ); + + int slotId = object->metaObject()->indexOfMethod( theSignal ); + if( slotId == -1 ) + { + return -1; + } + // HB_TRACE( HB_TR_DEBUG, ( " slotId %d", slotId ) ); + if( QMetaObject::connect( object, signalId, t_slots, slotId + QObject::staticMetaObject.methodCount(), Qt::AutoConnection ) ) + { + HB_TRACE( HB_TR_DEBUG, ( " normalized: %i %i %s", signalId, slotId, ( char * ) theSignal.data() ) ); + return slotId; + } + return -1; +} + +/*----------------------------------------------------------------------*/ + +static bool disconnect_signal( QObject * object, QString signal ) +{ + QByteArray theSignal = signal.toAscii() + .replace( "QWidget" , "QWidget *" ) + .replace( "QPrinter" , "QPrinter *" ) + .replace( "QLWItem" , "QListWidgetItem *" ) + .replace( "QTWItem" , "QTreeWidgetItem *" ) + .replace( "QTblWItem" , "QTableWidgetItem *" ) + .replace( "QMdiSubWindow", "QMdiSubWindow *" ); + + theSignal = QMetaObject::normalizedSignature( theSignal ) ; + + int signalId = object->metaObject()->indexOfSignal( theSignal ); + if( signalId == -1 ) + { + return false; + } +// HB_TRACE( HB_TR_DEBUG, ( " signalId %d ", signalId ) ); + return QMetaObject::disconnect( object, signalId, 0, 0 ); +} + +/*----------------------------------------------------------------------*/ + +static void hbqt_SlotsProxy( HBQSlots * t_slots, int id, QObject * object, void ** arguments ) +{ + // array of function calls + // static void *( arrayFunc[23])(PHB_ITEM *, void ** ) { + // + #if 0 + static void * ( arrayFunc[ 23 ] ) + { + hbqt_SlotsExecInt, + hbqt_SlotsExecIntInt, + hbqt_SlotsExecIntIntInt, + hbqt_SlotsExecIntIntIntInt, + hbqt_SlotsExecBool, + hbqt_SlotsExecQRectInt , + hbqt_SlotsExecString , + hbqt_SlotsExecModel , + hbqt_SlotsExecModelModel , + hbqt_SlotsExecItemSelItemSel , + hbqt_SlotsExecTextCharFormat , + hbqt_SlotsExecFont , + hbqt_SlotsExecQTextCursor , + hbqt_SlotsExecStringList , + hbqt_SlotsExecPointer , + hbqt_SlotsExecPointerPointer , + hbqt_SlotsExecPointerInt , + hbqt_SlotsExecQDate, + hbqt_SlotsExecQDateTime, + hbqt_SlotsExecQPoint, + hbqt_SlotsExecQRectF, + hbqt_SlotsExecQTime, + hbqt_SlotsExecQUrl + } + #endif + + static QList< QByteArray > argCombinations; + + if( argCombinations.size() == 0 ) + { + argCombinations << "int" << + "int$int" << + "int$int$int" << + "int$int$int$int" << + "bool" << + "QRect$int" << + "QString" << + "QModel" << + "QModel$QModel" << + "QItemSelection$QItemSelection" << + "QTextCharFormat" << + "QFont" << + "QTextCursor" << + "QStringList" << + "pointer" << + "pointer$pointer" << + "pointer$int"<< + "QDate" << + "QDateTime" << + "QPoint" << + "QRectF" << + "QTime" << + "QUrl" ; + } + + const QMetaMethod meta = object->metaObject()->method( id ); + + HB_TRACE( HB_TR_DEBUG, ( "SlotsProxy signature %s", meta.signature() ) ); + + QList arrayOfTypes = meta.parameterTypes(); + + // HB_TRACE( HB_TR_DEBUG, ( " SlotsProxy objectName %s ", qPrintable( object->objectName() ) ) ); + // HB_TRACE( HB_TR_DEBUG, ( " SlotsProxy className %s ", (char * ) object->metaObject()->className() ) ); + int parameterCount = arrayOfTypes.size(); + QStringList parList; + + for( int i = 0; i < parameterCount; i++ ) + { + if( arrayOfTypes.at( i ).contains( "::" ) ) // if includes :: is a enum -> int + { + parList += "int"; + } + else + { + if( arrayOfTypes.at( i ).contains( "*" ) ) // if includes * is a pointer -> pointer + { + parList += "pointer"; + } + else + { + parList += arrayOfTypes.at( i ); // + } + } + } + + QByteArray paramString = parList.join("$").toAscii(); + HB_TRACE( HB_TR_DEBUG, ( " SlotsProxy parList %s ", (char * ) paramString.data() ) ); + + if( object ) + { + char cSlotName[ 20 ]; + sprintf( cSlotName, "SLOT_%d", id ); + int i = object->property( cSlotName ).toInt(); + // HB_TRACE( HB_TR_DEBUG, ( "SlotsProxy %s=%d", cSlotName, i ) ); + + if( i > 0 && i <= t_slots->listBlock.size() && hb_vmRequestReenter() ) + { + if( parameterCount == 0 ) + { + hb_vmEvalBlockV( t_slots->listBlock.at( i - 1 ), 0 ); + } + else + { + int paramId = argCombinations.indexOf( paramString ); + HB_TRACE( HB_TR_DEBUG, ( " params=%s, paramId=%d", ( char *) paramString.data(), paramId ) ); + + switch( paramId ) + { + case 0: // if( paramString == "int" ) + hbqt_SlotsExecInt( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 1: // if( paramString == "int$int" ) + hbqt_SlotsExecIntInt( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 2: // if( paramString == "int$int$int" ) + hbqt_SlotsExecIntIntInt( (PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 3: // if( paramString == "int$int$int$int" ) + hbqt_SlotsExecIntIntIntInt( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 4: // if( paramString == "bool" ) + hbqt_SlotsExecBool( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 5: // if( paramString == "QRect$int" ) + hbqt_SlotsExecQRectInt( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 6: // if( paramString == "QString" ) + hbqt_SlotsExecString( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 7: // if( paramString == "QModel" ) + hbqt_SlotsExecModel( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 8: // if( paramString == "QModel$QModel" ) + hbqt_SlotsExecModelModel( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 9: // if( paramString == "QItemSelection$QItemSelection" ) + hbqt_SlotsExecItemSelItemSel( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 10: // if( paramString == "QTextCharFormat" ) + hbqt_SlotsExecTextCharFormat( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 11: // if( paramString == "QFont" ) + hbqt_SlotsExecFont( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 12: // if( paramString == "QTextCursor" ) + hbqt_SlotsExecQTextCursor( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 13: // if( paramString == "QStringList" ) + hbqt_SlotsExecStringList( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 14: // if( paramString == "pointer" ) + hbqt_SlotsExecPointer( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 15: // if( paramString == "pointer$pointer" ) + hbqt_SlotsExecPointerPointer( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 16: // if( paramString == "pointer$int" ) + hbqt_SlotsExecPointerInt( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 17: // if( paramString == "QDate" ) + hbqt_SlotsExecQDate( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 18: // if( paramString == "QDateTime" ) + hbqt_SlotsExecQDateTime( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 19: // if( paramString == "QPoint" ) + hbqt_SlotsExecQPoint( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 20: // if( paramString == "QRectF" ) + hbqt_SlotsExecQRectF( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 21: // if( paramString == "QTime" ) + hbqt_SlotsExecQTime( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + case 22: // if( paramString == "QUrl" ) + hbqt_SlotsExecQUrl( ( PHB_ITEM * ) t_slots->listBlock.at( i - 1 ), arguments ) ; + break; + } + } + hb_vmRequestRestore(); + } + } +} + +HBQSlots::HBQSlots( QObject* parent ) : QObject( parent ) +{ +} + +HBQSlots::~HBQSlots() +{ + int i; + + for( i = 0; i < listBlock.size(); i++ ) + { + if( listBlock[ i ] != NULL ) + { + hb_itemRelease( listBlock.at( i ) ); + listBlock[ i ] = NULL; + } + } + /* QUESTION: Should there be all remaining active slots disconnected at this point? */ + + /* Should be disconnected, but this is a responsibility of programmer as object is only known to the application */ + listBlock.clear(); +} + +bool HBQSlots::hbIsConnected( PHB_ITEM pObj, const char * slot ) +{ + HB_SYMBOL_UNUSED( pObj ); + + QObject * object = ( QObject * ) hbqt_pPtrFromObj( 1 ); + return isConnected( object, slot ); +} + +bool HBQSlots::isConnected( QObject * object, const char * slot ) +{ + int i; + + for( i = 0; i < listBlock.size(); i++ ) + { + if( listBlock[ i ] != NULL && listObj[ i ] == object ) + { + if( object->property( slot ).toInt() == i + 1 ) + { + return true; + } + } + } + return false; +} + +bool HBQSlots::hbConnect( PHB_ITEM pObj, const char * slot, PHB_ITEM bBlock ) +{ + HB_SYMBOL_UNUSED( pObj ); + HB_SYMBOL_UNUSED( bBlock ); + + QObject * object = ( QObject * ) hbqt_pPtrFromObj( 1 ); /* get sender */ + + if( object ) + { + if( !isConnected( object, slot ) ) + { +HB_TRACE( HB_TR_DEBUG, ( "AAA 3 %s %p", slot, object ) ); + bool bConnected = connect_signal( ( QString ) slot, object, this ); +HB_TRACE( HB_TR_DEBUG, ( "AAA 4" ) ); + if( bConnected ) + { + PHB_ITEM pBlock = hb_itemNew( bBlock ); /* get codeblock */ +HB_TRACE( HB_TR_DEBUG, ( "AAA 5" ) ); + listBlock << pBlock; + listObj << object; + + object->setProperty( slot, ( int ) listBlock.size() ); + + return true; + } + } + } + return false; +} + +bool HBQSlots::hbDisconnect( PHB_ITEM pObj, const char * signal ) +{ + HB_SYMBOL_UNUSED( pObj ); + + QObject * object = ( QObject* ) hbqt_pPtrFromObj( 1 ); + + if( object ) + { + int i = object->property( signal ).toInt(); + + if( i > 0 && i <= listBlock.size() ) + { + hb_itemRelease( listBlock.at( i - 1 ) ); + listBlock[ i - 1 ] = NULL; + listObj[ i - 1 ] = NULL; + + bool bRet = disconnect_signal( object, ( QString ) signal ); + + HB_TRACE( HB_TR_DEBUG, ( " QT_SLOTS_DISCONNECT: %s %s", bRet ? "YES" : "NO", signal ) ); + + return bRet; + } + } + return false; +} + +bool HBQSlots::hbClear() +{ + int i; + + for( i = 0; i < listBlock.size(); i++ ) + { + if( listBlock[ i ] != NULL ) + { + hb_itemRelease( listBlock.at( i ) ); + listBlock[ i ] = NULL; + } + } + listBlock.clear(); + return true; +} + +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; + } + // Q_ASSERT(id < slotList.size()); + + hbqt_SlotsProxy( this, id, sender(), arguments ); + return -1; +} + + +/*----------------------------------------------------------------------*/ +/* + * Harbour function to connect signals with slots + */ +HB_FUNC( QT_SLOTS_CONNECT ) +{ + HB_BOOL bRet = HB_FALSE; + HBQSlots * t_slots = hbqt_par_HBQSlots( 1 ); + + if( t_slots ) + { + QObject * object = ( QObject * ) hbqt_pPtrFromObj( 2 ); /* get sender */ + if( object ) + { + int i = object->property( hb_parcx( 3 ) ).toInt(); + if ( i == 0 ) + { + QString signal = hb_parcx( 3 ); /* get signal */ + int idSignal = connect_signal( signal, object, t_slots ) ; + if( idSignal >= 0 ) + { + PHB_ITEM pBlock = hb_itemNew( hb_param( 4, HB_IT_BLOCK ) ); /* get codeblock */ + t_slots->listBlock << pBlock; + + char cSlotName[ 20 ]; + sprintf( cSlotName, "SLOT_%d", idSignal ); + + object->setProperty( cSlotName, ( int ) t_slots->listBlock.size() ); + object->setProperty( hb_parcx(3), ( int ) t_slots->listBlock.size() ); + bRet = HB_TRUE; + } + } + } + } + if ( !bRet ) + hb_errRT_BASE( EG_ARG, 1100, NULL, "CONNECT", HB_ERR_ARGS_BASEPARAMS ); + hb_retl( bRet ); +} + +/* + * Harbour function to disconnect signals + */ +HB_FUNC( QT_SLOTS_DISCONNECT ) +{ + HB_BOOL bRet = HB_FALSE; + HBQSlots * t_slots = hbqt_par_HBQSlots( 1 ); + + if( t_slots ) + { + QObject * object = ( QObject* ) hbqt_pPtrFromObj( 2 ); + if( object ) + { + const char * slot = hb_parcx( 3 ); + + int i = object->property( slot ).toInt(); + + if( i > 0 && i <= t_slots->listBlock.size() ) + { + object->setProperty( slot, QVariant() ); + + bRet = ( disconnect_signal( object, ( QString ) slot ) == true ); + + hb_itemRelease( t_slots->listBlock.at( i - 1 ) ); + t_slots->listBlock[ i - 1 ] = NULL; + } + } + } + hb_retl( bRet ); +} + +HB_FUNC( QT_SLOTS_NEW ) +{ + void * pObj = NULL; + + pObj = ( HBQSlots * ) new HBQSlots(); + + hb_retptrGC( hbqt_gcAllocate_HBQSlots( pObj, true ) ); +} + +#endif #endif diff --git a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h index 1c43d17eb6..b75cd59864 100644 --- a/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h +++ b/harbour/contrib/hbqt/qtcore/hbqt_hbqslots.h @@ -78,6 +78,10 @@ /*----------------------------------------------------------------------*/ +#define __PRITPAL__ + +#ifdef __PRITPAL__ + class HBQSlots: public QObject { Q_OBJECT @@ -316,6 +320,27 @@ public slots: /* Latest */ }; +#else + +class HBQSlots: public QObject +{ + +public: + HBQSlots( QObject *parent = 0 ); + ~HBQSlots(); + QList listBlock; + QList listObj; + + int qt_metacall( QMetaObject::Call call, int id, void **arguments ); + + bool hbConnect( PHB_ITEM pObj, const char * slot, PHB_ITEM bBlock ); + bool hbDisconnect( PHB_ITEM pObj, const char * slot ); + bool hbIsConnected( PHB_ITEM pObj, const char * slot ); + bool isConnected( QObject * object, const char * slot ); + bool hbClear(); +}; + +#endif /*----------------------------------------------------------------------*/ #endif diff --git a/harbour/contrib/hbxbp/xbplistbox.prg b/harbour/contrib/hbxbp/xbplistbox.prg index cc2d62fcb0..a780f63923 100644 --- a/harbour/contrib/hbxbp/xbplistbox.prg +++ b/harbour/contrib/hbxbp/xbplistbox.prg @@ -175,6 +175,7 @@ METHOD XbpListBox:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) IF ! ::vertScroll ::oWidget:setVerticalScrollBarPolicy( Qt_ScrollBarAlwaysOff ) ENDIF + ::oWidget:setContextMenuPolicy( Qt_CustomContextMenu ) ::connect() ::setPosAndSize() @@ -192,7 +193,7 @@ METHOD XbpListBox:create( oParent, oOwner, aPos, aSize, aPresParams, lVisible ) METHOD XbpListBox:connect() - ::oWidget:connect( QEvent_ContextMenu, {|e| ::grabEvent( QEvent_ContextMenu, e ) } ) +// ::oWidget:connect( QEvent_ContextMenu, {|e| ::grabEvent( QEvent_ContextMenu, e ) } ) ::oWidget:connect( "currentItemChanged(QLWItem,QLWItem)", {|p,p1| ::execSlot( "currentItemChanged(QLWItem,QLWItem)", p, p1 ) } ) ::oWidget:connect( "currentRowChanged(int)" , {|p,p1| ::execSlot( "currentRowChanged(int)" , p, p1 ) } ) @@ -205,13 +206,15 @@ METHOD XbpListBox:connect() ::oWidget:connect( "itemPressed(QLWItem)" , {|p,p1| ::execSlot( "itemPressed(QLWItem)" , p, p1 ) } ) ::oWidget:connect( "itemSelectionChanged()" , {|p,p1| ::execSlot( "itemSelectionChanged()" , p, p1 ) } ) + ::oWidget:connect( "customContextMenuRequested(QPoint)" , {|p1 | ::execSlot( "customContextMenuRequested(QPoint)" , p1 ) } ) + RETURN Self /*----------------------------------------------------------------------*/ METHOD XbpListBox:disConnect() - ::oWidget:disconnect( QEvent_ContextMenu ) +// ::oWidget:disconnect( QEvent_ContextMenu ) ::oWidget:disConnect( "currentItemChanged(QLWItem,QLWItem)" ) ::oWidget:disConnect( "currentRowChanged(int)" ) @@ -224,6 +227,8 @@ METHOD XbpListBox:disConnect() ::oWidget:disConnect( "itemPressed(QLWItem)" ) ::oWidget:disConnect( "itemSelectionChanged()" ) + ::oWidget:disconnect( "customContextMenuRequested(QPoint)" ) + RETURN Self /*----------------------------------------------------------------------*/ @@ -264,7 +269,20 @@ METHOD XbpListBox:getItemIndex( pItm ) /*----------------------------------------------------------------------*/ METHOD XbpListBox:execSlot( cSlot, p ) - LOCAL qItm, nIndex + LOCAL qPos, qItm, nIndex, n, qPt + + IF cSlot == "customContextMenuRequested(QPoint)" + IF hb_isBlock( ::hb_contextMenu ) + qPos := QPoint( p ) + IF ( qItm := ::oWidget:itemAt( qPos ) ):isValidObject() + IF ( n := ascan( ::aItems, {|o| hbqt_IsEqualGcQtPointer( o, qItm ) } ) ) > 0 + qPt := ::oWidget:mapToGlobal( QPoint( p ) ) + eval( ::hb_contextMenu, { qPt:x(), qPt:y() }, NIL, ::aItems[ n ] ) + ENDIF + ENDIF + ENDIF + RETURN Self + ENDIF IF hb_isPointer( p ) IF ( nIndex := ::getItemIndex( p ) ) > 0 @@ -276,19 +294,9 @@ METHOD XbpListBox:execSlot( cSlot, p ) ENDIF SWITCH cSlot - CASE "currentItemChanged(QLWItem,QLWItem)" - EXIT CASE "currentRowChanged(int)" ::nCurSelected := p + 1 EXIT - CASE "currentTextChanged(QString)" - EXIT - CASE "itemActivated(QLWItem)" - EXIT - CASE "itemChanged(QLWItem)" - EXIT - CASE "itemPressed(QLWItem)" - EXIT CASE "itemClicked(QLWItem)" ::toggleSelected( nIndex ) ::itemMarked() @@ -299,8 +307,20 @@ METHOD XbpListBox:execSlot( cSlot, p ) CASE "itemEntered(QLWItem)" ::oWidget:setToolTip( qItm:text() ) EXIT + #if 0 + CASE "currentItemChanged(QLWItem,QLWItem)" + EXIT + CASE "currentTextChanged(QString)" + EXIT + CASE "itemActivated(QLWItem)" + EXIT + CASE "itemChanged(QLWItem)" + EXIT + CASE "itemPressed(QLWItem)" + EXIT CASE "itemSelectionChanged()" EXIT + #endif ENDSWITCH RETURN Self @@ -325,7 +345,6 @@ METHOD XbpListBox:configure( oParent, oOwner, aPos, aSize, aPresParams, lVisible METHOD XbpListBox:destroy() - ::clear( .f. ) ::xbpWindow:destroy()