Skip to content

Commit 5f6ca27

Browse files
authored
Merge pull request #49 from WandererFan/propertychanges
Add section on property changes
2 parents b462c3f + 796fe09 commit 5f6ca27

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

technical/PropertyChanges.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
layout: default
3+
---
4+
5+
6+
# Dealing with Property Changes
7+
8+
A brief introduction
9+
10+
Recommended reading:
11+
- The Application Module
12+
- [Property in the wiki](https://wiki.freecad.org/Property)
13+
14+
## The App side
15+
- When a Property's value changes, its PropertyContainer (eventually a DocumentObject) executes the onChanged method with the Property as a parameter. This is where you will take appropriate action based on the new property value.
16+
- Be cautious when inserting logic into onChanged and execute as it is possible to create a loop.
17+
18+
'''c++
19+
void myFeature::execute()
20+
{
21+
MyProperty->setValue(foo());
22+
}
23+
void myFeature::onChanged(App::Property property)
24+
{
25+
if (property == MyProperty) {
26+
execute();
27+
}
28+
}
29+
'''
30+
- The other interesting method involving property changes is mustExecute. This is where you control whether or not your object participates in the next recompute cycle.
31+
32+
33+
## The Gui side
34+
- On the Gui side, we must look first at your derived ViewProvider, which is attached to your DocumentObject. The ViewProvider is notified of changed properties for both itself and the DocumentObject it belongs to.
35+
- For properties belonging to the ViewProvider (those on the View tab in the PropertyEditor), the relevant method is again onChanged.
36+
- Whenever a DocumentObject Property changes, the updateData method of its attached ViewProvider is called.
37+

technical/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Technical information of interest to Contributors.
1414
- [The Source Code in More Depth](https://wiki.freecad.org/The_FreeCAD_source_code)
1515
- [Writing Code for Translation](./translation.md)
1616
- [Automated Testing](./automated_testing.md)
17+
- [Dealing with Property Changes](./PropertyChanges.md)
1718
- The FreeCAD developer's tool set:
1819
- C++ and Python
1920
- [Qt](https://www.qt.io/): a cross platform development framework

0 commit comments

Comments
 (0)