MOC is working with macros now.

This commit is contained in:
Atul R 2019-06-06 15:13:24 +02:00
parent 7706a8d697
commit eaa9c55390
4 changed files with 12 additions and 99 deletions

View File

@ -201,7 +201,13 @@ 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.cpp
moc headername.h -o headername_moc.cpp --include <any_include_file_which_contains_macro> // example : ../../core/YogaWidget/yogawidget.h
```
So for nlabel I would run it as:
```
moc nlabel.h -o nlabel_moc.cpp --include ../../core/YogaWidget/yogawidget.h
```
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.
@ -232,8 +238,8 @@ MIT
**MOC related**
- Qt's moc doesnt work with macros well if used separately. Current work around is to not use a macro in file having Q_OBJECT.
This invloves copy pasting a big chunck of code. Need to find a fix for that.
- ~Qt's moc doesnt work with macros well if used separately. Current work around is to not use a macro in file having Q_OBJECT.
This invloves copy pasting a big chunck of code. Need to find a fix for that.~
- Auto run qt's moc on files having Q_OBJECT
**Debug logs**

View File

@ -7,53 +7,7 @@ class NWidget: public QWidget, public YogaWidget
{
public:
// SET_YOGA_WIDGET_Q_PROPERTIES
Q_PROPERTY(QString display MEMBER _yDisplay WRITE setYDisplay)
Q_PROPERTY(QString alignItems MEMBER _yAlignItems WRITE setYAlignItems)
Q_PROPERTY(QString alignContent MEMBER _yAlignContent WRITE setYAlignContent)
Q_PROPERTY(QString alignSelf MEMBER _yAlignSelf WRITE setYAlignSelf)
Q_PROPERTY(QString justifyContent MEMBER _yJustifyContent WRITE setYJustifyContent)
Q_PROPERTY(QString direction MEMBER _yDirection WRITE setYDirection)
Q_PROPERTY(QString flexDirection MEMBER _yFlexDirection WRITE setYFlexDirection)
Q_PROPERTY(QString overflow MEMBER _yOverflow WRITE setYOverflow)
Q_PROPERTY(QString position MEMBER _yPosition WRITE setYPosition)
Q_PROPERTY(QString flexWrap MEMBER _yFlexWrap WRITE setYFlexWrap)
Q_PROPERTY(float flex MEMBER _yFlex WRITE setYFlex)
Q_PROPERTY(float flexGrow MEMBER _yFlexGrow WRITE setYFlexGrow)
Q_PROPERTY(float flexShrink MEMBER _yFlexShrink WRITE setYFlexShrink)
Q_PROPERTY(float aspectRatio MEMBER _yAspectRatio WRITE setYAspectRatio)
Q_PROPERTY(QString top MEMBER _yTop WRITE setYNodeTop)
Q_PROPERTY(QString right MEMBER _yRight WRITE setYNodeRight)
Q_PROPERTY(QString bottom MEMBER _yBottom WRITE setYNodeBottom)
Q_PROPERTY(QString left MEMBER _yLeft WRITE setYNodeLeft)
Q_PROPERTY(QString flexBasis MEMBER _yFlexBasis WRITE setYFlexBasis)
Q_PROPERTY(QString minWidth MEMBER _yMinWidth WRITE setYMinWidth)
Q_PROPERTY(QString minHeight MEMBER _yMinHeight WRITE setYMinHeight)
Q_PROPERTY(QString maxWidth MEMBER _yMaxWidth WRITE setYMaxWidth)
Q_PROPERTY(QString maxHeight MEMBER _yMaxHeight WRITE setYMaxHeight)
Q_PROPERTY(QString paddingTop MEMBER _yPaddingTop WRITE setYPaddingTop)
Q_PROPERTY(QString paddingRight MEMBER _yPaddingRight WRITE setYPaddingRight)
Q_PROPERTY(QString paddingBottom MEMBER _yPaddingBottom WRITE setYPaddingBottom)
Q_PROPERTY(QString paddingLeft MEMBER _yPaddingLeft WRITE setYPaddingLeft)
Q_PROPERTY(QString paddingHorizontal MEMBER _yPaddingHorizontal WRITE setYPaddingHorizontal)
Q_PROPERTY(QString paddingVertical MEMBER _yPaddingVertical WRITE setYPaddingVertical)
Q_PROPERTY(QString padding MEMBER _yPadding WRITE setYPadding)
Q_PROPERTY(QString marginTop MEMBER _yMarginTop WRITE setYMarginTop)
Q_PROPERTY(QString marginRight MEMBER _yMarginRight WRITE setYMarginRight)
Q_PROPERTY(QString marginBottom MEMBER _yMarginBottom WRITE setYMarginBottom)
Q_PROPERTY(QString marginLeft MEMBER _yMarginLeft WRITE setYMarginLeft)
Q_PROPERTY(QString marginHorizontal MEMBER _yMarginHorizontal WRITE setYMarginHorizontal)
Q_PROPERTY(QString marginVertical MEMBER _yMarginVertical WRITE setYMarginVertical)
Q_PROPERTY(QString margin MEMBER _yMargin WRITE setYMarginAll)
Q_PROPERTY(float borderTop MEMBER _yBorderTop WRITE setYBorderTop)
Q_PROPERTY(float borderRight MEMBER _yBorderRight WRITE setYBorderRight)
Q_PROPERTY(float borderBottom MEMBER _yBorderBottom WRITE setYBorderBottom)
Q_PROPERTY(float borderLeft MEMBER _yBorderLeft WRITE setYBorderLeft)
Q_PROPERTY(float borderHorizontal MEMBER _yBorderHorizontal WRITE setYBorderHorizontal)
Q_PROPERTY(float borderVertical MEMBER _yBorderVertical WRITE setYBorderVertical)
Q_PROPERTY(float border MEMBER _yBorder WRITE setYBorder)
SET_YOGA_WIDGET_Q_PROPERTIES
using QWidget::QWidget; //inherit all constructors of QWidget
Q_OBJECT
};

View File

@ -8,55 +8,8 @@ class NLabel: public QLabel, public YogaWidget
{
public:
// SET_YOGA_WIDGET_Q_PROPERTIES
Q_PROPERTY(QString display MEMBER _yDisplay WRITE setYDisplay)
Q_PROPERTY(QString alignItems MEMBER _yAlignItems WRITE setYAlignItems)
Q_PROPERTY(QString alignContent MEMBER _yAlignContent WRITE setYAlignContent)
Q_PROPERTY(QString alignSelf MEMBER _yAlignSelf WRITE setYAlignSelf)
Q_PROPERTY(QString justifyContent MEMBER _yJustifyContent WRITE setYJustifyContent)
Q_PROPERTY(QString direction MEMBER _yDirection WRITE setYDirection)
Q_PROPERTY(QString flexDirection MEMBER _yFlexDirection WRITE setYFlexDirection)
Q_PROPERTY(QString overflow MEMBER _yOverflow WRITE setYOverflow)
Q_PROPERTY(QString position MEMBER _yPosition WRITE setYPosition)
Q_PROPERTY(QString flexWrap MEMBER _yFlexWrap WRITE setYFlexWrap)
Q_PROPERTY(float flex MEMBER _yFlex WRITE setYFlex)
Q_PROPERTY(float flexGrow MEMBER _yFlexGrow WRITE setYFlexGrow)
Q_PROPERTY(float flexShrink MEMBER _yFlexShrink WRITE setYFlexShrink)
Q_PROPERTY(float aspectRatio MEMBER _yAspectRatio WRITE setYAspectRatio)
Q_PROPERTY(QString top MEMBER _yTop WRITE setYNodeTop)
Q_PROPERTY(QString right MEMBER _yRight WRITE setYNodeRight)
Q_PROPERTY(QString bottom MEMBER _yBottom WRITE setYNodeBottom)
Q_PROPERTY(QString left MEMBER _yLeft WRITE setYNodeLeft)
Q_PROPERTY(QString flexBasis MEMBER _yFlexBasis WRITE setYFlexBasis)
Q_PROPERTY(QString minWidth MEMBER _yMinWidth WRITE setYMinWidth)
Q_PROPERTY(QString minHeight MEMBER _yMinHeight WRITE setYMinHeight)
Q_PROPERTY(QString maxWidth MEMBER _yMaxWidth WRITE setYMaxWidth)
Q_PROPERTY(QString maxHeight MEMBER _yMaxHeight WRITE setYMaxHeight)
Q_PROPERTY(QString paddingTop MEMBER _yPaddingTop WRITE setYPaddingTop)
Q_PROPERTY(QString paddingRight MEMBER _yPaddingRight WRITE setYPaddingRight)
Q_PROPERTY(QString paddingBottom MEMBER _yPaddingBottom WRITE setYPaddingBottom)
Q_PROPERTY(QString paddingLeft MEMBER _yPaddingLeft WRITE setYPaddingLeft)
Q_PROPERTY(QString paddingHorizontal MEMBER _yPaddingHorizontal WRITE setYPaddingHorizontal)
Q_PROPERTY(QString paddingVertical MEMBER _yPaddingVertical WRITE setYPaddingVertical)
Q_PROPERTY(QString padding MEMBER _yPadding WRITE setYPadding)
Q_PROPERTY(QString marginTop MEMBER _yMarginTop WRITE setYMarginTop)
Q_PROPERTY(QString marginRight MEMBER _yMarginRight WRITE setYMarginRight)
Q_PROPERTY(QString marginBottom MEMBER _yMarginBottom WRITE setYMarginBottom)
Q_PROPERTY(QString marginLeft MEMBER _yMarginLeft WRITE setYMarginLeft)
Q_PROPERTY(QString marginHorizontal MEMBER _yMarginHorizontal WRITE setYMarginHorizontal)
Q_PROPERTY(QString marginVertical MEMBER _yMarginVertical WRITE setYMarginVertical)
Q_PROPERTY(QString margin MEMBER _yMargin WRITE setYMarginAll)
Q_PROPERTY(float borderTop MEMBER _yBorderTop WRITE setYBorderTop)
Q_PROPERTY(float borderRight MEMBER _yBorderRight WRITE setYBorderRight)
Q_PROPERTY(float borderBottom MEMBER _yBorderBottom WRITE setYBorderBottom)
Q_PROPERTY(float borderLeft MEMBER _yBorderLeft WRITE setYBorderLeft)
Q_PROPERTY(float borderHorizontal MEMBER _yBorderHorizontal WRITE setYBorderHorizontal)
Q_PROPERTY(float borderVertical MEMBER _yBorderVertical WRITE setYBorderVertical)
Q_PROPERTY(float border MEMBER _yBorder WRITE setYBorder)
SET_YOGA_WIDGET_Q_PROPERTIES
using QLabel::QLabel; //inherit all constructors of QLabel
Q_OBJECT
};

View File

@ -18,7 +18,7 @@ All Widgets for which you need to set yoga props via qstylesheet should
*/
// This macro is not working so copy paste it for now
// For this macro to work use moc like this: moc nlabel.h -o nlabel_moc.cpp --include ../../core/YogaWidget/yogawidget.h
#ifndef SET_YOGA_WIDGET_Q_PROPERTIES
#define SET_YOGA_WIDGET_Q_PROPERTIES \
Q_PROPERTY(QString display MEMBER _yDisplay WRITE setYDisplay) \