direct slot invocation (Re: kdelibs/kdecore)

Oswald Buddenhagen ossi at kde.org
Sun Feb 16 19:23:17 GMT 2003


moin,

i originally sent this to scott only, but it seems to be worth
discussing publically from what i heard on irc.

my position here is that my code is safe even though it uses internal
apis. the stuff around qt_invoke cannot be changed before qt 4.0, as
qt3.0-created mocs (which use qt_invoke) must still work with the
qmetaobject provided by later qt3.x versions. and as long qt_invoke does
not change, there is also little point in changing findSlot. so i think
it is safe to assume that this api is stable within all qt3.x releases.

-------------------------

On Sat, Feb 15, 2003 at 11:31:49PM +0100, Scott Wheeler wrote:
> CVS commit by wheeler: 
> 
> Added support for application wide edit actions (cut, copy, paste) etc. as
> mentioned on core-devel.
> 
as usual some optimization nitpicking from me, and as (almost) always
"post mortem". :)

> --- kdelibs/kdecore/kapplication.cpp  #1.564:1.565
> @@ -44,4 +44,5 @@
>  #include <qtooltip.h>
>  #include <qstylefactory.h>
> +#include <qmetaobject.h>
>  #ifndef QT_NO_SQL
>  #include <qsqlpropertymap.h>
> @@ -1519,4 +1520,22 @@ bool KApplication::x11EventFilter( XEven
>  #endif
>  

> +void KApplication::invokeEditSlot( const char *slotName, const char *slot )
void KApplication::invokeEditSlot( const char *slot )

> +{
> +  QObject *object = focusWidget();
> +  

> +  if( !object || !slotName || !slot )
if( !object )

> +    return;
> +  
> +  QMetaObject *meta = object->metaObject();

> +  QStrList l = meta->slotNames(true);
> +  
> +  if( l.find( slotName ) == -1 )
> +    return;
> +  
> +  connect( this, SIGNAL( editSignal() ), object, slot );
> +  emit editSignal();
> +  disconnect( this, SIGNAL( editSignal() ), object, slot );
int idx = meta->findSlot(slot, true);
if (idx < 0)
  return;
object->qt_invoke(idx, 0);

> +}
> +
>  void KApplication::addKipcEventMask(int id)
>  {
> @@ -1983,4 +2002,29 @@ void KApplication::invokeBrowser( const 
>        return;
>     }
> +}
> +
> +void KApplication::cut()
> +{

> +  invokeEditSlot( "cut()", SLOT( cut() ) );
invokeEditSlot( SLOT( cut() ) );

> +}
> +
> +void KApplication::copy()
> +{

> +  invokeEditSlot( "copy()", SLOT( copy() ) );
ditto

> +}
> +
> +void KApplication::paste()
> +{

> +  invokeEditSlot( "paste()", SLOT( paste() ) );
etc.

> +}
> +
> +void KApplication::clear()
> +{

> +  invokeEditSlot( "clear()", SLOT( clear() ) );
*yawn*

> +}
> +
> +void KApplication::selectAll()
> +{

> +  invokeEditSlot( "selectAll()", SLOT( selectAll() ) );
*zzZZZzz*

>  }
>  
> 
> --- kdelibs/kdecore/kapplication.h  #1.281:1.282
> @@ -469,4 +469,10 @@ public slots:
>    void invokeBrowser( const QString &url );
>  
> +  void cut();
> +  void copy();
> +  void paste();
> +  void clear();
> +  void selectAll();
> +
>  public:
>    /**
> @@ -913,4 +919,6 @@ protected:
>    int pArgc;
>  

> +  void invokeEditSlot( const char *slotName, const char *slot );
void invokeEditSlot( const char *slot );

> +
>  private slots:
>    void dcopFailure(const QString &);
> @@ -1099,4 +1108,6 @@ signals:
>     */
>    void shutDown();

> +
> +  void editSignal();
*plopp*

>  
>  private:
> 
> 

i would not bet that this is 100% correct, but at least it comes close,
i think. i looked at q{,meta}object for half an hour now - it _has_ to
be close. :)

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.




More information about the kde-core-devel mailing list