Skip to content

Commit 68ff868

Browse files
authored
Merge pull request #51 from WandererFan/propertychanges
add chapter on object deletion
2 parents bcba2ab + 82684dd commit 68ff868

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

technical/ObjectDeletion.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: default
3+
---
4+
5+
# How to control object deletion
6+
7+
It is possible for a user to attempt to delete a DocumentObject while a Task
8+
Dialog is attempting to update that object. Handling this in a Task Dialog
9+
is not tidy.
10+
11+
## Recommended reading:
12+
- ViewProviders
13+
- In/Out Lists
14+
15+
There are two methods in the ViewProvider that deal with this situation.
16+
17+
'''c++
18+
bool canDelete(App::DocumentObject *obj)
19+
'''
20+
is called when Std_Delete is asked to delete obj, BUT it is called for each of
21+
obj's parent in the InList. This is where you would decide if you will allow
22+
one of your children can be deleted. In effect, the is canDeleteMyChildObject().
23+
Return true to allow the child to be deleted, or false to prevent the deletion.
24+
25+
'''c++
26+
bool onDelete(const std::vector<std::string> & parms)
27+
'''
28+
is also called when when Std_Delete is asked to delete a DocumentObject, but in
29+
this case it is the DocumentObject's ViewProvider that is called. Return true
30+
to allow deletion of the DocumentObject, or false to prevent the deletion.
31+
32+
Note that it is possible to circumvent these methods via scripting.

technical/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Technical information of interest to Contributors.
3030
- [Creating a WorkBench](https://wiki.freecad.org/Workbench_creation)
3131
- The [PowerUser's hub](https://wiki.freecad.org/Power_users_hub) in the FreeCAD wiki contains good information about Python scripting and workbench creation
3232
- [Accessing User Preferences](./preferences.md)
33+
- [Controlling Object Deletion](./ObjectDeletion.md)
3334
- [Create a Python Binding for C++ Class](./CreatePythonBindingForCpp.md)
3435
- [Checklist for Adding a Feature to a Workbench in C++](./ChecklistForNewFeatureC++.md)
3536

0 commit comments

Comments
 (0)