RNA: Improve handling of bitflags enum properties.
* Remove the 'set default from all bitflags items' behavior of `RNA_def_property_enum_bitflag_sdna`. * Add some minimal sanity check regarding bitflag enums that also define an `items` runtime callback. It currently assumes that if a valid set of items is also statically defined, the items callback will return a subset of these. Implements #143538. Pull Request: https://projects.blender.org/blender/blender/pulls/143733
This commit is contained in:
committed by
Bastien Montagne
parent
b9958fa4da
commit
d415890708
@@ -2180,6 +2180,17 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
|
||||
case PROP_ENUM: {
|
||||
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
|
||||
|
||||
if (dp->enumbitflags && eprop->item_fn &&
|
||||
!(eprop->item != rna_enum_dummy_NULL_items || eprop->set || eprop->set_ex))
|
||||
{
|
||||
CLOG_ERROR(&LOG,
|
||||
"%s.%s, bitflag enum should not define an `item` callback function, unless "
|
||||
"they also define a static list of items, or a custom `set` callback.",
|
||||
srna->identifier,
|
||||
prop->identifier);
|
||||
DefRNA.error = true;
|
||||
}
|
||||
|
||||
if (!(prop->flag & PROP_EDITABLE) && (eprop->set || eprop->set_ex)) {
|
||||
CLOG_ERROR(&LOG,
|
||||
"%s.%s, is read-only but has defines a \"set\" callback.",
|
||||
@@ -4210,10 +4221,11 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
|
||||
else {
|
||||
if (!defaultfound && !(eprop->item_fn && eprop->item == rna_enum_dummy_NULL_items)) {
|
||||
CLOG_ERROR(&LOG,
|
||||
"%s%s.%s, enum default is not in items.",
|
||||
"%s%s.%s, enum default '%d' is not in items.",
|
||||
srna->identifier,
|
||||
errnest,
|
||||
prop->identifier);
|
||||
prop->identifier,
|
||||
eprop->defaultvalue);
|
||||
DefRNA.error = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2965,17 +2965,6 @@ void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop,
|
||||
|
||||
if (dp) {
|
||||
dp->enumbitflags = 1;
|
||||
|
||||
#ifndef RNA_RUNTIME
|
||||
int defaultvalue_mask = 0;
|
||||
EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
|
||||
for (int i = 0; i < eprop->totitem; i++) {
|
||||
if (eprop->item[i].identifier[0]) {
|
||||
defaultvalue_mask |= eprop->defaultvalue & eprop->item[i].value;
|
||||
}
|
||||
}
|
||||
eprop->defaultvalue = defaultvalue_mask;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5371,6 +5371,7 @@ static void rna_def_userdef_view(BlenderRNA *brna)
|
||||
prop = RNA_def_property(srna, "header_align", PROP_ENUM, PROP_NONE);
|
||||
RNA_def_property_enum_items(prop, header_align_items);
|
||||
RNA_def_property_enum_bitflag_sdna(prop, nullptr, "uiflag");
|
||||
RNA_def_property_enum_default(prop, USER_HEADER_FROM_PREF | USER_HEADER_BOTTOM);
|
||||
RNA_def_property_ui_text(prop, "Header Position", "Default header position for new space-types");
|
||||
RNA_def_property_update(prop, 0, "rna_userdef_screen_update_header_default");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user