Added support for deleting empty groups from the property bag's group tracking.

This commit is contained in:
Markus Lampert
2021-01-26 19:46:06 -08:00
parent a4890e51f5
commit 75e65dd09d
5 changed files with 91 additions and 1 deletions

View File

@@ -72,7 +72,7 @@ class PropertyBag(object):
obj.setEditorMode(self.CustomPropertyGroups, 2) # hide
def getCustomProperties(self):
'''Return a list of all custom properties created in this container.'''
'''getCustomProperties() ... Return a list of all custom properties created in this container.'''
return [p for p in self.obj.PropertiesList if self.obj.getGroupOfProperty(p) in self.obj.CustomPropertyGroups]
def addCustomProperty(self, propertyType, name, group=None, desc=None):
@@ -87,6 +87,16 @@ class PropertyBag(object):
self.obj.CustomPropertyGroups = groups
self.obj.addProperty(propertyType, name, group, desc)
def refreshCustomPropertyGroups(self):
'''refreshCustomPropertyGroups() ... removes empty property groups, should be called after deleting properties.'''
customGroups = []
for p in self.obj.PropertiesList:
group = self.obj.getGroupOfProperty(p)
if group in self.obj.CustomPropertyGroups and not group in customGroups:
customGroups.append(group)
self.obj.CustomPropertyGroups = customGroups
def Create(name = 'PropertyBag'):
obj = FreeCAD.ActiveDocument.addObject('App::FeaturePython', name)
obj.Proxy = PropertyBag(obj)

View File

@@ -130,6 +130,7 @@ class PropertyCreate(object):
self.obj = obj
self.form = FreeCADGui.PySideUic.loadUi(":panels/PropertyCreate.ui")
obj.Proxy.refreshCustomPropertyGroups()
for g in sorted(obj.CustomPropertyGroups):
self.form.propertyGroup.addItem(g)
if grp: