Added support for deleting empty groups from the property bag's group tracking.
This commit is contained in:
@@ -202,6 +202,7 @@ SET(PathTests_SRCS
|
||||
PathTests/TestPathOpTools.py
|
||||
PathTests/TestPathPost.py
|
||||
PathTests/TestPathPreferences.py
|
||||
PathTests/TestPathPropertyBag.py
|
||||
PathTests/TestPathSetupSheet.py
|
||||
PathTests/TestPathStock.py
|
||||
PathTests/TestPathThreadMilling.py
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
76
src/Mod/Path/PathTests/TestPathPropertyBag.py
Normal file
76
src/Mod/Path/PathTests/TestPathPropertyBag.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# ***************************************************************************
|
||||
# * Copyright (c) 2021 sliptonic <shopinthewoods@gmail.com> *
|
||||
# * *
|
||||
# * This program is free software; you can redistribute it and/or modify *
|
||||
# * it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
# * as published by the Free Software Foundation; either version 2 of *
|
||||
# * the License, or (at your option) any later version. *
|
||||
# * for detail see the LICENCE text file. *
|
||||
# * *
|
||||
# * This program is distributed in the hope that it will be useful, *
|
||||
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
# * GNU Library General Public License for more details. *
|
||||
# * *
|
||||
# * You should have received a copy of the GNU Library General Public *
|
||||
# * License along with this program; if not, write to the Free Software *
|
||||
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
# * USA *
|
||||
# * *
|
||||
# ***************************************************************************
|
||||
|
||||
import FreeCAD
|
||||
import PathScripts.PathPropertyBag as PathPropertyBag
|
||||
import PathTests.PathTestUtils as PathTestUtils
|
||||
|
||||
class TestPathPropertyBag(PathTestUtils.PathTestBase):
|
||||
|
||||
def setUp(self):
|
||||
self.doc = FreeCAD.newDocument('test-property-bag')
|
||||
|
||||
def tearDown(self):
|
||||
FreeCAD.closeDocument(self.doc.Name)
|
||||
|
||||
def test00(self):
|
||||
'''basic PropertyBag creation and access test'''
|
||||
bag = PathPropertyBag.Create()
|
||||
self.assertTrue(hasattr(bag, 'Proxy'))
|
||||
self.assertEqual(bag.Proxy.getCustomProperties(), [])
|
||||
self.assertEqual(bag.CustomPropertyGroups, [])
|
||||
|
||||
def test01(self):
|
||||
'''adding properties to a PropertyBag is tracked properly'''
|
||||
bag = PathPropertyBag.Create()
|
||||
proxy = bag.Proxy
|
||||
proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description')
|
||||
self.assertTrue(hasattr(bag, 'Title'))
|
||||
bag.Title = 'Madame'
|
||||
self.assertEqual(bag.Title, 'Madame')
|
||||
self.assertEqual(bag.Proxy.getCustomProperties(), ['Title'])
|
||||
self.assertEqual(bag.CustomPropertyGroups, ['Address'])
|
||||
|
||||
def test02(self):
|
||||
'''refreshCustomPropertyGroups deletes empty groups'''
|
||||
bag = PathPropertyBag.Create()
|
||||
proxy = bag.Proxy
|
||||
proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description')
|
||||
bag.Title = 'Madame'
|
||||
bag.removeProperty('Title')
|
||||
proxy.refreshCustomPropertyGroups()
|
||||
self.assertEqual(bag.Proxy.getCustomProperties(), [])
|
||||
self.assertEqual(bag.CustomPropertyGroups, [])
|
||||
|
||||
def test03(self):
|
||||
'''refreshCustomPropertyGroups does not delete non-empty groups'''
|
||||
bag = PathPropertyBag.Create()
|
||||
proxy = bag.Proxy
|
||||
proxy.addCustomProperty('App::PropertyString', 'Title', 'Address', 'Some description')
|
||||
proxy.addCustomProperty('App::PropertyString', 'Gender', 'Attributes')
|
||||
bag.Title = 'Madame'
|
||||
bag.Gender = 'Female'
|
||||
bag.removeProperty('Gender')
|
||||
proxy.refreshCustomPropertyGroups()
|
||||
self.assertEqual(bag.Proxy.getCustomProperties(), ['Title'])
|
||||
self.assertEqual(bag.CustomPropertyGroups, ['Address'])
|
||||
|
||||
@@ -24,6 +24,7 @@ import TestApp
|
||||
|
||||
from PathTests.TestPathLog import TestPathLog
|
||||
from PathTests.TestPathPreferences import TestPathPreferences
|
||||
from PathTests.TestPathPropertyBag import TestPathPropertyBag
|
||||
from PathTests.TestPathCore import TestPathCore
|
||||
#from PathTests.TestPathPost import PathPostTestCases
|
||||
from PathTests.TestPathGeom import TestPathGeom
|
||||
@@ -66,4 +67,5 @@ False if TestPathToolBit.__name__ else True
|
||||
False if TestPathVoronoi.__name__ else True
|
||||
False if TestPathThreadMilling.__name__ else True
|
||||
False if TestPathVcarve.__name__ else True
|
||||
False if TestPathPropertyBag.__name__ else True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user