mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 11:55:29 +01:00
decrease repeating code
This commit is contained in:
parent
2cb833995a
commit
8aac85e99b
2 changed files with 32 additions and 156 deletions
|
@ -720,20 +720,7 @@ int LuaEngineGui::createCheckBox(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
labelText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QCheckBox *checkBox = new QCheckBox(parent);
|
||||
|
@ -779,20 +766,7 @@ int LuaEngineGui::createGroupBox(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
groupBoxTitle = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QGroupBox *groupBox = new QGroupBox(parent);
|
||||
|
@ -813,20 +787,7 @@ int LuaEngineGui::createLabel(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
labelText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QLabel *label = new QLabel(parent);
|
||||
|
@ -888,20 +849,7 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QLineEdit *lineEdit = new QLineEdit(parent);
|
||||
|
@ -1022,20 +970,7 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QPlainTextEdit *textEdit = new QPlainTextEdit(parent);
|
||||
|
@ -1058,20 +993,7 @@ int LuaEngineGui::createProgressBar(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
value = getVariant(L_p, 1).toInt();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
if (getArgumentCount(L_p) >= 4) {
|
||||
minValue = getVariant(L_p, 3).toInt();
|
||||
maxValue = getVariant(L_p, 4).toInt();
|
||||
|
@ -1098,20 +1020,7 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
buttonText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QPushButton *pushButton = new QPushButton(parent);
|
||||
|
@ -1132,20 +1041,7 @@ int LuaEngineGui::createRadioButton(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
labelText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QRadioButton *radioButton = new QRadioButton(parent);
|
||||
|
@ -1187,20 +1083,7 @@ int LuaEngineGui::createTabBar(lua_State *L_p)
|
|||
QLayout *layout = nullptr;
|
||||
QWidget *parent = nullptr;
|
||||
if (getArgumentCount(L_p) >= 1) {
|
||||
void *pointer = getPointer(L_p, 1);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 1), layout, parent);
|
||||
}
|
||||
QTabWidget *tabWidget = new QTabWidget(parent);
|
||||
tabWidget->setObjectName(nameForPointer(tabWidget));
|
||||
|
@ -1219,20 +1102,7 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
editText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QTextEdit *textEdit = new QTextEdit(parent);
|
||||
|
@ -1253,20 +1123,7 @@ int LuaEngineGui::createToolButton(lua_State *L_p)
|
|||
if (getArgumentCount(L_p) >= 1) {
|
||||
buttonText = getVariant(L_p, 1).toString();
|
||||
if (getArgumentCount(L_p) >= 2) {
|
||||
void *pointer = getPointer(L_p, 2);
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
lpForPointer(getPointer(L_p, 2), layout, parent);
|
||||
}
|
||||
}
|
||||
QToolButton *toolButton = new QToolButton(parent);
|
||||
|
@ -1421,6 +1278,23 @@ QWidget* LuaEngineGui::windowForObject(QObject *object)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void LuaEngineGui::lpForPointer(void *pointer, QLayout *layout, QWidget *parent)
|
||||
{
|
||||
if (pointer != NULL && ((QObject*)pointer)->inherits("QMainWindow")) {
|
||||
parent = ((QMainWindow*)pointer)->centralWidget();
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QWidget")) {
|
||||
parent = (QWidget*)pointer;
|
||||
}
|
||||
else if (pointer != NULL && ((QObject*)pointer)->inherits("QLayout")) {
|
||||
QWidget *widget = windowForObject((QObject*)pointer);
|
||||
if (widget != nullptr) {
|
||||
layout = (QLayout*)pointer;
|
||||
parent = widget;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString LuaEngineGui::nameForPointer(void *pointer)
|
||||
{
|
||||
QString nameStorage;
|
||||
|
|
|
@ -21,8 +21,9 @@
|
|||
#include "LuaEngineGui_global.h"
|
||||
#include "LuaEngine.h"
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include <QLayout>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class LUAENGINEGUISHARED_EXPORT LuaEngineGui : public LuaEngine
|
||||
{
|
||||
|
@ -80,8 +81,9 @@ public:
|
|||
|
||||
private:
|
||||
lua_State *L;
|
||||
static QString nameForPointer(void *pointer);
|
||||
static QWidget* windowForObject(QObject *object);
|
||||
static void lpForPointer(void *pointer, QLayout *layout, QWidget *parent);
|
||||
static QString nameForPointer(void *pointer);
|
||||
};
|
||||
|
||||
#endif // LUAENGINEGUI_H
|
||||
|
|
Loading…
Reference in a new issue