[Development] RFC: new moc feature

Olivier Goffart olivier at woboq.com
Sat Dec 5 11:22:23 CET 2015


On Saturday 5. December 2015 09:30:33 Sean Harmer wrote:
> Hi devs,
> 
> I'd like to get some feedback on a new feature for moc before we take it
> any further than mild musing. The context is Qt3D has some frontend
> QObject subclass types, and corresponding backend, non-QObject subclass
> types for reasons of allowing us to process data on the backend without
> blocking the main thread or locking it.
> 
> To get the property values from the frontend objects to the backend we
> wrap the data up in QScenePropertyChange and in the backend object we
> unpack the data and handle it with code something like this:
> 
>      if (e->type() == NodeUpdated) {
>          const QScenePropertyChangePtr &propertyChange =
> qSharedPointerCast<QScenePropertyChange>(e);
>          if (propertyChange->propertyName() ==
> QByteArrayLiteral("scale3D")) {
>              m_scale = propertyChange->value().value<QVector3D>();
>              updateMatrix();
>          } else if (propertyChange->propertyName() ==
> QByteArrayLiteral("rotation")) {
>              m_rotation = propertyChange->value().value<QQuaternion>();
>              updateMatrix();
>          } else if (propertyChange->propertyName() ==
> QByteArrayLiteral("translation")) {
>              m_translation = propertyChange->value().value<QVector3D>();
>              updateMatrix();
>          } else if (propertyChange->propertyName() ==
> QByteArrayLiteral("enabled")) {
>              m_enabled = propertyChange->value().toBool();
>          }
>      }
> 
> Not too bad in this case but those cascaded if-else if blocks are not
> good when the number of properties is large.

Why not?  Readability or performence?

> This is where the proposed new feature of moc would come in. If moc were
> able to generate an enum where each enum value corresponds to a static
> property we would be able to use a switch in the above code.
> 
> Is such a feature feasible? Are there reasons why it couldn't work?

I'm afraid this is not feasable. This enum would need to be in the header, and 
the moc generated code is not a header.


Instead, I would suggest something similar to llvm::StringSwitch
http://code.woboq.org/llvm/llvm/include/llvm/ADT/StringSwitch.h.html

-- 
Olivier 

Woboq - Qt services and support - http://woboq.com - http://code.woboq.org




More information about the Development mailing list