[Interest] Is there any plan to make property binding working in C++?

Xavier Bigand flamaros.xavier at gmail.com
Mon May 9 11:06:40 CEST 2016


Exactly property binding is interesting when we are doing more complex
operations, with your examples I don't really see where the connect solve a
dependency graph.

An example from our code :

    bool WallEntity::dimentionsVisibleBinding()

    {

        if (mWall.get(); == nullptr)
  // dimentionsVisibleBinding will be called if the mWall value change
as for all other properties used here

            return false;


        if (Application::singleton()->getEditionModeState() !=
eEditionModeState2D)   // property

            return false;


        if (isVisible() == false)

            return false;


        if (core::Settings::singleton()->getWallCotationsDisplayed())
 // property

            return true;


        if (isSelected() || hasSelectedRoomEntity() ||
hasSelectedWallEntityAsNeighbor())   //properties

            return true;


        return false;

    }


    // We also have normal slots on our properties

    void WallEntity::onDimentionsVisibleChanged()

    {

        mLeftTextEntity->setVisible(mDimentionsVisible.get());

        mRightTextEntity->setVisible(mDimentionsVisible.get());

        mArrowEntity->setVisible(mDimentionsVisible.get());

        mDimensionFrameEntity->setVisible(mDimentionsVisible.get());

        mLineEntity->setVisible(mDimentionsVisible.get());

    }


// .get() isn't really necessary but it's more explicit and in some
cases the compiler request it because it can't decide to take the ()
operator.



2016-05-09 10:32 GMT+02:00 Jean-Michaƫl Celerier <
jeanmichael.celerier at gmail.com>:

>
> On Mon, May 9, 2016 at 7:41 AM, Thiago Macieira <thiago.macieira at intel.com
> > wrote:
>
>>
>> We already have one, it's called QObject::connect.
>>
>
> To be faire, to emulate property binding, I think that you also have to
> set the current value upon connection.
> Which isn't straightforward if you want to do more than a trivial "set"
> operation :
>
> connect(model, &Model::fooChanged,
>              this, [=] (Foo f) { this->view->setHeight(toPixels(f)); }
>
> this->view->setHeight(toPixels(model.foo()));
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>


-- 
Xavier
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160509/c87bbcc6/attachment.html>


More information about the Interest mailing list