[Bug] even if the Group property is set readonly, dragging is allowed

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
flachyjoe
Veteran
Posts: 1891
Joined: Sat Mar 31, 2012 12:00 pm
Location: Limoges, France

[Bug] even if the Group property is set readonly, dragging is allowed

Post by flachyjoe »

Hi,
Context:

Code: Select all

class StaticGroup:
    def __init__(self, obj, children):

        obj.Proxy = self

        self.Type = "MyObject"
        self.children = children

        obj.Group = children
        obj.setPropertyStatus('Group', 'ReadOnly')

obj = App.ActiveDocument.addObject('App::DocumentObjectGroupPython', 'MyStaticGroup')
StaticGroup(obj, children)
Expected result:
Dragging an object in the StaticGroup shouldn't change the Group property and fail

Observed result:
Dragging change the Group property, an object can be add or a child can be removed.

Workaround:

Code: Select all

class StaticGroup:
    def __init__(self, obj, children):

        obj.Proxy = self

        self.Type = "MyObject"
        self.children = children

        obj.Group = children

    def onChanged(self, fp, prop):
        if str(prop) == 'Group':
            fp.Group = self.children
OS: Ubuntu 21.04 (XFCE/xubuntu)
Word size of FreeCAD: 64-bit
Version: 0.20.25207 (Git)
Build type: Unknown
Branch: master
Hash: e73ddda1b704fb602e1528efbf860862f51b9a3b
Python version: 3.9.5
Qt version: 5.15.2
Coin version: 4.0.0
OCC version: 7.5.2
Locale: French/France (fr_FR)
- Flachy Joe -
Image
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: [Bug] even if the Group property is set readonly, dragging is allowed

Post by ickby »

Read-only for a property does only apply for the property editor. It does not prevent any programmatic change of the property, neither by python, c++ or even other UI elements like Dialogs etc.

Drag and drop as a UI feature is controlled by the viewprovider. There you can define if drag and drop is supported, and what to do on a drop. For this override the filling functions:

Code: Select all

canDragObjects() --> return true/false for enable/disable
canDragObject(obj) --> same for individual objects
dragObject(obj) --> when object is draged by the user
As a side note: if you want to make a property really unchangeable, you need to set it to immutable (possible since 0.19). If I remember this works by using

Code: Select all

setPropertyStatus
. the method has good documentation on how-to do it.
But I would expect strange behaviour in the sense, that the UI feedback would show the user to allow drag and drop, but nothing would be changed and only an error printed.
User avatar
flachyjoe
Veteran
Posts: 1891
Joined: Sat Mar 31, 2012 12:00 pm
Location: Limoges, France

Re: [Bug] even if the Group property is set readonly, dragging is allowed

Post by flachyjoe »

Thank you ickby for the clarification.

UI reacts anyway on read-only properties with removing of spin buttons and other three-dots ones and blocks text editing so it's disappointing to allow drag and drop.
- Flachy Joe -
Image
ickby
Veteran
Posts: 3116
Joined: Wed Oct 05, 2011 7:36 am

Re: [Bug] even if the Group property is set readonly, dragging is allowed

Post by ickby »

Drag and drop is a universal implementarion, detailed by the document objects. It has no idea, what a group property is, or how it influences drag and drop. So it is understandable that it cannot react on the read only status.
Post Reply