There is no Property::setValue().

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
andrecaldas
Posts: 300
Joined: Fri Jan 27, 2023 8:45 pm
Contact:

There is no Property::setValue().

Post by andrecaldas »

If I am not getting anything wrong (again)...

It is very strange (although understandable) that the macro ADD_PROPERTY_TYPE calls Property::setValue() when Property itself has no setValue member function.

I do understand the convenience, though.

I think some classes do define a dummy setValue just to make this macro happy. :-(

Is it a bad idea to have an ADD_PROPERTY_TYPE_NO_DEFAULT?
marioalexis
Posts: 124
Joined: Wed Jun 19, 2019 7:44 pm

Re: There is no Property::setValue().

Post by marioalexis »

The Property class is abstract, so you don't create instances of Property class, but objects of derived classes such as those defined in PropertyStandard.h, which have a setValue function member.
User avatar
andrecaldas
Posts: 300
Joined: Fri Jan 27, 2023 8:45 pm
Contact:

Re: There is no Property::setValue().

Post by andrecaldas »

marioalexis wrote: Sat Mar 18, 2023 2:06 am The Property class is abstract, so you don't create instances of Property class, but objects of derived classes such as those defined in PropertyStandard.h, which have a setValue function member.
The idea of an abstract class is to provide an interface. There is no Property::setValue. Not even virtual.

Personally, I do not think there should be one. And I am not advocating for it. But if it is not part of the interface, the ADD_PROPERTY_TYPE should not assume there is one.

One solution (to a non-existing-problem, I know) is to have a comment before the definition of ADD_PROPERTY_TYPE explaining the situation, plus an alternative that does not call setValue.

It seems that there are classes derived from Property that define a setValue just to make the macro "happy". For example, PropertyListsT defines a very strange setValue.

Most of those property classes should probably have a very suitable default value you don't need to set. It is strange that they have to call ADD_PROPERTY_TYPE, using things like (nullptr, nullptr).
Post Reply