Browse files

qtcollider: construct all SC types at Qt -> SC type conversion

Construct all Point, Rect, Color and QPalette involved in Qt to
SC type conversion immediately at conversion, thus avoiding the
need to construct them beforhand in SC.

Notable effects:

* Any type can be returned by QObject-getProperty without the need
  to pass an instance of the type to the method.

* Any type can be passed to SC in an Array

* Any type can be passed to SC as signal argument

* Any type can be returned by QObject-invokeMethod
  • Loading branch information...
1 parent df3bdcc commit baed293b1d17c2bbb5c2359eed503816964674c6 @jleben jleben committed Dec 4, 2011
View
2 QtCollider/Common.cpp
@@ -25,7 +25,7 @@ void QtCollider::runLang (
++g->sp; SetObject(g->sp, receiver);
Q_FOREACH( QVariant var, args ) {
++g->sp;
- if( Slot::setVariant( g->sp, var ) )
+ if( !Slot::setVariant( g->sp, var ) )
SetNil( g->sp );
}
runInterpreter(g, method, args.size() + 1);
View
94 QtCollider/Slot.cpp
@@ -46,32 +46,26 @@ static QPalette::ColorRole paletteColorRoles[] = {
QPalette::HighlightedText,
};
-int Slot::setRect( PyrSlot *slot, const QRectF &r )
+void Slot::setRect( PyrSlot *slot, const QRectF &r )
{
- if( !isKindOfSlot( slot, class_Rect ) ) {
- return errWrongType;
- }
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Rect, 0, true, true );
+ SetObject( slot, obj );
- PyrSlot *slots = slotRawObject( slot )->slots;
+ PyrSlot *slots = obj->slots;
SetFloat( slots+0, r.x() );
SetFloat( slots+1, r.y() );
SetFloat( slots+2, r.width() );
SetFloat( slots+3, r.height() );
-
- return errNone;
}
-int Slot::setPoint( PyrSlot *slot, const QPointF &pt )
+void Slot::setPoint( PyrSlot *slot, const QPointF &pt )
{
- if( !isKindOfSlot( slot, class_Point ) ) {
- return errWrongType;
- }
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Point, 0, true, true );
+ SetObject( slot, obj );
- PyrSlot *slots = slotRawObject( slot )->slots;
+ PyrSlot *slots = obj->slots;
SetFloat( slots+0, pt.x() );
SetFloat( slots+1, pt.y() );
-
- return errNone;
}
void Slot::setSize( PyrSlot *slot, const QSizeF &sz )
@@ -91,31 +85,30 @@ void Slot::setString( PyrSlot *slot, const QString& arg )
SetObject( slot, str );
}
-int Slot::setColor( PyrSlot *slot, const QColor &c )
+void Slot::setColor( PyrSlot *slot, const QColor &c )
{
- if( !isKindOfSlot( slot, class_Color) ) return errWrongType;
-
- PyrSlot *slots = slotRawObject( slot )->slots;
+ PyrObject *obj = instantiateObject( gMainVMGlobals->gc, class_Color, 0, true, true );
+ SetObject( slot, obj );
+ PyrSlot *slots = obj->slots;
SetFloat( slots+0, c.red() / 255.0 );
SetFloat( slots+1, c.green() / 255.0 );
SetFloat( slots+2, c.blue() / 255.0 );
SetFloat( slots+3, c.alpha() / 255.0 );
-
- return errNone;
}
-int Slot::setPalette( PyrSlot *slot, const QPalette &plt )
+void Slot::setPalette( PyrSlot *slot, const QPalette &plt )
{
- if( !isKindOfSlot( slot, class_QPalette ) ) return errWrongType;
+ PyrGC *gc = gMainVMGlobals->gc;
+ PyrObject *obj = instantiateObject( gc, class_QPalette, 0, true, true );
+ SetObject( slot, obj );
- PyrSlot *s = slotRawObject( slot )->slots;
+ PyrSlot *s = obj->slots;
for( int i=0; i<8; ++i, ++s ) {
- if( setColor( s, plt.color( paletteColorRoles[i] ) ) ) return errFailed;
+ setColor( s, plt.color( paletteColorRoles[i] ) );
+ gc->GCWrite( obj, s );
}
-
- return errNone;
}
void Slot::setQObject( PyrSlot *s, QObject *o )
@@ -151,15 +144,15 @@ void Slot::setVariantList( PyrSlot *slot, const VariantList& varList )
int i;
PyrSlot *s = array->slots;
for( i = 0; i < count; ++i, ++s ) {
- if( Slot::setVariant( s, varList.data[i] ) ) {
+ if( !Slot::setVariant( s, varList.data[i] ) ) {
qcDebugMsg(1, "WARNING: Could not set one slot of array" );
}
array->size++;
g->gc->GCWrite( array, s );
}
}
-int Slot::setVariant( PyrSlot *slot, const QVariant &val )
+bool Slot::setVariant( PyrSlot *slot, const QVariant &val )
{
bool b_val;
int type = val.userType();
@@ -169,40 +162,56 @@ int Slot::setVariant( PyrSlot *slot, const QVariant &val )
b_val = val.toBool();
if( b_val ) SetTrue( slot );
else SetFalse( slot );
- return errNone;
+ break;
+
case QMetaType::QPoint:
case QMetaType::QPointF:
- return Slot::setPoint( slot, val.toPointF() );
+ Slot::setPoint( slot, val.toPointF() );
+ break;
+
case QMetaType::QSize:
case QMetaType::QSizeF:
Slot::setSize( slot, val.toSizeF() );
- return errNone;
+ break;
+
case QMetaType::QRect:
case QMetaType::QRectF:
- return Slot::setRect( slot, val.toRectF() );
+ Slot::setRect( slot, val.toRectF() );
+ break;
+
case QMetaType::QString:
Slot::setString( slot, val.toString() );
- return errNone;
+ break;
+
case QMetaType::QColor:
- return Slot::setColor( slot, val.value<QColor>() );
+ Slot::setColor( slot, val.value<QColor>() );
+ break;
+
case QMetaType::QPalette:
- return Slot::setPalette( slot, val.value<QPalette>() );
+ Slot::setPalette( slot, val.value<QPalette>() );
+ break;
+
case QMetaType::Float:
case QMetaType::Double:
SetFloat( slot, val.value<double>() );
- return errNone;
+ break;
+
case QMetaType::Int:
SetInt( slot, val.toInt() );
- return errNone;
+ break;
+
case QMetaType::QObjectStar:
Slot::setQObject( slot, val.value<QObject*>() );
- return errNone;
+ break;
+
case QMetaType::QWidgetStar:
Slot::setQObject( slot, val.value<QWidget*>() );
- return errNone;
+ break;
+
case QMetaType::Void:
SetNil( slot );
- return errNone;
+ break;
+
default:
if( type == qMetaTypeId<PyrObject*>() ) {
SetObject( slot, val.value<PyrObject*>() );
@@ -215,10 +224,11 @@ int Slot::setVariant( PyrSlot *slot, const QVariant &val )
}
else {
qcErrorMsg( "the QVariant could not be interpreted!" );
- return errFailed;
+ return false;
}
- return errNone;
}
+
+ return true;
}
bool Slot::toBool( PyrSlot *slot )
View
10 QtCollider/Slot.h
@@ -57,16 +57,16 @@ namespace Slot
QcTreeWidget::ItemPtr toTreeWidgetItem( PyrSlot * );
QVariant toVariant( PyrSlot * );
- int setRect( PyrSlot *, const QRectF & );
- int setPoint( PyrSlot *, const QPointF & );
+ void setRect( PyrSlot *, const QRectF & );
+ void setPoint( PyrSlot *, const QPointF & );
void setSize( PyrSlot *, const QSizeF & );
void setString( PyrSlot *, const QString & );
- int setColor( PyrSlot *, const QColor & );
- int setPalette( PyrSlot *, const QPalette & );
+ void setColor( PyrSlot *, const QColor & );
+ void setPalette( PyrSlot *, const QPalette & );
void setQObject( PyrSlot *, QObject * );
void setTreeWidgetItem( PyrSlot *, const QcTreeWidget::ItemPtr & );
void setVariantList( PyrSlot *, const VariantList& );
- int setVariant( PyrSlot *, const QVariant & );
+ bool setVariant( PyrSlot *, const QVariant & );
};
class Variant
View
15 QtCollider/primitives/prim_QObject.cpp
@@ -297,29 +297,24 @@ QC_LANG_PRIMITIVE( QObject_SetProperty, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g
return errNone;
}
-QC_LANG_PRIMITIVE( QObject_GetProperty, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
+QC_LANG_PRIMITIVE( QObject_GetProperty, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QObjectProxy *proxy = QOBJECT_FROM_SLOT( r );
if( NotSym(a) ) return errWrongType;
PyrSymbol *symProp = slotRawSymbol( a );
- PyrSlot *slotRetExtra = a+1;
qcSCObjectDebugMsg( 1, slotRawObject(r), QString("GET: %1").arg(symProp->name) );
if( !proxy->compareThread() ) return QtCollider::wrongThreadError();
QVariant val = proxy->property( symProp->name );
-
if( !val.isValid() ) return errFailed;
- bool haveExtra = NotNil( slotRetExtra );
- int err = Slot::setVariant( ( haveExtra ? slotRetExtra : r ), val );
- if( err ) return err;
-
- if( haveExtra ) slotCopy( r, slotRetExtra );
-
- return errNone;
+ if( Slot::setVariant(r, val) )
+ return errNone;
+ else
+ return errFailed;
}
QC_LANG_PRIMITIVE( QObject_SetEventHandler, 4, PyrSlot *r, PyrSlot *a, VMGlobals *g )
View
7 QtCollider/primitives/prim_QWidget.cpp
@@ -66,7 +66,7 @@ QC_LANG_PRIMITIVE( QWidget_Refresh, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g ) {
return errNone;
}
-QC_LANG_PRIMITIVE( QWidget_MapToGlobal, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g ) {
+QC_LANG_PRIMITIVE( QWidget_MapToGlobal, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g ) {
QWidgetProxy *proxy = qobject_cast<QWidgetProxy*>( Slot::toObjectProxy( r ) );
if( !proxy->compareThread() ) return QtCollider::wrongThreadError();
@@ -76,10 +76,7 @@ QC_LANG_PRIMITIVE( QWidget_MapToGlobal, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g
QPoint pt( Slot::toPoint( a ).toPoint() );
pt = w->mapToGlobal( pt );
-
- int err = Slot::setPoint( a+1, pt );
- if( err ) return err;
- slotCopy( r, a+1 );
+ Slot::setPoint( r, pt );
return errNone;
}
View
31 QtCollider/primitives/prim_misc.cpp
@@ -50,35 +50,25 @@ QC_LANG_PRIMITIVE( QtGUI_DebugLevel, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
return errNone;
}
-QC_LANG_PRIMITIVE( QWindow_ScreenBounds, 1, PyrSlot *r, PyrSlot *rectSlot, VMGlobals *g )
+QC_LANG_PRIMITIVE( QWindow_ScreenBounds, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
QRect screenGeometry = QApplication::desktop()->screenGeometry();
-
- int err = Slot::setRect( rectSlot, screenGeometry );
- if( err ) return err;
-
- slotCopy( r, rectSlot );
-
+ Slot::setRect( r, screenGeometry );
return errNone;
}
-QC_LANG_PRIMITIVE( QWindow_AvailableGeometry, 1, PyrSlot *r, PyrSlot *rectSlot, VMGlobals *g )
+QC_LANG_PRIMITIVE( QWindow_AvailableGeometry, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
QRect rect = QApplication::desktop()->availableGeometry();
-
- int err = Slot::setRect( rectSlot, rect );
- if( err ) return err;
-
- slotCopy( r, rectSlot );
-
+ Slot::setRect( r, rect );
return errNone;
}
-QC_LANG_PRIMITIVE( Qt_StringBounds, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g )
+QC_LANG_PRIMITIVE( Qt_StringBounds, 2, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
QString str = Slot::toString( a );
@@ -90,9 +80,7 @@ QC_LANG_PRIMITIVE( Qt_StringBounds, 3, PyrSlot *r, PyrSlot *a, VMGlobals *g )
// we keep the font height even on empty string;
if( str.isEmpty() ) bounds.setHeight( fm.height() );
- Slot::setRect( a+2, bounds );
- slotCopy( r, a+2 );
-
+ Slot::setRect( r, bounds );
return errNone;
}
@@ -107,15 +95,12 @@ QC_LANG_PRIMITIVE( Qt_AvailableFonts, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
return errNone;
}
-QC_LANG_PRIMITIVE( Qt_GlobalPalette, 1, PyrSlot *r, PyrSlot *a, VMGlobals *g )
+QC_LANG_PRIMITIVE( Qt_GlobalPalette, 0, PyrSlot *r, PyrSlot *a, VMGlobals *g )
{
if( !QcApplication::compareThread() ) return QtCollider::wrongThreadError();
QPalette p( QApplication::palette() );
-
- if( Slot::setPalette( a, p ) ) return errFailed;
- slotCopy( r, a );
-
+ Slot::setPalette( r, p );
return errNone;
}
View
4 SCClassLibrary/QtCollider/BasicViews.sc
@@ -154,11 +154,11 @@ QScrollView : QAbstractScroll {
}
innerBounds {
- ^this.getProperty( \innerBounds, Rect.new );
+ ^this.getProperty( \innerBounds );
}
visibleOrigin {
- ^this.getProperty( \visibleOrigin, Point.new );
+ ^this.getProperty( \visibleOrigin );
}
visibleOrigin_ { arg point;
View
2 SCClassLibrary/QtCollider/QObject.sc
@@ -95,7 +95,7 @@ QObject {
^this.primitiveFailed
}
- getProperty{ arg property, preAllocatedReturn;
+ getProperty { arg property;
_QObject_GetProperty
^this.primitiveFailed
}
View
2 SCClassLibrary/QtCollider/QScope.sc
@@ -39,7 +39,7 @@ QScope : QView {
this.setProperty( \waveColors, aColorArray );
}
- background { ^this.getProperty( \background, Color.new ); }
+ background { ^this.getProperty( \background ); }
background_ { arg color; this.setProperty( \background, color, true ); }
}
View
4 SCClassLibrary/QtCollider/QSoundFileView.sc
@@ -166,7 +166,7 @@ QSoundFileView : QView {
timeCursorPosition { ^this.getProperty( \cursorPosition ); }
timeCursorPosition_ { arg frame; this.setProperty( \cursorPosition, frame ) }
- timeCursorColor { ^this.getProperty( \cursorColor, Color.new ); }
+ timeCursorColor { ^this.getProperty( \cursorColor ); }
timeCursorColor_ { arg color; this.setProperty( \cursorColor, color ) }
// grid
@@ -180,7 +180,7 @@ QSoundFileView : QView {
gridOffset { ^this.getProperty( \gridOffset ) }
gridOffset_ { arg seconds; this.setProperty( \gridOffset, seconds ) }
- gridColor { ^this.getProperty( \gridColor, Color.new ) }
+ gridColor { ^this.getProperty( \gridColor ) }
gridColor_ { arg color; this.setProperty( \gridColor, color ) }
// actions
View
12 SCClassLibrary/QtCollider/QView.sc
@@ -58,7 +58,8 @@ QView : QObject {
}
mapToGlobal { arg point;
- ^this.prMapToGlobal( point, Point.new );
+ _QWidget_MapToGlobal
+ ^this.primitiveFailed;
}
// ----------------- properties --------------------------
@@ -72,7 +73,7 @@ QView : QObject {
}
palette {
- ^this.getProperty( \palette, QPalette.new.init );
+ ^this.getProperty( \palette );
}
palette_ { arg p;
@@ -98,7 +99,7 @@ QView : QObject {
}
bounds {
- ^this.getProperty(\geometry, Rect.new)
+ ^this.getProperty(\geometry)
}
bounds_ { arg rect;
@@ -686,11 +687,6 @@ QView : QObject {
this.setEventHandlerEnabled( 63, enabled );
}
- prMapToGlobal { arg point, retPoint;
- _QWidget_MapToGlobal
- ^this.primitiveFailed;
- }
-
prSetLayout { arg layout;
_QWidget_SetLayout
^this.primitiveFailed;
View
26 SCClassLibrary/QtCollider/QWindow.sc
@@ -25,13 +25,13 @@ QScrollTopView : QScrollView {
bounds {
var r;
- r = this.getProperty( \geometry, Rect.new );
+ r = this.getProperty( \geometry );
^r.moveTo(0,0);
}
bounds_ { arg rect;
var rNew = rect.asRect;
- var rOld = this.getProperty( \geometry, Rect.new );
+ var rOld = this.getProperty( \geometry );
this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
}
@@ -55,13 +55,13 @@ QTopView : QView {
bounds {
var r;
- r = this.getProperty( \geometry, Rect.new );
+ r = this.getProperty( \geometry );
^r.moveTo(0,0);
}
bounds_ { arg rect;
var rNew = rect.asRect;
- var rOld = this.getProperty( \geometry, Rect.new );
+ var rOld = this.getProperty( \geometry );
this.setProperty( \geometry, rOld.resizeTo( rNew.width, rNew.height ) );
}
@@ -93,11 +93,11 @@ QWindow
}
*screenBounds {
- ^this.prScreenBounds( Rect.new );
+ _QWindow_ScreenBounds
}
*availableBounds {
- ^this.prAvailableBounds( Rect() );
+ _QWindow_AvailableGeometry
}
*closeAll {
@@ -150,12 +150,12 @@ QWindow
}
bounds {
- ^QWindow.flipY( view.getProperty( \geometry, Rect.new ) );
+ ^QWindow.flipY( view.getProperty( \geometry ) );
}
setInnerExtent { arg w, h;
// bypass this.bounds, to avoid QWindow flipping the y coordinate
- var r = view.getProperty(\geometry, Rect.new );
+ var r = view.getProperty(\geometry );
view.setProperty(\geometry, r.resizeTo( w, h ); )
}
@@ -217,16 +217,6 @@ QWindow
^Rect( aRect.left, flippedTop, aRect.width, aRect.height );
}
- *prScreenBounds { arg return;
- _QWindow_ScreenBounds
- ^this.primitiveFailed
- }
-
- *prAvailableBounds { arg return;
- _QWindow_AvailableGeometry
- ^this.primitiveFailed
- }
-
*addWindow { arg window;
allWindows = allWindows.add( window );
}
View
12 SCClassLibrary/QtCollider/QtGUI.sc
@@ -92,14 +92,15 @@ QtGUI {
}
*stringBounds { arg aString, aFont;
- var bounds = this.prStringBounds( aString, aFont, Rect.new );
+ var bounds = this.prStringBounds( aString, aFont );
bounds.left = 0;
bounds.top = 0;
^bounds
}
*palette {
- ^this.prPalette( QPalette.new.init );
+ _Qt_GlobalPalette
+ ^this.primitiveFailed;
}
*palette_ { arg p;
@@ -123,12 +124,7 @@ QtGUI {
// private ///////////////////////////////////////////////////////////
- *prPalette { arg ret;
- _Qt_GlobalPalette
- ^this.primitiveFailed;
- }
-
- *prStringBounds { arg aString, aFont, aRect;
+ *prStringBounds { arg aString, aFont;
_Qt_StringBounds
^this.primitiveFailed
}

0 comments on commit baed293

Please sign in to comment.