getWidgetText added

This commit is contained in:
Syping 2018-08-24 17:45:33 +02:00
parent ad1505251d
commit 3e88d70c23
3 changed files with 27 additions and 0 deletions

View file

@ -76,6 +76,9 @@ end
function closeDialog(pushButton) function closeDialog(pushButton)
disconnect(pushButton, "clicked()") disconnect(pushButton, "clicked()")
if not (getWidgetText(dialogLineEdit) == "") then
showMessageBox(InfoMessageBox, "You typed: " .. getWidgetText(dialogLineEdit), "LuaEngine", getParent(pushButton))
end
closeWidget(getParent(pushButton)) closeWidget(getParent(pushButton))
end end

View file

@ -59,6 +59,7 @@ void LuaEngineGui::pushClass(lua_State *L_p)
pushFunction(L_p, "closeWidget", closeWidget); pushFunction(L_p, "closeWidget", closeWidget);
pushFunction(L_p, "executeWidget", executeWidget); pushFunction(L_p, "executeWidget", executeWidget);
pushFunction(L_p, "showWidget", showWidget); pushFunction(L_p, "showWidget", showWidget);
pushFunction(L_p, "getWidgetText", getWidgetText);
pushFunction(L_p, "setWidgetLayout", setWidgetLayout); pushFunction(L_p, "setWidgetLayout", setWidgetLayout);
pushVariant(L_p, "ShowCurrent", 0); pushVariant(L_p, "ShowCurrent", 0);
pushVariant(L_p, "ShowNormal", 1); pushVariant(L_p, "ShowNormal", 1);
@ -596,6 +597,28 @@ int LuaEngineGui::getParent(lua_State *L_p)
return 0; return 0;
} }
int LuaEngineGui::getWidgetText(lua_State *L_p)
{
if (getArgumentCount(L_p) >= 1) {
void *pointer = getPointer(L_p, 1);
if (pointer != NULL) {
if (((QObject*)pointer)->inherits("QLabel")) {
pushVariant(L_p, ((QLabel*)pointer)->text());
return 1;
}
else if (((QObject*)pointer)->inherits("QLineEdit")) {
pushVariant(L_p, ((QLineEdit*)pointer)->text());
return 1;
}
else if (((QObject*)pointer)->inherits("QWidget")) {
pushVariant(L_p, ((QWidget*)pointer)->windowTitle());
return 1;
}
}
}
return 0;
}
QString LuaEngineGui::nameForPointer(void *pointer) QString LuaEngineGui::nameForPointer(void *pointer)
{ {
QString nameStorage; QString nameStorage;

View file

@ -51,6 +51,7 @@ public:
static int createPushButton(lua_State *L_p); static int createPushButton(lua_State *L_p);
static int createSpacerItem(lua_State *L_p); static int createSpacerItem(lua_State *L_p);
static int getParent(lua_State *L_p); static int getParent(lua_State *L_p);
static int getWidgetText(lua_State *L_p);
private: private:
lua_State *L; lua_State *L;