Qt Editor: Support EmptyName enum delegate property for user-defined option lists

This can be used to clarify what happens e.g. when nil is selected in an object function delegate.
qteditor
Sven Eberhardt 2016-07-30 14:13:23 -04:00
parent 323691eeca
commit d55c988d2e
2 changed files with 7 additions and 3 deletions

View File

@ -822,6 +822,7 @@ C4PropertyDelegateEnum::C4PropertyDelegateEnum(const C4PropertyDelegateFactory *
default_option_key = props->GetPropertyStr(P_OptionKey);
default_value_key = props->GetPropertyStr(P_ValueKey);
allow_editing = props->GetPropertyBool(P_AllowEditing);
empty_name = props->GetPropertyStr(P_EmptyName);
}
if (poptions)
{
@ -833,12 +834,13 @@ C4PropertyDelegateEnum::C4PropertyDelegateEnum(const C4PropertyDelegateFactory *
if (!props) continue;
Option option;
option.name = props->GetPropertyStr(P_Name);
if (!option.name.Get()) option.name = ::Strings.RegString("???");
if (!option.name) option.name = ::Strings.RegString("???");
option.help = props->GetPropertyStr(P_EditorHelp);
option.group = props->GetPropertyStr(P_Group);
option.value_key = props->GetPropertyStr(P_ValueKey);
if (!option.value_key) option.value_key = default_value_key;
props->GetProperty(P_Value, &option.value);
if (option.value.GetType() == C4V_Nil && empty_name) option.name = empty_name.Get();
props->GetProperty(P_Get, &option.value_function);
option.type = C4V_Type(props->GetPropertyInt(P_Type, C4V_Any));
option.option_key = props->GetPropertyStr(P_OptionKey);
@ -1262,8 +1264,7 @@ C4PropertyDelegateDef::C4PropertyDelegateDef(const C4PropertyDelegateFactory *fa
: C4PropertyDelegateEnum(factory, props)
{
// nil is always an option
C4String *empty_name = props ? props->GetPropertyStr(P_EmptyName) : nullptr;
AddConstOption(empty_name ? empty_name : ::Strings.RegString("nil"), C4VNull);
AddConstOption(empty_name ? empty_name.Get() : ::Strings.RegString("nil"), C4VNull);
// Collect sorted definitions
C4String *filter_property = props ? props->GetPropertyStr(P_Filter) : nullptr;
if (filter_property)

View File

@ -329,6 +329,9 @@ private:
std::vector<Option> options;
bool allow_editing;
protected:
C4RefCntPointer<C4String> empty_name; // Override for name of empty option
protected:
void ClearOptions();
void ReserveOptions(int32_t num);