most calls don't care if the widget has a layout, so make this behaviour controllable by the caller

svn path=/trunk/KDE/kdebase/runtime/; revision=1097162
This commit is contained in:
Aaron J. Seigo 2010-02-28 15:32:21 +00:00
parent 3ce97e4d1d
commit b03d2dc7bd
3 changed files with 8 additions and 8 deletions

View File

@ -43,11 +43,11 @@ DECLARE_VOID_NUMBER_METHOD(QGraphicsAnchorLayout, removeAt)
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
QGraphicsLayoutItem *extractLayoutItem (QScriptContext *ctx, int index = 0); QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false);
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{ {
QGraphicsLayoutItem *parent = extractLayoutItem(ctx); QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true);
//FIXME: don't leak memory when parent is 0 //FIXME: don't leak memory when parent is 0
return qScriptValueFromValue(eng, new QGraphicsAnchorLayout(parent)); return qScriptValueFromValue(eng, new QGraphicsAnchorLayout(parent));
} }

View File

@ -72,11 +72,11 @@ DECLARE_INT_NUMBER_SET_METHOD(QGraphicsGridLayout, setColumnFixedWidth)
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0); QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false);
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{ {
QGraphicsLayoutItem *parent = extractLayoutItem(ctx); QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true);
//FIXME: don't leak memory when parent is 0 //FIXME: don't leak memory when parent is 0
return qScriptValueFromValue(eng, new QGraphicsGridLayout(parent)); return qScriptValueFromValue(eng, new QGraphicsGridLayout(parent));
} }

View File

@ -47,7 +47,7 @@ DECLARE_VOID_QUAD_NUMBER_METHOD(QGraphicsLinearLayout, setContentsMargins)
///////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////
// Q_DECLARE_METATYPE(QGraphicsLayoutItem*) // Q_DECLARE_METATYPE(QGraphicsLayoutItem*)
QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0) QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0, bool noExistingLayout = false)
{ {
QScriptValue v = ctx->argument(index); QScriptValue v = ctx->argument(index);
if (ctx->argumentCount() == 0 || v.isQObject()) { if (ctx->argumentCount() == 0 || v.isQObject()) {
@ -64,7 +64,7 @@ QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0)
} }
} }
if (w->layout()) { if (noExistingLayout && w->layout()) {
return 0; return 0;
} }
@ -93,7 +93,7 @@ QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0)
} }
QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(item); QGraphicsWidget *w = dynamic_cast<QGraphicsWidget *>(item);
if (w && w->layout()) { if (noExistingLayout && w && w->layout()) {
return 0; return 0;
} }
@ -102,7 +102,7 @@ QGraphicsLayoutItem *extractLayoutItem(QScriptContext *ctx, int index = 0)
static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng) static QScriptValue ctor(QScriptContext *ctx, QScriptEngine *eng)
{ {
QGraphicsLayoutItem *parent = extractLayoutItem(ctx); QGraphicsLayoutItem *parent = extractLayoutItem(ctx, 0, true);
//FIXME: don't leak memory when parent is 0 //FIXME: don't leak memory when parent is 0
return qScriptValueFromValue(eng, new QGraphicsLinearLayout(parent)); return qScriptValueFromValue(eng, new QGraphicsLinearLayout(parent));
} }