If it's Q_PROPERTY grievance time, can we add static, compile-time reflection of the property's attributes ?
here's the macro I've quickly cobbled for myself, if it can be useful to anyone else : https://github.com/jcelerier/verdigris/blob/master/src/wobjectdefs.h#L918 ; it has been extremely useful for me to generate a lot of UI stuff easily as well as implementing a generic command pattern (that doesn't hide everything behind a QVariant). Best, Jean-Michaël ------- Jean-Michaël Celerier http://www.jcelerier.name On Wed, Dec 5, 2018 at 6:33 PM Vlad Stelmahovsky <[email protected]> wrote: > use QtCreator, so you can autogenerate most of the code there > > On 12/5/18 5:41 PM, Jason H wrote: > > I've been doing a lot of Q_PROPERTY stuff again, and I waste too much > time writing boiler plate code. Last time, I was reminded of the MEMBER > modifier, which is what I thought I wanted. But after having worked with it > some more, it's not what I want. > > > > Given: > > Q_PROPERTY (qreal scale READ scale WRITE setScale NOTIFY scaleChanged) > // What I end up writing > > Q_PROPERTY (qreal scale MEMBER _scale NOTIFY) // What I want to write > > > > I want the member form to also declare/implement: > > public: > > qreal scale() { return _scale; } > > void setScale(qreal scale) { if (scale != scale) { _scale = scale; emit > scaleChanged(scale); } } > > signal: > > void scaleChanged(qreal scale); > > > > Where T=type, N=name M=member > > public: > > T N() { return M; } > > void setN(T N) { if (M != N) { M = N; emit NChanged(N); } } > > signal: > > void NChanged(T N); > > > > I'm trying to think of how to do this, and this seems doable: > > > > class X { > > > > ... > > INCLUDE_AUTOMOC_DECLARATIONS > > }; > > > > Where > > INCLUDE_AUTOMOC_DECLARATIONS expands to: > > #include "filename_X_automoc.h" > > > > Where MOC has written the declarations. Similarly, there can be one for > implementations as well. > > > > Ideally though, all I should need to write: > > Q_PROPERTY (qreal scale NOTIFY) > > > > Epanding to: > > private: > > T _N; > > public: > > T N() { return _N; } > > void setN(T N) { if (_N != N) { M = N; emit NChanged(N); } } > > signal: > > void NChanged(T N); > > > > I know this might sound trivial but if I'm making 5 classes each with 10 > properties, that's 1500 lines of boilerplate code that I'm writing (with > code style applied). > > > > Is there any way to get closer to my ideal? > > _______________________________________________ > > Interest mailing list > > [email protected] > > https://lists.qt-project.org/listinfo/interest > _______________________________________________ > Interest mailing list > [email protected] > https://lists.qt-project.org/listinfo/interest >
_______________________________________________ Interest mailing list [email protected] https://lists.qt-project.org/listinfo/interest
