Qt Editor: When descending into array delegates, use the parent name as header.

qteditor
Sven Eberhardt 2016-07-05 23:27:55 -04:00
parent 343658db96
commit 8bc5e1911d
2 changed files with 18 additions and 10 deletions

View File

@ -122,6 +122,7 @@ C4PropertyDelegate::C4PropertyDelegate(const C4PropertyDelegateFactory *factory,
// Resolve getter+setter callback names // Resolve getter+setter callback names
if (props) if (props)
{ {
name = props->GetPropertyStr(P_Name);
set_function = props->GetPropertyStr(P_Set); set_function = props->GetPropertyStr(P_Set);
set_function_is_global = props->GetPropertyBool(P_Global); set_function_is_global = props->GetPropertyBool(P_Global);
async_get_function = props->GetPropertyStr(P_AsyncGet); async_get_function = props->GetPropertyStr(P_AsyncGet);
@ -328,11 +329,12 @@ QWidget *C4PropertyDelegateDescendPath::CreateEditor(const class C4PropertyDeleg
// (and cannot be without going async in network mode) // (and cannot be without going async in network mode)
// On regular button press, re-resolve path to value // On regular button press, re-resolve path to value
C4Value val = editor->button_pending ? editor->last_value : editor->property_path.ResolveValue(); C4Value val = editor->button_pending ? editor->last_value : editor->property_path.ResolveValue();
if (val.getPropList() || val.getArray()) bool is_proplist = !!val.getPropList(), is_array = !!val.getArray();
if (is_proplist || is_array)
{ {
C4PropList *info_proplist = this->info_proplist.getPropList(); C4PropList *info_proplist = this->info_proplist.getPropList();
if (!info_proplist) info_proplist = val.getPropList(); if (!info_proplist) info_proplist = val.getPropList();
this->factory->GetPropertyModel()->DescendPath(val, info_proplist, editor->property_path); this->factory->GetPropertyModel()->DescendPath(val, info_proplist, editor->property_path, is_array ? GetNameStr() : nullptr);
::Console.EditCursor.InvalidateSelection(); ::Console.EditCursor.InvalidateSelection();
} }
}); });
@ -1221,7 +1223,7 @@ QWidget *C4PropertyDelegateC4ValueInput::CreateEditor(const class C4PropertyDele
C4Value val = editor->property_path.ResolveValue(); C4Value val = editor->property_path.ResolveValue();
if (val.getPropList() || val.getArray()) if (val.getPropList() || val.getArray())
{ {
this->factory->GetPropertyModel()->DescendPath(val, val.getPropList(), editor->property_path); this->factory->GetPropertyModel()->DescendPath(val, val.getPropList(), editor->property_path, nullptr);
::Console.EditCursor.InvalidateSelection(); ::Console.EditCursor.InvalidateSelection();
} }
}); });
@ -1544,18 +1546,20 @@ void C4ConsoleQtPropListModel::SetBasePropList(C4PropList *new_proplist)
info_proplist.SetPropList(target_value.getObj()); info_proplist.SetPropList(target_value.getObj());
target_path = C4PropertyPath(new_proplist); target_path = C4PropertyPath(new_proplist);
target_path_stack.clear(); target_path_stack.clear();
name_override = nullptr;
UpdateValue(true); UpdateValue(true);
delegate_factory->OnPropListChanged(); delegate_factory->OnPropListChanged();
} }
void C4ConsoleQtPropListModel::DescendPath(const C4Value &new_value, C4PropList *new_info_proplist, const C4PropertyPath &new_path) void C4ConsoleQtPropListModel::DescendPath(const C4Value &new_value, C4PropList *new_info_proplist, const C4PropertyPath &new_path, C4String *new_name_override)
{ {
// Add previous proplist to stack // Add previous proplist to stack
target_path_stack.push_back(TargetStackEntry(target_path, target_value, info_proplist)); target_path_stack.push_back(TargetStackEntry(target_path, target_value, info_proplist, name_override.Get()));
// descend // descend
target_value = new_value; target_value = new_value;
info_proplist.SetPropList(new_info_proplist); info_proplist.SetPropList(new_info_proplist);
target_path = new_path; target_path = new_path;
name_override = new_name_override;
UpdateValue(true); UpdateValue(true);
delegate_factory->OnPropListChanged(); delegate_factory->OnPropListChanged();
} }
@ -1580,6 +1584,7 @@ void C4ConsoleQtPropListModel::AscendPath()
target_path = entry.path; target_path = entry.path;
target_value = entry.value; target_value = entry.value;
info_proplist = entry.info_proplist; info_proplist = entry.info_proplist;
name_override = entry.name_override;
UpdateValue(true); UpdateValue(true);
break; break;
} }
@ -1725,7 +1730,7 @@ int32_t C4ConsoleQtPropListModel::UpdateValueArray(C4ValueArray *target_array, i
layout_valid = false; layout_valid = false;
property_groups.resize(1); property_groups.resize(1);
} }
property_groups[0].name = LoadResStr("IDS_CNS_ARRAYEDIT"); property_groups[0].name = (name_override ? name_override->GetCStr() : LoadResStr("IDS_CNS_ARRAYEDIT"));
PropertyGroup &properties = property_groups[0]; PropertyGroup &properties = property_groups[0];
if (properties.props.size() != target_array->GetSize()) if (properties.props.size() != target_array->GetSize())
{ {

View File

@ -70,7 +70,7 @@ class C4PropertyDelegate : public QObject
protected: protected:
const class C4PropertyDelegateFactory *factory; const class C4PropertyDelegateFactory *factory;
C4RefCntPointer<C4String> set_function, async_get_function; C4RefCntPointer<C4String> set_function, async_get_function, name;
bool set_function_is_global; bool set_function_is_global;
public: public:
@ -92,6 +92,7 @@ public:
virtual bool HasCustomPaint() const { return false; } virtual bool HasCustomPaint() const { return false; }
virtual void Paint(QPainter *painter, const QStyleOptionViewItem &option, const C4Value &val) const { } virtual void Paint(QPainter *painter, const QStyleOptionViewItem &option, const C4Value &val) const { }
C4PropertyPath GetPathForProperty(struct C4ConsoleQtPropListModelProperty *editor_prop) const; C4PropertyPath GetPathForProperty(struct C4ConsoleQtPropListModelProperty *editor_prop) const;
C4String *GetNameStr() const { return name.Get(); }
signals: signals:
void EditorValueChangedSignal(QWidget *editor) const; void EditorValueChangedSignal(QWidget *editor) const;
@ -483,9 +484,10 @@ public:
// TODO: Would be nice to store only path without values and info_proplist. However, info_proplist is hard to resolve when traversing up // TODO: Would be nice to store only path without values and info_proplist. However, info_proplist is hard to resolve when traversing up
// So just keep the value for now and hope that proplists do not change during selection // So just keep the value for now and hope that proplists do not change during selection
C4Value value, info_proplist; C4Value value, info_proplist;
C4RefCntPointer<C4String> name_override;
TargetStackEntry(const C4PropertyPath &path, const C4Value &value, const C4Value &info_proplist) TargetStackEntry(const C4PropertyPath &path, const C4Value &value, const C4Value &info_proplist, C4String *name_override)
: path(path), value(value), info_proplist(info_proplist) {} : path(path), value(value), info_proplist(info_proplist), name_override(name_override) {}
}; };
struct EditedPath // Information about how to find currently edited element (to restore after model update) struct EditedPath // Information about how to find currently edited element (to restore after model update)
{ {
@ -497,6 +499,7 @@ private:
C4Value base_proplist; // Parent-most value, i.e. object or effect selected in editor through C4Value base_proplist; // Parent-most value, i.e. object or effect selected in editor through
C4Value info_proplist; // Proplist from which available properties are derived. May differ from target_proplist in child proplists. C4Value info_proplist; // Proplist from which available properties are derived. May differ from target_proplist in child proplists.
C4PropertyPath target_path; // script path to target proplist to set values C4PropertyPath target_path; // script path to target proplist to set values
C4RefCntPointer<C4String> name_override; // String to override the name on the first group instead of using info_proplist->GetName() (used only for arrays)
std::list<TargetStackEntry> target_path_stack; // stack of target paths descended into by setting child properties std::list<TargetStackEntry> target_path_stack; // stack of target paths descended into by setting child properties
std::vector<PropertyGroup> property_groups; std::vector<PropertyGroup> property_groups;
QFont header_font; QFont header_font;
@ -511,7 +514,7 @@ public:
bool AddPropertyGroup(C4PropList *add_proplist, int32_t group_index, QString name, C4PropList *ignore_overridden, C4Object *base_effect_object, C4String *default_selection, int32_t *default_selection_index); bool AddPropertyGroup(C4PropList *add_proplist, int32_t group_index, QString name, C4PropList *ignore_overridden, C4Object *base_effect_object, C4String *default_selection, int32_t *default_selection_index);
void SetBasePropList(C4PropList *new_proplist); // Clear stack and select new proplist void SetBasePropList(C4PropList *new_proplist); // Clear stack and select new proplist
void DescendPath(const C4Value &new_value, C4PropList *new_info_proplist, const C4PropertyPath &new_path); // Add proplist to stack void DescendPath(const C4Value &new_value, C4PropList *new_info_proplist, const C4PropertyPath &new_path, C4String *new_name_override); // Add proplist to stack
void AscendPath(); // go back one element in target path stack void AscendPath(); // go back one element in target path stack
void UpdateValue(bool select_default); void UpdateValue(bool select_default);