Navigation Menu

Skip to content

Commit

Permalink
qtcollider: optimization - use Symbols to reference C++ methods and p…
Browse files Browse the repository at this point in the history
…roperties
  • Loading branch information
jleben committed May 3, 2012
1 parent dad9233 commit c7e6514
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 52 deletions.
52 changes: 31 additions & 21 deletions QtCollider/primitives/prim_QObject.cpp
Expand Up @@ -50,8 +50,10 @@ int QObject_Finalize( struct VMGlobals *, struct PyrObject * );

QC_LANG_PRIMITIVE( QObject_New, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
if(NotSym(a+0)) return errWrongType;

PyrObject *scObject = slotRawObject( r );
QString qtClassName = Slot::toString( a+0 );
QString qtClassName = QString(slotRawSymbol(a+0)->name);

qcSCObjectDebugMsg( 1, scObject, QString("CREATE: %2").arg(qtClassName) );

Expand Down Expand Up @@ -202,7 +204,9 @@ QC_LANG_PRIMITIVE( QMetaObject_Properties, 0, PyrSlot *r, PyrSlot *a, VMGlobals
{
if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();

QString className = Slot::toString( slotRawObject(r)->slots+0 );
PyrSlot *sClassName = slotRawObject(r)->slots+0;
if(NotSym(sClassName)) return errWrongType;
QString className( slotRawSymbol(sClassName)->name );

QcAbstractFactory *f = QtCollider::factories().value( className );

Expand All @@ -221,7 +225,9 @@ QC_LANG_PRIMITIVE( QMetaObject_Methods, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g
{
if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();

QString className = Slot::toString(slotRawObject(r)->slots+0);
PyrSlot *sClassName = slotRawObject(r)->slots+0;
if(NotSym(sClassName)) return errWrongType;
QString className( slotRawSymbol(sClassName)->name );

QcAbstractFactory *f = QtCollider::factories().value( className );

Expand Down Expand Up @@ -373,80 +379,84 @@ QC_LANG_PRIMITIVE( QObject_SetEventHandlerEnabled, 2, PyrSlot *r, PyrSlot *a, VM

QC_LANG_PRIMITIVE( QObject_ConnectMethod, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QString signal = Slot::toString( a+0 );
if( signal.isEmpty() || NotSym( a+1 ) ) return errWrongType;
PyrSymbol *handler = 0; slotSymbolVal( a+1, &handler );
if( NotSym(a+0) || NotSym( a+1 ) ) return errWrongType;

PyrSymbol *signal = slotRawSymbol(a+0);
PyrSymbol *handler = slotRawSymbol(a+1);
Qt::ConnectionType ctype =
Slot::toBool( a+2 ) ? Qt::DirectConnection : Qt::QueuedConnection;

qcSCObjectDebugMsg( 1, slotRawObject(r),
QString("CONNECT METHOD: %1 -> %2 [%3]").arg(signal).arg(handler->name)
QString("CONNECT METHOD: %1 -> %2 [%3]").arg(signal->name).arg(handler->name)
.arg( IsTrue(a+2) ? "SYNC" : "ASYNC") );

QObjectProxy *proxy = QOBJECT_FROM_SLOT( r );

if( !proxy->compareThread() ) return QtCollider::wrongThreadError();

bool ok = proxy->connectMethod( signal.toAscii().constData(), handler, ctype );
bool ok = proxy->connectMethod( signal->name, handler, ctype );

return ok ? errNone : errFailed;
}

QC_LANG_PRIMITIVE( QObject_DisconnectMethod, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QString signal = Slot::toString( a+0 );
if( signal.isEmpty() || NotSym( a+1 ) ) return errWrongType;
PyrSymbol *handler = 0; slotSymbolVal( a+1, &handler );
if( NotSym(a+0) || NotSym( a+1 ) ) return errWrongType;

PyrSymbol *signal = slotRawSymbol(a+0);
PyrSymbol *handler = slotRawSymbol(a+1);

qcSCObjectDebugMsg( 1, slotRawObject(r),
QString("DISCONNECT METHOD: %1 -> %2").arg(signal).arg(handler->name) );
QString("DISCONNECT METHOD: %1 -> %2").arg(signal->name).arg(handler->name) );

QObjectProxy *proxy = QOBJECT_FROM_SLOT( r );

if( !proxy->compareThread() ) return QtCollider::wrongThreadError();

bool ok = proxy->disconnectMethod( signal.toAscii().constData(), handler );
bool ok = proxy->disconnectMethod( signal->name, handler );

return ok ? errNone : errFailed;
}

QC_LANG_PRIMITIVE( QObject_ConnectObject, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QString signal = Slot::toString( a+0 );
if( signal.isEmpty() || NotObj( a+1 ) ) return errWrongType;
if( NotSym(a+0) || NotObj( a+1 ) ) return errWrongType;

PyrSymbol *signal = slotRawSymbol(a+0);
PyrObject *handlerObj = slotRawObject( a+1 );
Qt::ConnectionType ctype =
Slot::toBool( a+2 ) ? Qt::DirectConnection : Qt::QueuedConnection;

qcSCObjectDebugMsg( 1, slotRawObject(r),
QString("CONNECT OBJECT: %1 -> %2 [%3]")
.arg(signal)
.arg( signal->name )
.arg( slotRawSymbol( &handlerObj->classptr->name )->name )
.arg( IsTrue(a+2) ? "SYNC" : "ASYNC") );

QObjectProxy *proxy = QOBJECT_FROM_SLOT( r );

if( !proxy->compareThread() ) return QtCollider::wrongThreadError();

bool ok = proxy->connectObject( signal.toAscii().constData(), handlerObj, ctype );
bool ok = proxy->connectObject( signal->name, handlerObj, ctype );

return ok ? errNone : errFailed;
}

QC_LANG_PRIMITIVE( QObject_DisconnectObject, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QString signal = Slot::toString( a+0 );
if( signal.isEmpty() || NotObj( a+1 ) ) return errWrongType;
if( NotSym(a+0) || NotObj( a+1 ) ) return errWrongType;

PyrSymbol *signal = slotRawSymbol(a+0);
PyrObject *handlerObj = slotRawObject( a+1 );

qcSCObjectDebugMsg( 1, slotRawObject(r),
QString("DISCONNECT OBJECT: %1").arg(signal) );
QString("DISCONNECT OBJECT: %1").arg(signal->name) );

QObjectProxy *proxy = QOBJECT_FROM_SLOT( r );

if( !proxy->compareThread() ) return QtCollider::wrongThreadError();

bool ok = proxy->disconnectObject( signal.toAscii().constData(), handlerObj );
bool ok = proxy->disconnectObject( signal->name, handlerObj );

return ok ? errNone : errFailed;
}
Expand Down
16 changes: 8 additions & 8 deletions SCClassLibrary/QtCollider/BasicViews.sc
Expand Up @@ -118,11 +118,11 @@ QAbstractStepValue : QView {
/////////////////////// CONTAINERS ////////////////////////////////

QHLayoutView : QView {
*qtClass { ^"QcHLayoutWidget" }
*qtClass { ^'QcHLayoutWidget' }
}

QVLayoutView : QView {
*qtClass { ^"QcVLayoutWidget" }
*qtClass { ^'QcVLayoutWidget' }
}

QScrollCanvas : QObject {
Expand All @@ -148,7 +148,7 @@ QScrollView : QAbstractScroll {
^super.new( parent, bounds ).initQScrollView;
}

*qtClass { ^"QcScrollArea" }
*qtClass { ^'QcScrollArea' }

children { arg class = QView;
^canvas.children( class );
Expand Down Expand Up @@ -196,7 +196,7 @@ QScrollView : QAbstractScroll {
/////////////////////////// WIDGETS ///////////////////////////////

QStaticText : QTextViewBase {
*qtClass { ^"QLabel" }
*qtClass { ^'QLabel' }

*new { arg aParent, aBounds;
var obj = super.new( aParent, aBounds );
Expand Down Expand Up @@ -224,7 +224,7 @@ QStaticText : QTextViewBase {
}

QTextField : QTextViewBase {
*qtClass { ^"QcTextField" }
*qtClass { ^'QcTextField' }

string {
^this.getProperty( \text );
Expand Down Expand Up @@ -273,7 +273,7 @@ QTextField : QTextViewBase {
QButton : QView {
var <states;

*qtClass { ^"QcButton" }
*qtClass { ^'QcButton' }

value {
^this.getProperty( \value );
Expand Down Expand Up @@ -317,7 +317,7 @@ QButton : QView {

QCheckBox : QView {

*qtClass { ^"QcCheckBox" }
*qtClass { ^'QcCheckBox' }

*new{ |parent,bounds,text|
^super.new(parent,bounds).init(text)
Expand Down Expand Up @@ -357,7 +357,7 @@ QCheckBox : QView {

QPopUpMenu : QItemViewBase {

*qtClass { ^"QcPopUpMenu" }
*qtClass { ^'QcPopUpMenu' }

allowsReselection { ^this.getProperty( \reactivationEnabled ) }

Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QEnvelopeView.sc
Expand Up @@ -5,7 +5,7 @@ QEnvelopeView : QView
var <drawLines = true, <drawRects = true;
var <metaAction;

*qtClass {^"QcGraph"}
*qtClass {^'QcGraph'}

editable_ { arg aBool;
editable = aBool;
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QKnob.sc
Expand Up @@ -18,7 +18,7 @@ QKnob : QAbstractStepValue {

var <>keystep = 0.01;

*qtClass {^"QcKnob"}
*qtClass {^'QcKnob'}

*new { arg parent, bounds;
var me = super.new(parent,bounds);
Expand Down
4 changes: 2 additions & 2 deletions SCClassLibrary/QtCollider/QLayout.sc
Expand Up @@ -56,12 +56,12 @@ QLineLayout : QLayout {

QHLayout : QLineLayout {
*implementsClass {^'HLayout'}
*qtClass { ^'QcHBoxLayout'; }
*qtClass { ^'QcHBoxLayout' }
}

QVLayout : QLineLayout {
*implementsClass {^'VLayout'}
*qtClass { ^'QcVBoxLayout'; }
*qtClass { ^'QcVBoxLayout' }
}

// GRID LAYOUT ///////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QLevelIndicator.sc
@@ -1,6 +1,6 @@
QLevelIndicator : QView {

*qtClass {^"QcLevelIndicator"}
*qtClass {^'QcLevelIndicator'}

value {
^this.getProperty(\value)
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QListView.sc
Expand Up @@ -2,7 +2,7 @@ QListView : QItemViewBase {
var <colors;
var <enterKeyAction;

*qtClass { ^"QcListWidget" }
*qtClass { ^'QcListWidget' }

mouseDownEvent { arg x, y, modifiers, buttonNumber, clickCount;
// Override QView:mouseDownEvent:
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QMultiSliderView.sc
Expand Up @@ -6,7 +6,7 @@ QMultiSliderView : QView {
var <metaAction;


*qtClass { ^"QcMultiSlider" }
*qtClass { ^'QcMultiSlider' }

size { ^this.getProperty(\sliderCount) }
size_ { arg int; this.setProperty( \sliderCount, int ) }
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QNumberBox.sc
Expand Up @@ -4,7 +4,7 @@ QNumberBox : QAbstractStepValue {
var <normalColor, <typingColor;
var <object, <>setBoth = true;

*qtClass { ^"QcNumberBox" }
*qtClass { ^'QcNumberBox' }

*new { arg aParent, aBounds;
var obj = super.new( aParent, aBounds );
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QObject.sc
Expand Up @@ -38,7 +38,7 @@ QObject {

*qtClass { ^nil }

*meta { ^QMetaObject(this.qtClass); }
*meta { ^QMetaObject(this.qtClass) }

*new { arg argumentArray;
var className = this.qtClass;
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QRangeSlider.sc
@@ -1,5 +1,5 @@
QRangeSlider : QAbstractStepValue {
*qtClass { ^"QcRangeSlider" }
*qtClass { ^'QcRangeSlider' }

*new { arg parent, bounds;
^super.new( parent, bounds ).initQRangeSlider( bounds );
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QScope.sc
Expand Up @@ -2,7 +2,7 @@ QScope : QView {
var <bufnum, <style=0, <xZoom=1.0, <yZoom=1.0, <x=0.0, <y=0.0;
var <waveColors;

*qtClass { ^"QcScope" }
*qtClass { ^'QcScope' }

bufnum_ { arg anInt;
bufnum = anInt;
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QScope2.sc
Expand Up @@ -3,7 +3,7 @@ QScope2 : QView {
var <xZoom=1.0, <yZoom=1.0, <x=0.0, <y=0.0;
var <waveColors;

*qtClass { ^"QcScopeShm" }
*qtClass { ^'QcScopeShm' }

bufnum_ { arg anInt;
bufnum = anInt;
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QSlider.sc
Expand Up @@ -2,7 +2,7 @@ QSlider : QAbstractStepValue {
//compatibility stuff:
var <orientation;

*qtClass { ^"QcSlider" }
*qtClass { ^'QcSlider' }

*new { arg parent, bounds;
^super.new( parent, bounds ).initQSlider( bounds );
Expand Down
4 changes: 2 additions & 2 deletions SCClassLibrary/QtCollider/QSlider2D.sc
@@ -1,9 +1,9 @@
QSlider2D : QAbstractStepValue {
*qtClass { ^"QcSlider2D" }
*qtClass { ^'QcSlider2D' }

*new { arg parent, bounds;
var me = super.new( parent, bounds );
me.connectMethod( "randomize()", \randomize );
me.connectMethod( 'randomize()', \randomize );
^me;
}

Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QSoundFileView.sc
Expand Up @@ -5,7 +5,7 @@ QSoundFileView : QView {
var <>elasticMode; // NOTE: no-op, only for compatibility
var curDoneAction;

*qtClass { ^"QcWaveform" }
*qtClass { ^'QcWaveform' }

load { arg filename, startframe, frames, block, doneAction;
if( filename.isString && filename != "" ) {
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QTextView.sc
@@ -1,7 +1,7 @@
QTextView : QAbstractScroll {
var <stringColor, <font, <editable=true;

*qtClass { ^"QcTextEdit" }
*qtClass { ^'QcTextEdit' }

enterInterpretsSelection { ^this.getProperty( \enterInterpretsSelection ); }

Expand Down
10 changes: 5 additions & 5 deletions SCClassLibrary/QtCollider/QTreeView.sc
Expand Up @@ -2,7 +2,7 @@ QTreeView : QView {
var <itemPressedAction;
var <onItemChanged;

*qtClass { ^"QcTreeWidget" }
*qtClass { ^'QcTreeWidget' }

columns_ { arg labels; this.setProperty( \columns, labels ); }
columns { ^this.getProperty( \columns ); }
Expand Down Expand Up @@ -41,20 +41,20 @@ QTreeView : QView {

itemPressedAction_ { arg action;
if(itemPressedAction.notNil) {
this.disconnectFunction( "itemPressedAction()", itemPressedAction );
this.disconnectFunction( 'itemPressedAction()', itemPressedAction );
};
if(action.notNil) {
this.connectFunction( "itemPressedAction()", action );
this.connectFunction( 'itemPressedAction()', action );
};
itemPressedAction = action;
}

onItemChanged_ { arg hook;
if(onItemChanged.notNil) {
this.disconnectFunction( "currentItemChanged()", onItemChanged );
this.disconnectFunction( 'currentItemChanged()', onItemChanged );
};
if(hook.notNil) {
this.connectFunction( "currentItemChanged()", hook );
this.connectFunction( 'currentItemChanged()', hook );
};
onItemChanged = hook;
}
Expand Down
2 changes: 1 addition & 1 deletion SCClassLibrary/QtCollider/QUserView.sc
@@ -1,7 +1,7 @@
QUserView : QView {
var <drawFunc, <drawingEnabled=true;

*qtClass { ^"QcCustomPainted" }
*qtClass { ^'QcCustomPainted' }

*new { arg parent, bounds;
var me = super.new(parent, bounds ?? {this.sizeHint} );
Expand Down

0 comments on commit c7e6514

Please sign in to comment.