mirror of
https://gitlab.com/Syping/luaengineapp.git
synced 2024-12-22 20:05:30 +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) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
labelText = getVariant(L_p, 1).toString();
|
labelText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QCheckBox *checkBox = new QCheckBox(parent);
|
QCheckBox *checkBox = new QCheckBox(parent);
|
||||||
|
@ -779,20 +766,7 @@ int LuaEngineGui::createGroupBox(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
groupBoxTitle = getVariant(L_p, 1).toString();
|
groupBoxTitle = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QGroupBox *groupBox = new QGroupBox(parent);
|
QGroupBox *groupBox = new QGroupBox(parent);
|
||||||
|
@ -813,20 +787,7 @@ int LuaEngineGui::createLabel(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
labelText = getVariant(L_p, 1).toString();
|
labelText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QLabel *label = new QLabel(parent);
|
QLabel *label = new QLabel(parent);
|
||||||
|
@ -888,20 +849,7 @@ int LuaEngineGui::createLineEdit(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
editText = getVariant(L_p, 1).toString();
|
editText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QLineEdit *lineEdit = new QLineEdit(parent);
|
QLineEdit *lineEdit = new QLineEdit(parent);
|
||||||
|
@ -1022,20 +970,7 @@ int LuaEngineGui::createPlainTextEdit(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
editText = getVariant(L_p, 1).toString();
|
editText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPlainTextEdit *textEdit = new QPlainTextEdit(parent);
|
QPlainTextEdit *textEdit = new QPlainTextEdit(parent);
|
||||||
|
@ -1058,20 +993,7 @@ int LuaEngineGui::createProgressBar(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
value = getVariant(L_p, 1).toInt();
|
value = getVariant(L_p, 1).toInt();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (getArgumentCount(L_p) >= 4) {
|
if (getArgumentCount(L_p) >= 4) {
|
||||||
minValue = getVariant(L_p, 3).toInt();
|
minValue = getVariant(L_p, 3).toInt();
|
||||||
maxValue = getVariant(L_p, 4).toInt();
|
maxValue = getVariant(L_p, 4).toInt();
|
||||||
|
@ -1098,20 +1020,7 @@ int LuaEngineGui::createPushButton(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
buttonText = getVariant(L_p, 1).toString();
|
buttonText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QPushButton *pushButton = new QPushButton(parent);
|
QPushButton *pushButton = new QPushButton(parent);
|
||||||
|
@ -1132,20 +1041,7 @@ int LuaEngineGui::createRadioButton(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
labelText = getVariant(L_p, 1).toString();
|
labelText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QRadioButton *radioButton = new QRadioButton(parent);
|
QRadioButton *radioButton = new QRadioButton(parent);
|
||||||
|
@ -1187,20 +1083,7 @@ int LuaEngineGui::createTabBar(lua_State *L_p)
|
||||||
QLayout *layout = nullptr;
|
QLayout *layout = nullptr;
|
||||||
QWidget *parent = nullptr;
|
QWidget *parent = nullptr;
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
void *pointer = getPointer(L_p, 1);
|
lpForPointer(getPointer(L_p, 1), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
QTabWidget *tabWidget = new QTabWidget(parent);
|
QTabWidget *tabWidget = new QTabWidget(parent);
|
||||||
tabWidget->setObjectName(nameForPointer(tabWidget));
|
tabWidget->setObjectName(nameForPointer(tabWidget));
|
||||||
|
@ -1219,20 +1102,7 @@ int LuaEngineGui::createTextEdit(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
editText = getVariant(L_p, 1).toString();
|
editText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QTextEdit *textEdit = new QTextEdit(parent);
|
QTextEdit *textEdit = new QTextEdit(parent);
|
||||||
|
@ -1253,20 +1123,7 @@ int LuaEngineGui::createToolButton(lua_State *L_p)
|
||||||
if (getArgumentCount(L_p) >= 1) {
|
if (getArgumentCount(L_p) >= 1) {
|
||||||
buttonText = getVariant(L_p, 1).toString();
|
buttonText = getVariant(L_p, 1).toString();
|
||||||
if (getArgumentCount(L_p) >= 2) {
|
if (getArgumentCount(L_p) >= 2) {
|
||||||
void *pointer = getPointer(L_p, 2);
|
lpForPointer(getPointer(L_p, 2), layout, 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QToolButton *toolButton = new QToolButton(parent);
|
QToolButton *toolButton = new QToolButton(parent);
|
||||||
|
@ -1421,6 +1278,23 @@ QWidget* LuaEngineGui::windowForObject(QObject *object)
|
||||||
return nullptr;
|
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 LuaEngineGui::nameForPointer(void *pointer)
|
||||||
{
|
{
|
||||||
QString nameStorage;
|
QString nameStorage;
|
||||||
|
|
|
@ -21,8 +21,9 @@
|
||||||
#include "LuaEngineGui_global.h"
|
#include "LuaEngineGui_global.h"
|
||||||
#include "LuaEngine.h"
|
#include "LuaEngine.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QString>
|
#include <QLayout>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class LUAENGINEGUISHARED_EXPORT LuaEngineGui : public LuaEngine
|
class LUAENGINEGUISHARED_EXPORT LuaEngineGui : public LuaEngine
|
||||||
{
|
{
|
||||||
|
@ -80,8 +81,9 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
static QString nameForPointer(void *pointer);
|
|
||||||
static QWidget* windowForObject(QObject *object);
|
static QWidget* windowForObject(QObject *object);
|
||||||
|
static void lpForPointer(void *pointer, QLayout *layout, QWidget *parent);
|
||||||
|
static QString nameForPointer(void *pointer);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LUAENGINEGUI_H
|
#endif // LUAENGINEGUI_H
|
||||||
|
|
Loading…
Reference in a new issue