Dynamically Hideable Property Status

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!
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Dynamically Hideable Property Status

Post by abdullah »

Hi there,

Helping out with the PartDesign Chamfer PR, I have realised of a behaviour of the Property editor that I think it could be improved.

The Chamfer will have several "Modes of operation", where different Modes require different properties. One mode requires just one size, a second mode two sizes (also called radii or distances), third mode one size and one angle (dimension - angle). This is similar to pad, which in one mode has two lengths. This behaviour is controled by a enum combobox which lists the Modes and allows to select one or the other.

With the current FC Code this happens:

Image

i.e. when changing the enum, the property editor must be exited so that the properties are updated.

I was looking for this behaviour:

Image

i.e. the properties auto-update when the enum property is changed.

I have not found a way to do this with the current FC (maybe I missed something).

The reason is that hidden properties are not added to the PropertyModel of the PropertyView. Then it is necessary to rebuild the PropertyModel upon changing the hidden status of a property.

One option to get the desired behaviour is to add all the hidden properties to the PropertyModel and modify the PropertyEditor to actually only show those that are not hidden.

An alternative, to avoid bloating the PropertyView with all the hidden properties, when most are not necessary, I have coded an implementation which uses a new property status bit DynamicallyHideable. Then the PropertyModel is built including DynamicallyHideable properties irrespective of better they are hidden or not, making the PropertyEditor update the visibility of those properties depending on whether they are indeed Hidden or not. This enables the behaviour shown in the second snapshot above.
wmayer wrote: ping
Would you take a look to this commit and let me know how acceptable it is?
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Dynamically Hideable Property Status

Post by realthunder »

You can already achieve this using Property::setStatus(Property::Hidden, true/false), or from Python obj.setPropertyStatus(property_name, 'Hidden'), or '-Hidden'. Make sure you don't add Prop_Hidden when you create the property. That is a static flag which cannot be changed at runtime.
property-hide.gif
property-hide.gif (63 KiB) Viewed 1076 times
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Dynamically Hideable Property Status

Post by abdullah »

realthunder wrote: Sat May 16, 2020 2:05 am You can already achieve this using Property::setStatus(Property::Hidden, true/false), or from Python obj.setPropertyStatus(property_name, 'Hidden'), or '-Hidden'. Make sure you don't add Prop_Hidden when you create the property. That is a static flag which cannot be changed at runtime.

property-hide.gif
Hi! I really appreciate your reply (and maybe later on a reply about static flags here. I have tracked down the commits to you, so nobody better than you to help me understand it ;) ).

Coming back to this functionality. Your example is an object that when attached to the PropertyView has all properties shown. Then, the PropertyModel is populated with them. Afterwards you can hide and show as per your example. You are indeed right that this case works with the current master code.

The problem arises when the object is attached to the PropertyView with hidden properties that we want to dynamically show/hide. It is different because the current code intentionally does not build the PropertyModel with hidden properties. Your own example:
Peek 16-05-2020 06-11.gif
Peek 16-05-2020 06-11.gif (111.83 KiB) Viewed 1051 times
I know you are very resourceful, so if you know a better way or want to review my code, I welcome it. It is about better code for all and learning is a steady process :D
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Dynamically Hideable Property Status

Post by realthunder »

abdullah wrote: Sat May 16, 2020 4:19 am The problem arises when the object is attached to the PropertyView with hidden properties that we want to dynamically show/hide. It is different because the current code intentionally does not build the PropertyModel with hidden properties. Your own example:
Now I see what you mean here. You can test the commit here. If it works fine for you, I can submit the PR.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Dynamically Hideable Property Status

Post by abdullah »

realthunder wrote: Sat May 16, 2020 5:15 am
abdullah wrote: Sat May 16, 2020 4:19 am The problem arises when the object is attached to the PropertyView with hidden properties that we want to dynamically show/hide. It is different because the current code intentionally does not build the PropertyModel with hidden properties. Your own example:
Now I see what you mean here. You can test the commit here. If it works fine for you, I can submit the PR.
A nice angle! It perfectly solves the problem with a substantial lower impact. ;)

Please, PR it.

Thanks! :D
realthunder
Veteran
Posts: 2190
Joined: Tue Jan 03, 2017 10:55 am

Re: Dynamically Hideable Property Status

Post by realthunder »

PR submitted here.
Try Assembly3 with my custom build of FreeCAD at here.
And if you'd like to show your support, you can donate through patreon, liberapay, or paypal
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Dynamically Hideable Property Status

Post by abdullah »

realthunder wrote: Sat May 16, 2020 6:34 am PR submitted here.
Merged.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Dynamically Hideable Property Status

Post by wmayer »

The Python API of DocumentObject also provides the methods getEditorMode and setEditorMode that changes the same status bits and were already available in v0.18 and earlier.

In v0.18 it worked to select an object whose "Hidden" flag of a property (e.g. Label) is set and then calling

Code: Select all

obj.setEditorMode("Label", 0)
makes it appear again.

In v0.19 this didn't work any more but with the PR applied it works again.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Dynamically Hideable Property Status

Post by wmayer »

The original ability to hide and show items in the property editor has been implemented with git commit 0ec81d2760bd

The most important point is that the "Hidden" flag of the status bits of a property is ignored and as long as the App::Prop_Hidden is not set the property is always added. Afterwards the status bit for "Hidden" is checked and if set the item is made invisible with the call of QTreeView::setRowHidden(..., true).

If you then select an object where a property is made hidden and you show it again all what needs to be done is to show the item with QTreeView::setRowHidden(..., false). This is very efficient because you don't have to reset the full model.

Now with v0.19 the behaviour is quite different and very often the full model is reset which is way more expensive than just changing individual items and it has the bad side-effect that if an item has an active editor it will be destroyed.

Example:

Code: Select all

class TestObject:
  def __init__(self, obj):
    obj.addProperty("App::PropertyBool", "Toggle").Toggle = False
    obj.setEditorMode("Label", 2)
    obj.Proxy = self
  def onChanged(self, obj, prop):
    if prop == "Toggle":
      if obj.Toggle:
        obj.setEditorMode("Label", 0)
      else:
        obj.setEditorMode("Label", 2)


doc=App.newDocument()
obj=doc.addObject("App::FeaturePython","test")
TestObject(obj)
Select the object in the tree view and in the property editor set Toggle to True. You will see that the combo box will be destroyed and you have to click the item again.

If you do the same in v0.18 you will see that everything works as expected.
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Dynamically Hideable Property Status

Post by wmayer »

The old and more efficient behaviour can be easily restored. Therefore the PR should be reverted and inside the function PropertyView::onTimer() it must be avoided to use isPropertyHidden() because this checks for App::Prop_Hidden or the status bits. Instead a function is needed that only checks the App::Prop_Hidden.
Post Reply