Remoto - VFS
|
A form is an aggregate of named typed fields. More...
#include <VFS_form.h>
Public Member Functions | |
VFS_form (QString base="") | |
virtual | ~VFS_form () |
void | addBreak (int index=-1) |
Add a break field to a form. More... | |
void | append (QString name, VFS_form_field field, int index=-1) |
Append a field to the form. More... | |
void | applyDiff (QJsonObject diff, bool useAttributes=false) |
Apply a diff to this form. More... | |
bool | contains (QString field) |
Check if a field is part of a form. More... | |
QJsonValue | getOption (QString var, QString option) |
Fetch an option value from a form field if it exists. More... | |
QJsonValue | getValue (QString var) |
Fetch the value of a form field. More... | |
void | remove (QString name) |
Remove a field from the form. More... | |
void | removeIndexRange (int s, int e) |
Remove fields whose index is within a range. More... | |
void | replace (QString name, VFS_form_field field) |
Replace or append a field to the form. More... | |
void | setBase (QString baseForm) |
Set the 'class' that this form inherits from. More... | |
void | setHelp (QString helpText) |
Set the helptext for this form. More... | |
bool | setOption (QString var, QString option, QJsonValue o) |
Set an option on a form field if it exists. More... | |
bool | setValue (QString var, QJsonValue val) |
Set the value of a form field if it exists. More... | |
QJsonDocument | toJsonDocument (bool useAttributes=false) |
Return a form document as a QJsonDocument. More... | |
QJsonDocument | toSubclassDocument () |
Return the form as a QJsonDocument, and include reference to its base. More... | |
Private Member Functions | |
QJsonValue | cleanValue (QJsonValue o, bool isValue=false) |
Normalize a form value recursively. More... | |
Private Attributes | |
QString | _baseForm |
The base json 'class' that this form will augment. Leave blank for no base. More... | |
int | _breakCount |
The break count, because all fields must have unique names, and addBreak will use this. More... | |
QJsonObject | _form |
The form itself, which is just a json object. More... | |
QString | _helpText |
The help text that will appear in a menu or modal for this form. More... | |
int | _index |
The index count used for autoindexing. More... | |
A form is an aggregate of named typed fields.
baseForm | The base json 'class' that this will derive from. |
A form can optionally build upon another form, in a kind of inheritance scheme.
Fields will be sorted by index when rendered, and can be autoindexed when added.
Forms can also be used by VFS_node instances to represent a model of data, which can be rendered using a form in a javascript client, for instance.
Definition at line 9 of file VFS_form.h.
|
explicit |
baseForm |
Definition at line 33 of file VFS_form.cpp.
|
virtual |
Definition at line 41 of file VFS_form.cpp.
void VFS_form::addBreak | ( | int | index = -1 | ) |
Add a break field to a form.
index | The index if provided, otherwise autoindex. |
Definition at line 426 of file VFS_form.cpp.
void VFS_form::append | ( | QString | name, |
VFS_form_field | field, | ||
int | index = -1 |
||
) |
Append a field to the form.
name | The field name |
field | The field itself |
index | The index, or none if autoindexing is desired. |
Definition at line 222 of file VFS_form.cpp.
void VFS_form::applyDiff | ( | QJsonObject | diff, |
bool | useAttributes = false |
||
) |
Apply a diff to this form.
diff | The diff to apply |
useAttributes | Whether or not to assume the diff data is in the "attributes" field of the diff object. |
Definition at line 448 of file VFS_form.cpp.
|
private |
Normalize a form value recursively.
v | A json value |
isValue | whether the field being cleaned is "value". |
Definition at line 78 of file VFS_form.cpp.
bool VFS_form::contains | ( | QString | field | ) |
Check if a field is part of a form.
field | The field to check |
Definition at line 299 of file VFS_form.cpp.
QJsonValue VFS_form::getOption | ( | QString | var, |
QString | option | ||
) |
Fetch an option value from a form field if it exists.
var | The field name |
option | The option name |
Definition at line 408 of file VFS_form.cpp.
QJsonValue VFS_form::getValue | ( | QString | var | ) |
Fetch the value of a form field.
var | The field name |
Definition at line 361 of file VFS_form.cpp.
void VFS_form::remove | ( | QString | name | ) |
Remove a field from the form.
name | The field name |
If the field is not found, the function will silently continue
Definition at line 244 of file VFS_form.cpp.
void VFS_form::removeIndexRange | ( | int | s, |
int | e | ||
) |
Remove fields whose index is within a range.
s | The start index |
e | The end index |
This will remove fields where s <= index <= e
Definition at line 281 of file VFS_form.cpp.
void VFS_form::replace | ( | QString | name, |
VFS_form_field | field | ||
) |
Replace or append a field to the form.
name | The field name |
field | The field itself |
If the field exists, it will be replaced. The new field will take the index from the old field.
If the field doesn't exist, it will be added and autoindexed.
Definition at line 260 of file VFS_form.cpp.
void VFS_form::setBase | ( | QString | baseForm | ) |
Set the 'class' that this form inherits from.
baseForm | The base form |
Definition at line 51 of file VFS_form.cpp.
void VFS_form::setHelp | ( | QString | helpText | ) |
Set the helptext for this form.
helpText | The help text |
Definition at line 61 of file VFS_form.cpp.
bool VFS_form::setOption | ( | QString | var, |
QString | option, | ||
QJsonValue | o | ||
) |
Set an option on a form field if it exists.
var | The field name |
option | The option name |
o | The option value |
Definition at line 385 of file VFS_form.cpp.
bool VFS_form::setValue | ( | QString | var, |
QJsonValue | val | ||
) |
Set the value of a form field if it exists.
var | The field name |
val | The field value |
Definition at line 313 of file VFS_form.cpp.
QJsonDocument VFS_form::toJsonDocument | ( | bool | useAttributes = false | ) |
Return a form document as a QJsonDocument.
useAttributes | Offset the values using an "attributes" field |
Forms are ostensibly name:value pairs, but depending on the receiving side, an attributes offset may be needed.
may become
depending on the receiving interpreter.
Definition at line 147 of file VFS_form.cpp.
QJsonDocument VFS_form::toSubclassDocument | ( | ) |
Return the form as a QJsonDocument, and include reference to its base.
The result will always use the "attributes" form, and will contain a reference to the 'class' that this form builds on.
This is used, for instance, when you have a node that needs settings applied. The document itself will only contain the values of the settings, but the base 'class' will contain all of the widget parameters and cosmetic stuff. The client is responsible for pulling the base 'class' and doing the merge/diff.
Definition at line 178 of file VFS_form.cpp.
|
private |
The base json 'class' that this form will augment. Leave blank for no base.
Definition at line 44 of file VFS_form.h.
|
private |
The break count, because all fields must have unique names, and addBreak will use this.
Definition at line 42 of file VFS_form.h.
|
private |
The form itself, which is just a json object.
Definition at line 46 of file VFS_form.h.
|
private |
The help text that will appear in a menu or modal for this form.
Definition at line 45 of file VFS_form.h.
|
private |
The index count used for autoindexing.
Definition at line 41 of file VFS_form.h.