From 085c05dd85037503bf3e686be77e5b3c2ebba028 Mon Sep 17 00:00:00 2001 From: Atul R Date: Sun, 16 Jun 2019 15:55:17 +0200 Subject: [PATCH] Organised code so that its easier to modify all widgets at once. --- config/moc.json | 2 +- src/cpp/QtWidgets/QCheckBox/ncheckbox.h | 10 +++----- src/cpp/QtWidgets/QLabel/nlabel.h | 10 +++----- src/cpp/QtWidgets/QLineEdit/nlineedit.h | 10 +++----- src/cpp/QtWidgets/QMainWindow/nmainwindow.h | 15 ++++------- src/cpp/QtWidgets/QProgressBar/nprogressbar.h | 10 +++----- src/cpp/QtWidgets/QPushButton/npushbutton.h | 15 +++-------- src/cpp/QtWidgets/QRadioButton/nradiobutton.h | 12 +++------ src/cpp/autogen/ncheckbox_moc.cpp | 6 ++--- src/cpp/autogen/nlabel_moc.cpp | 6 ++--- src/cpp/autogen/nlineedit_moc.cpp | 6 ++--- src/cpp/autogen/nmainwindow_moc.cpp | 6 ++--- src/cpp/autogen/nprogressbar_moc.cpp | 6 ++--- src/cpp/autogen/npushbutton_moc.cpp | 6 ++--- src/cpp/autogen/nradiobutton_moc.cpp | 6 ++--- src/cpp/core/NodeWidget/nodewidget.h | 25 +++++++++++++++++++ 16 files changed, 65 insertions(+), 86 deletions(-) create mode 100644 src/cpp/core/NodeWidget/nodewidget.h diff --git a/config/moc.json b/config/moc.json index 9c3de2d41..92a120e1d 100644 --- a/config/moc.json +++ b/config/moc.json @@ -1,5 +1,5 @@ { - "include": "src/cpp/core/YogaWidget/yogawidget.h", + "include": "src/cpp/core/NodeWidget/nodewidget.h", "headers": [ "src/cpp/QtGui/QWidget/nwidget.h", "src/cpp/QtWidgets/QLabel/nlabel.h", diff --git a/src/cpp/QtWidgets/QCheckBox/ncheckbox.h b/src/cpp/QtWidgets/QCheckBox/ncheckbox.h index 305f5d54c..5213f9f5e 100644 --- a/src/cpp/QtWidgets/QCheckBox/ncheckbox.h +++ b/src/cpp/QtWidgets/QCheckBox/ncheckbox.h @@ -1,17 +1,13 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" -class NCheckBox: public QCheckBox, public YogaWidget, public EventWidget +class NCheckBox: public QCheckBox, public NodeWidget { - + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QCheckBox::QCheckBox; //inherit all constructors of QCheckBox - Q_OBJECT }; diff --git a/src/cpp/QtWidgets/QLabel/nlabel.h b/src/cpp/QtWidgets/QLabel/nlabel.h index 586afc6f5..830d9491e 100644 --- a/src/cpp/QtWidgets/QLabel/nlabel.h +++ b/src/cpp/QtWidgets/QLabel/nlabel.h @@ -1,17 +1,13 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" -class NLabel: public QLabel, public YogaWidget, public EventWidget +class NLabel: public QLabel, public NodeWidget { - + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QLabel::QLabel; //inherit all constructors of QLabel - Q_OBJECT }; diff --git a/src/cpp/QtWidgets/QLineEdit/nlineedit.h b/src/cpp/QtWidgets/QLineEdit/nlineedit.h index 0d7c5a2d9..20aea2f41 100644 --- a/src/cpp/QtWidgets/QLineEdit/nlineedit.h +++ b/src/cpp/QtWidgets/QLineEdit/nlineedit.h @@ -1,17 +1,13 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" -class NLineEdit: public QLineEdit, public YogaWidget, public EventWidget +class NLineEdit: public QLineEdit, public NodeWidget { - + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QLineEdit::QLineEdit; //inherit all constructors of QLineEdit - Q_OBJECT }; diff --git a/src/cpp/QtWidgets/QMainWindow/nmainwindow.h b/src/cpp/QtWidgets/QMainWindow/nmainwindow.h index 364423a22..dc57de4c3 100644 --- a/src/cpp/QtWidgets/QMainWindow/nmainwindow.h +++ b/src/cpp/QtWidgets/QMainWindow/nmainwindow.h @@ -1,15 +1,14 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" -#include "deps/spdlog/spdlog.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" #include -class NMainWindow: public QMainWindow, public YogaWidget, public EventWidget +class NMainWindow: public QMainWindow, public NodeWidget { - + NODEWIDGET_IMPLEMENTATIONS +public: + using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow private: void calculateLayout(){ YGDirection direction = YGNodeStyleGetDirection(this->getFlexNode()); @@ -28,10 +27,6 @@ private: void resizeEvent(QResizeEvent * event){ calculateLayout(); } -public: - SET_YOGA_WIDGET_Q_PROPERTIES - using QMainWindow::QMainWindow; //inherit all constructors of QMainWindow - Q_OBJECT }; diff --git a/src/cpp/QtWidgets/QProgressBar/nprogressbar.h b/src/cpp/QtWidgets/QProgressBar/nprogressbar.h index 74922c0ab..55141aa71 100644 --- a/src/cpp/QtWidgets/QProgressBar/nprogressbar.h +++ b/src/cpp/QtWidgets/QProgressBar/nprogressbar.h @@ -1,17 +1,13 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" -class NProgressBar: public QProgressBar, public YogaWidget, public EventWidget +class NProgressBar: public QProgressBar, public NodeWidget { - + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QProgressBar::QProgressBar; //inherit all constructors of QProgressBar - Q_OBJECT }; diff --git a/src/cpp/QtWidgets/QPushButton/npushbutton.h b/src/cpp/QtWidgets/QPushButton/npushbutton.h index 5dff14bd4..d6aec88c8 100644 --- a/src/cpp/QtWidgets/QPushButton/npushbutton.h +++ b/src/cpp/QtWidgets/QPushButton/npushbutton.h @@ -1,23 +1,16 @@ #pragma once #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" +#include "src/cpp/core/NodeWidget/nodewidget.h" #include "napi.h" -class NPushButton: public QPushButton, public YogaWidget, public EventWidget +class NPushButton: public QPushButton, public NodeWidget { + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QPushButton::QPushButton; //inherit all constructors of QPushButton - Q_OBJECT -public: - bool event(QEvent* event){ - EventWidget::event(event); - return QWidget::event(event); - } - void connectWidgetSignalsToEventEmitter(){ + void connectWidgetSignalsToEventEmitter() { // Qt Connects: Implement all signal connects here QObject::connect(this, &QPushButton::clicked, [=](bool checked) { this->emitOnNode->call([=](Napi::Env env, std::vector& args) { diff --git a/src/cpp/QtWidgets/QRadioButton/nradiobutton.h b/src/cpp/QtWidgets/QRadioButton/nradiobutton.h index d8ce1fc05..a126665d8 100644 --- a/src/cpp/QtWidgets/QRadioButton/nradiobutton.h +++ b/src/cpp/QtWidgets/QRadioButton/nradiobutton.h @@ -1,17 +1,13 @@ #pragma once -#include #include -#include "src/cpp/core/YogaWidget/yogawidget.h" -#include "src/cpp/core/Events/eventwidget.h" - -class NRadioButton: public QRadioButton, public YogaWidget, public EventWidget -{ +#include "src/cpp/core/NodeWidget/nodewidget.h" +class NRadioButton: public QRadioButton, public NodeWidget +{ + NODEWIDGET_IMPLEMENTATIONS public: - SET_YOGA_WIDGET_Q_PROPERTIES using QRadioButton::QRadioButton; //inherit all constructors of QRadioButton - Q_OBJECT }; diff --git a/src/cpp/autogen/ncheckbox_moc.cpp b/src/cpp/autogen/ncheckbox_moc.cpp index 4b4475934..185164613 100644 --- a/src/cpp/autogen/ncheckbox_moc.cpp +++ b/src/cpp/autogen/ncheckbox_moc.cpp @@ -292,10 +292,8 @@ void *NCheckBox::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NCheckBox.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QCheckBox::qt_metacast(_clname); } diff --git a/src/cpp/autogen/nlabel_moc.cpp b/src/cpp/autogen/nlabel_moc.cpp index 939897a7f..9e5179448 100644 --- a/src/cpp/autogen/nlabel_moc.cpp +++ b/src/cpp/autogen/nlabel_moc.cpp @@ -292,10 +292,8 @@ void *NLabel::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NLabel.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QLabel::qt_metacast(_clname); } diff --git a/src/cpp/autogen/nlineedit_moc.cpp b/src/cpp/autogen/nlineedit_moc.cpp index 617545522..fef87b361 100644 --- a/src/cpp/autogen/nlineedit_moc.cpp +++ b/src/cpp/autogen/nlineedit_moc.cpp @@ -292,10 +292,8 @@ void *NLineEdit::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NLineEdit.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QLineEdit::qt_metacast(_clname); } diff --git a/src/cpp/autogen/nmainwindow_moc.cpp b/src/cpp/autogen/nmainwindow_moc.cpp index 37f824e0e..67d92dcd4 100644 --- a/src/cpp/autogen/nmainwindow_moc.cpp +++ b/src/cpp/autogen/nmainwindow_moc.cpp @@ -292,10 +292,8 @@ void *NMainWindow::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NMainWindow.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QMainWindow::qt_metacast(_clname); } diff --git a/src/cpp/autogen/nprogressbar_moc.cpp b/src/cpp/autogen/nprogressbar_moc.cpp index 7ab6b8b83..4b30b1a95 100644 --- a/src/cpp/autogen/nprogressbar_moc.cpp +++ b/src/cpp/autogen/nprogressbar_moc.cpp @@ -292,10 +292,8 @@ void *NProgressBar::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NProgressBar.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QProgressBar::qt_metacast(_clname); } diff --git a/src/cpp/autogen/npushbutton_moc.cpp b/src/cpp/autogen/npushbutton_moc.cpp index 2bc4d8315..edd37858a 100644 --- a/src/cpp/autogen/npushbutton_moc.cpp +++ b/src/cpp/autogen/npushbutton_moc.cpp @@ -292,10 +292,8 @@ void *NPushButton::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NPushButton.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QPushButton::qt_metacast(_clname); } diff --git a/src/cpp/autogen/nradiobutton_moc.cpp b/src/cpp/autogen/nradiobutton_moc.cpp index ad044e986..3ac3c521e 100644 --- a/src/cpp/autogen/nradiobutton_moc.cpp +++ b/src/cpp/autogen/nradiobutton_moc.cpp @@ -292,10 +292,8 @@ void *NRadioButton::qt_metacast(const char *_clname) if (!_clname) return nullptr; if (!strcmp(_clname, qt_meta_stringdata_NRadioButton.stringdata0)) return static_cast(this); - if (!strcmp(_clname, "YogaWidget")) - return static_cast< YogaWidget*>(this); - if (!strcmp(_clname, "EventWidget")) - return static_cast< EventWidget*>(this); + if (!strcmp(_clname, "NodeWidget")) + return static_cast< NodeWidget*>(this); return QRadioButton::qt_metacast(_clname); } diff --git a/src/cpp/core/NodeWidget/nodewidget.h b/src/cpp/core/NodeWidget/nodewidget.h new file mode 100644 index 000000000..1eb78081f --- /dev/null +++ b/src/cpp/core/NodeWidget/nodewidget.h @@ -0,0 +1,25 @@ +#pragma once +#include "src/cpp/core/YogaWidget/yogawidget.h" +#include "src/cpp/core/Events/eventwidget.h" + +// class to unify all the custom features + add extra features if needed +class NodeWidget : public YogaWidget, public EventWidget { + +}; + + + +#ifndef NODEWIDGET_IMPLEMENTATIONS +#define NODEWIDGET_IMPLEMENTATIONS \ +\ +Q_OBJECT \ +public: \ + SET_YOGA_WIDGET_Q_PROPERTIES \ + bool event(QEvent* event) { \ + EventWidget::event(event); \ + return QWidget::event(event); \ + } \ + +#endif //NODEWIDGET_IMPLEMENTATIONS + + \ No newline at end of file