Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Marc Mutz
On Wednesday 15 April 2015 21:05:39 Keith Gardner wrote: > Would something like this be better? > > std::function No, a std::function in general allocates memory and even if it uses the small object optimisation, the call to the lambda will still be indirect. Thanks, Marc -- Marc Mutz | Seni

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Keith Gardner
On Wed, Apr 15, 2015 at 2:20 PM Andre Somers wrote: > On 15-4-2015 21:05, Keith Gardner wrote: > > > QPropertyGuard g{this}; >> > g.addProperty("a"); // use QObject::property >> > g.addProperty("b", m_b); // take value member by reference >> > g.addProperty(m_c, &cChanged); // ...and als

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Marc Mutz
On Wednesday 15 April 2015 16:58:24 André Somers wrote: > Basically, if you have this code (or something like it) somewhere, you > already have a problem: > > void MyClass::setFooAndBar(QString foo, int bar) > { >if (m_foo != foo) { > m_foo = foo; > emit fooChanged(foo); //this is

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Andre Somers
On 15-4-2015 21:05, Keith Gardner wrote: > QPropertyGuard g{this}; > g.addProperty("a"); // use QObject::property > g.addProperty("b", m_b); // take value member by reference > g.addProperty(m_c, &cChanged); // ...and also slot address There's type erasure going on, s

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Keith Gardner
> > > QPropertyGuard g{this}; > > g.addProperty("a"); // use QObject::property > > g.addProperty("b", m_b); // take value member by reference > > g.addProperty(m_c, &cChanged); // ...and also slot address > > There's type erasure going on, so it will allocate memory. Allocating > memory > i

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Marc Mutz
On Wednesday 15 April 2015 17:08:11 Matthew Woehlke wrote: > FWIW I had the same thought; also, I'm not a fan of needing the > Q_UNUSED, or using a macro to 'hide' it. I haven't had to use Q_UNUSED on a RAII object since iirc GCC 3 times. What broken compilers are you guys using? > What about so

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Matthew Woehlke
On 2015-04-15 13:55, Alan Alpert wrote: > The common case is one property I think, so keep that case to one > line. I'd envision using it in all my basic setters to save code at > the start of a project, and then when the features start to creep in > it's easier to add complexity into the setters.

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Alan Alpert
On Wed, Apr 15, 2015 at 8:08 AM, Matthew Woehlke wrote: > On 2015-04-15 10:43, Marc Mutz wrote: >> On Wednesday 15 April 2015 11:49:56 André Somers wrote: >>> void MyClass::setFoo(QString value) >>> { >>>PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY >>>Q_UNUSED(gua

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Giuseppe D'Angelo
On 15 April 2015 at 17:12, Matthew Woehlke wrote: > > Then the slot is broken. What if the sender needs to do something after > it delivers the signal? What if other slots are connected? Deleting a > signal sender from a slot connected to the signal is inherently > dangerous. Don't do it. For the

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Andre Somers
On 15-4-2015 18:44, Matthew Woehlke wrote: > The second form would thus save the value <-> QVariant comparison and > not much else. The third form however eliminates the string look-up > entirely by having the user provide both the backing member variable > *and* what to do when a change should

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Keith Gardner
> > I'd certainly be interested to seeing how you solved this, yes. Thanks! > I have made a repository for the class with an example. Sorry that there is no documentation for it. It requires C++11 support for r-value references, std::functional, and some type traits features. In addition to hav

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Matthew Woehlke
On 2015-04-15 12:29, Andre Somers wrote: > On 15-4-2015 17:08, Matthew Woehlke wrote: >> What about something like this? >> >>QPropertyGuard g{this}; >>g.addProperty("a"); // use QObject::property >>g.addProperty("b", m_b); // take value member by reference >>g.addProperty(m_c, &cCh

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Andre Somers
On 15-4-2015 17:08, Matthew Woehlke wrote: > On 2015-04-15 10:43, Marc Mutz wrote: >> On Wednesday 15 April 2015 11:49:56 André Somers wrote: >>> void MyClass::setFoo(QString value) >>> { >>> PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY >>> Q_UNUSED(guard); >>> >>>

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Andre Somers
On 15-4-2015 16:54, Keith Gardner wrote: On Wed, Apr 15, 2015 at 9:38 AM Marc Mutz > wrote: Hi André, On Wednesday 15 April 2015 11:49:56 André Somers wrote: > void MyClass::setFoo(QString value) > { >PropertyGuard guard(this, "foo"); //foo

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Christian Kandeler
On 04/15/2015 05:12 PM, Matthew Woehlke wrote: > [Valid points about the inconsistent state of the object elided.] > > On 2015-04-15 10:58, André Somers wrote: >> What if that slot [connected to the instance property changed >> signal] triggers something that ends up deleting the instance? > > Then

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Matthew Woehlke
[Valid points about the inconsistent state of the object elided.] On 2015-04-15 10:58, André Somers wrote: > What if that slot [connected to the instance property changed > signal] triggers something that ends up deleting the instance? Then the slot is broken. What if the sender needs to do somet

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Matthew Woehlke
On 2015-04-15 10:43, Marc Mutz wrote: > On Wednesday 15 April 2015 11:49:56 André Somers wrote: >> void MyClass::setFoo(QString value) >> { >>PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY >>Q_UNUSED(guard); >> >>m_foo = value; >> } > > This is an interesting id

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread André Somers
Hi Marc, Thank you for responding. Marc Mutz schreef op 15-4-2015 om 16:43: > Hi André, > > On Wednesday 15 April 2015 11:49:56 André Somers wrote: >> void MyClass::setFoo(QString value) >> { >> PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY >> Q_UNUSED(guard); >>

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Keith Gardner
On Wed, Apr 15, 2015 at 9:38 AM Marc Mutz wrote: > Hi André, > > On Wednesday 15 April 2015 11:49:56 André Somers wrote: > > void MyClass::setFoo(QString value) > > { > >PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY > >Q_UNUSED(guard); > > > >m_foo = value; >

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Marc Mutz
Hi André, On Wednesday 15 April 2015 11:49:56 André Somers wrote: > void MyClass::setFoo(QString value) > { >PropertyGuard guard(this, "foo"); //foo is the name of the Q_PROPERTY >Q_UNUSED(guard); > >m_foo = value; > } This is an interesting idea, though I don't think I have encount

Re: [Development] RFC: RAII for property changes

2015-04-15 Thread Nils Jeisecke
Hi, On Wed, Apr 15, 2015 at 11:49 AM, André Somers wrote: > That's why I have been working with a RAII implementation to monitor > property changes for a while now. This looks like an interesting idea. Another issue I often have with properties is performance related. Imagine a model that has m

[Development] RFC: RAII for property changes

2015-04-15 Thread André Somers
Hi, When writing QObject-derived classes with properties, I often found myself writing code like this: void MyClass::setFoo(QString value) { if (m_foo != value) { m_foo = value; emit fooChanged(m_foo); } } Trivial enough, in the simple case. However, when more than one property