Skip to content

Accessor for form fields subfields

I am currently working on an application that fills pdf forms automatically by means of YAML files.

In order to do so i would like to locate all the form fields by name. That means that in order to handle non-terminal fields i have to be able to enumerate children fields. Until now i was hacking out the protected status of children and numchildren by doing this ugly hack:

/** 
    FormField has no api to access children fields.
    This is a kludge to access protected fields of
    FormField throught static methods of a derived
    class.
*/      
class FormFieldHack : public FormField
{           
public: 
    static int getNumChildrenFields(FormField * field)
    {   
        FormFieldHack * hack = static_cast<FormFieldHack*>(field);
        if (hack->terminal) return 0; // numChildren are widgets
        return hack->numChildren;
    }   
    static FormField * getChildField(FormField * field, int i)
    {   
        FormFieldHack * hack = static_cast<FormFieldHack*>(field);
        return hack->children[i];
    }       
};          

But that was, as i said, a dirty hack. I would rather prefer to include those two methods I add in the PR to the FormField interface. Unless there is a sensible reason to keep that not accessible.

I called them subfields instead of children to avoid missunderstanding with children widgets.

Thanks.

Merge request reports