+ createListItem, createListView, getObjectParent, LEListWidgetItem,

setParent -> setObjectParent
This commit is contained in:
Syping 2020-05-19 20:50:03 +02:00
parent ff28849d90
commit fcabd1685d
7 changed files with 216 additions and 33 deletions

View file

@ -31,9 +31,10 @@ LuaEngine::LuaEngine(QObject *parent, bool loadBaseLibraries) : QObject(parent)
pushVariant("DeleteInstant", 0);
pushVariant("DeleteLater", 1);
pushFunction("delete", luaObjectDelete_p);
pushFunction("getParent", luaObjectParent_p);
pushFunction("connect", luaTriggerConnect_p);
pushFunction("disconnect", luaTriggerDisconnect_p);
pushFunction("getObjectParent", luaObjectGetParent_p);
pushFunction("setObjectParent", luaObjectSetParent_p);
pushFunction("luaEngineVersion", luaEngineVersion_p);
pushFunction("luaEnginePlatform", luaEnginePlatform_p);
}
@ -427,7 +428,7 @@ int LuaEngine::luaObjectDelete_p(lua_State *L_p)
return 0;
}
int LuaEngine::luaObjectParent_p(lua_State *L_p)
int LuaEngine::luaObjectGetParent_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
@ -439,6 +440,18 @@ int LuaEngine::luaObjectParent_p(lua_State *L_p)
return 0;
}
int LuaEngine::luaObjectSetParent_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 2) {
void *o_pointer = getPointer(L_p, 1);
void *p_pointer = getPointer(L_p, 2);
if (o_pointer != NULL && p_pointer != NULL && ((QObject*)o_pointer)->inherits("QObject") && ((QObject*)p_pointer)->inherits("QObject")) {
((QObject*)o_pointer)->setParent((QObject*)p_pointer);
}
}
return 0;
}
int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 3) {
@ -455,7 +468,7 @@ int LuaEngine::luaTriggerConnect_p(lua_State *L_p)
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), getVariant(L_p, 3).toString());
engine->setProperty(funcStorage.toUtf8().data(), getVariant(L_p, 3));
QObject::connect(object, signal, engine, slot);
}
}
@ -480,7 +493,7 @@ int LuaEngine::luaTriggerDisconnect_p(lua_State *L_p)
QMetaMethod slot = engine->metaObject()->method(slotIndex);
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << object << "_" << signal.name();
pushVariant(L_p, funcStorage.toUtf8().data(), QVariant());
engine->setProperty(funcStorage.toUtf8().data(), QVariant());
QObject::disconnect(object, signal, engine, slot);
}
}
@ -494,6 +507,6 @@ void LuaEngine::luaTriggerSlot_p()
QMetaMethod signal = sender()->metaObject()->method(senderSignalIndex());
QString funcStorage;
QTextStream(&funcStorage) << "__ConnectFunc_" << sender() << "_" << signal.name();
QString luaConnectFunc = getVariant(funcStorage.toUtf8().data()).toString();
QString luaConnectFunc = property(funcStorage.toUtf8().data()).toString();
executeLuaFunction(luaConnectFunc.toUtf8().data(), QVariant::fromValue((void*)sender()));
}

View file

@ -82,7 +82,8 @@ private:
static int luaEngineVersion_p(lua_State *L_p);
static int luaEnginePlatform_p(lua_State *L_p);
static int luaObjectDelete_p(lua_State *L_p);
static int luaObjectParent_p(lua_State *L_p);
static int luaObjectGetParent_p(lua_State *L_p);
static int luaObjectSetParent_p(lua_State *L_p);
static int luaTriggerConnect_p(lua_State *L_p);
static int luaTriggerDisconnect_p(lua_State *L_p);