diff --git a/README.md b/README.md index 6e4a41243..2a4f5212f 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ Taking the example of QLabel, if you look inside the directory `src/cpp/QtWidget ├── QLabel │   ├── nlabel.cpp │   ├── nlabel.h <---- Extended QLabel -│   ├── nlabel_moc.h <--- Autogenerated file by qt moc. +│   ├── nlabel_moc.cpp <--- Autogenerated file by qt moc. │   ├── qlabel_wrap.cpp │   └── qlabel_wrap.h <--- Wrapper file ``` @@ -201,10 +201,10 @@ The idea is : So if you take a look at NLabel you will see, it inherits from QLabel and YogaWidget. It would in future inherit from more classes that implement event listeners etc. YogaWidget is a class that contains the magic that enables a regular Qt Widget to have Yoga node. A Yoga node is an instance used by yoga library to calculate a widgets position on the screen. Yoga is a library that will layout the widget on the screen. To do so we will specify the flex properties like alignitems, justify content, margin, paddings etc on the Yoga node of the widget. Apart from adding yoga node, YogaWidget adds support for specifying those yoga properties via Qt's stylesheet. (This is done by using Q_PROPERTY). To make this work we need to use something called as Q_OBJECT inside the class which is a C++ macro. Q_OBJECT will be expanded to relevant code by the compiler. In Qt whenever we add Q_OBJECT to a header file, we need to use a pre compiler called Qt MOC (Meta Object Compiler). The way we use it is ``` -moc headername.h -o headername_moc.h +moc headername.h -o headername_moc.cpp ``` -This will run moc on `headername.h` and generate `headername_moc.h`. We will include this file instead of `headername.h`. This is the reason we have `nlabel_moc.h`. If you dont do this. Then it will give a symbol not found error. +This will run moc on `headername.h` and generate `headername_moc.cpp`. We will include this file instead of `headername.h`. This is the reason we have `nlabel_moc.cpp`. If you dont do this. Then it will give a symbol not found error. I hope QLabel's example is enough for now. For more examples and inspirations we can take a look at other wrapped widgets. diff --git a/binding.gyp b/binding.gyp index 9cf78520d..3eec123a5 100644 --- a/binding.gyp +++ b/binding.gyp @@ -1,6 +1,7 @@ { "includes": [ "./config/application.gypi", + "./config/moc.gypi", './config/yoga.gypi' ], "targets": [] diff --git a/config/application.gypi b/config/application.gypi index ee54b02dd..ad39581d0 100644 --- a/config/application.gypi +++ b/config/application.gypi @@ -16,12 +16,10 @@ "../src/cpp/core/YogaWidget/yogawidget.cpp", # wrapped cpps "../src/cpp/QtGui/QApplication/qapplication_wrap.cpp", - "../src/cpp/QtGui/QWidget/nwidget.cpp", "../src/cpp/QtGui/QWidget/qwidget_wrap.cpp", '../src/cpp/core/FlexLayout/flexnode_wrap.cpp', '../src/cpp/core/FlexLayout/flexlayout_wrap.cpp', "../src/cpp/QtWidgets/QGridLayout/qgridlayout_wrap.cpp", - "../src/cpp/QtWidgets/QLabel/nlabel.cpp", "../src/cpp/QtWidgets/QLabel/qlabel_wrap.cpp", "../src/cpp/QtWidgets/QLayout/qlayout_wrap.cpp", "../src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp", diff --git a/config/moc.gypi b/config/moc.gypi new file mode 100644 index 000000000..1804d9034 --- /dev/null +++ b/config/moc.gypi @@ -0,0 +1,9 @@ +{ + "includes": [], + "target_defaults": { + "sources": [ + "../src/cpp/QtGui/QWidget/nwidget_moc.cpp", + "../src/cpp/QtWidgets/QLabel/nlabel_moc.cpp", + ], + } +} diff --git a/config/yoga.gypi b/config/yoga.gypi index 3073d859c..719226fde 100644 --- a/config/yoga.gypi +++ b/config/yoga.gypi @@ -16,5 +16,4 @@ "../deps/yoga/event/event.cpp", ], } - } diff --git a/src/cpp/QtGui/QWidget/nwidget.cpp b/src/cpp/QtGui/QWidget/nwidget.cpp deleted file mode 100644 index 9ee4cc97f..000000000 --- a/src/cpp/QtGui/QWidget/nwidget.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "nwidget_moc.h" \ No newline at end of file diff --git a/src/cpp/QtGui/QWidget/nwidget_moc.h b/src/cpp/QtGui/QWidget/nwidget_moc.cpp similarity index 100% rename from src/cpp/QtGui/QWidget/nwidget_moc.h rename to src/cpp/QtGui/QWidget/nwidget_moc.cpp diff --git a/src/cpp/QtWidgets/QLabel/nlabel.cpp b/src/cpp/QtWidgets/QLabel/nlabel.cpp deleted file mode 100644 index 2482ae4f9..000000000 --- a/src/cpp/QtWidgets/QLabel/nlabel.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "nlabel_moc.h" \ No newline at end of file diff --git a/src/cpp/QtWidgets/QLabel/nlabel_moc.h b/src/cpp/QtWidgets/QLabel/nlabel_moc.cpp similarity index 100% rename from src/cpp/QtWidgets/QLabel/nlabel_moc.h rename to src/cpp/QtWidgets/QLabel/nlabel_moc.cpp