forked from Mirrors/openclonk
Editor: Add OnUpdate to all delegates and EditorPropertyChanged callbacks to selected root object
parent
c7feea408d
commit
5032e61dea
|
@ -177,6 +177,7 @@ C4PropertyDelegate::C4PropertyDelegate(const C4PropertyDelegateFactory *factory,
|
|||
set_function_type = C4PropertyPath::PPT_SetFunction;
|
||||
}
|
||||
async_get_function = props->GetPropertyStr(P_AsyncGet);
|
||||
update_callback = props->GetPropertyStr(P_OnUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,6 +284,7 @@ void C4PropertyDelegateInt::SetModelData(QObject *editor, const C4PropertyPath &
|
|||
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
property_path.SetProperty(C4VInt(spinBox->value()));
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
}
|
||||
|
||||
QWidget *C4PropertyDelegateInt::CreateEditor(const C4PropertyDelegateFactory *parent_delegate, QWidget *parent, const QStyleOptionViewItem &option, bool by_selection, bool is_child) const
|
||||
|
@ -332,6 +334,7 @@ void C4PropertyDelegateString::SetModelData(QObject *editor, const C4PropertyPat
|
|||
// TODO: Would be better to handle escaping in the C4Value-to-string code
|
||||
new_value = new_value.replace("\\", "\\\\").replace("\"", "\\\"");
|
||||
property_path.SetProperty(C4VString(new_value.toUtf8()));
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
line_edit->commit_pending = false;
|
||||
}
|
||||
}
|
||||
|
@ -739,6 +742,7 @@ void C4PropertyDelegateColor::SetModelData(QObject *aeditor, const C4PropertyPat
|
|||
{
|
||||
Editor *editor = static_cast<Editor *>(aeditor);
|
||||
property_path.SetProperty(editor->last_value);
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
}
|
||||
|
||||
QWidget *C4PropertyDelegateColor::CreateEditor(const class C4PropertyDelegateFactory *parent_delegate, QWidget *parent, const QStyleOptionViewItem &option, bool by_selection, bool is_child) const
|
||||
|
@ -1459,6 +1463,7 @@ void C4PropertyDelegateEnum::SetOptionValue(const C4PropertyPath &use_path, cons
|
|||
C4PropList *option_props = option.props.getPropList();
|
||||
use_path.SetProperty(option_value, ignore_base_props_static);
|
||||
}
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(use_path, this);
|
||||
}
|
||||
|
||||
QWidget *C4PropertyDelegateEnum::CreateEditor(const C4PropertyDelegateFactory *parent_delegate, QWidget *parent, const QStyleOptionViewItem &option, bool by_selection, bool is_child) const
|
||||
|
@ -1977,6 +1982,7 @@ void C4PropertyDelegateC4ValueInput::SetModelData(QObject *aeditor, const C4Prop
|
|||
if (editor->commit_pending)
|
||||
{
|
||||
property_path.SetProperty(editor->edit->text().toUtf8());
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
editor->commit_pending = false;
|
||||
}
|
||||
}
|
||||
|
@ -2020,7 +2026,11 @@ void C4PropertyDelegateShape::SetModelData(QObject *editor, const C4PropertyPath
|
|||
// Only set shape data if triggered through shape movement signal; ignore update calls from e.g. parent enum editor
|
||||
if (!editor)
|
||||
{
|
||||
if (prop_shape && prop_shape->GetParentDelegate() == this) property_path.SetProperty(prop_shape->GetValue());
|
||||
if (prop_shape && prop_shape->GetParentDelegate() == this)
|
||||
{
|
||||
property_path.SetProperty(prop_shape->GetValue());
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2179,7 +2189,6 @@ C4PropertyDelegateGraph::C4PropertyDelegateGraph(const class C4PropertyDelegateF
|
|||
horizontal_fix = props->GetPropertyBool(P_HorizontalFix);
|
||||
vertical_fix = props->GetPropertyBool(P_VerticalFix);
|
||||
structure_fix = props->GetPropertyBool(P_StructureFix);
|
||||
update_callback = props->GetPropertyStr(P_OnUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2265,10 +2274,7 @@ void C4PropertyDelegateGraph::ConnectSignals(C4ConsoleQtShape *shape, const C4Pr
|
|||
// Send graph editing via queue
|
||||
::Control.DoInput(CID_EditGraph, new C4ControlEditGraph(property_path.GetGetPath(), action, index, x, y), CDT_Decide);
|
||||
// Also send update callback to root object
|
||||
if (update_callback)
|
||||
{
|
||||
::Console.EditCursor.EMControl(CID_Script, new C4ControlScript(FormatString("%s->%s(%s)", property_path.GetRoot(), update_callback->GetCStr(), property_path.GetGetPath()).getData(), 0, false));
|
||||
}
|
||||
factory->GetPropertyModel()->DoOnUpdateCall(property_path, this);
|
||||
});
|
||||
connect(shape, &C4ConsoleQtShape::BorderSelectionChanged, this, []() {
|
||||
// Different part of the shape selected: Refresh info on next update
|
||||
|
@ -2430,7 +2436,8 @@ void C4PropertyDelegateFactory::setModelData(QWidget *editor, QAbstractItemModel
|
|||
void C4PropertyDelegateFactory::SetPropertyData(const C4PropertyDelegate *d, QObject *editor, C4ConsoleQtPropListModel::Property *editor_prop) const
|
||||
{
|
||||
// Set according to delegate
|
||||
d->SetModelData(editor, d->GetPathForProperty(editor_prop), editor_prop->shape ? editor_prop->shape->Get() : nullptr);
|
||||
const C4PropertyPath set_path = d->GetPathForProperty(editor_prop);
|
||||
d->SetModelData(editor, set_path, editor_prop->shape ? editor_prop->shape->Get() : nullptr);
|
||||
}
|
||||
|
||||
QWidget *C4PropertyDelegateFactory::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
|
@ -3111,6 +3118,23 @@ int32_t C4ConsoleQtPropListModel::UpdateValueArray(C4ValueArray *target_array, i
|
|||
return 1; // one group for the values
|
||||
}
|
||||
|
||||
void C4ConsoleQtPropListModel::DoOnUpdateCall(const C4PropertyPath &updated_path, const C4PropertyDelegate *delegate)
|
||||
{
|
||||
// If delegate has its own update clalback, perform that on the root
|
||||
const char *update_callback = delegate->GetUpdateCallback();
|
||||
if (update_callback)
|
||||
{
|
||||
::Console.EditCursor.EMControl(CID_Script, new C4ControlScript(FormatString("%s->%s(%s)", updated_path.GetRoot(), update_callback, updated_path.GetGetPath()).getData(), 0, false));
|
||||
}
|
||||
// Do general object property update control
|
||||
C4PropList *base_proplist = this->base_proplist.getPropList();
|
||||
C4Value q;
|
||||
if (base_proplist && base_proplist->GetProperty(P_EditorPropertyChanged, &q))
|
||||
{
|
||||
::Console.EditCursor.EMControl(CID_Script, new C4ControlScript(FormatString("%s->%s(\"%s\")", updated_path.GetRoot(), ::Strings.P[P_EditorPropertyChanged].GetCStr(), updated_path.GetGetPath()).getData(), 0, false));
|
||||
}
|
||||
}
|
||||
|
||||
C4ConsoleQtPropListModel::Property *C4ConsoleQtPropListModel::GetPropByIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid()) return nullptr;
|
||||
|
|
|
@ -80,6 +80,7 @@ protected:
|
|||
C4Value creation_props;
|
||||
C4RefCntPointer<C4String> set_function, async_get_function, name;
|
||||
C4PropertyPath::PathType set_function_type;
|
||||
C4RefCntPointer<C4String> update_callback;
|
||||
|
||||
public:
|
||||
C4PropertyDelegate(const class C4PropertyDelegateFactory *factory, C4PropList *props);
|
||||
|
@ -97,6 +98,7 @@ public:
|
|||
const char *GetSetFunction() const { return set_function.Get() ? set_function->GetCStr() : nullptr; } // get name of setter function for this property
|
||||
virtual const class C4PropertyDelegateShape *GetShapeDelegate(C4Value &val, C4PropertyPath *shape_path) const { return nullptr; }
|
||||
virtual const class C4PropertyDelegateShape *GetDirectShapeDelegate() const { return nullptr; }
|
||||
const char *GetUpdateCallback() const { return update_callback ? update_callback->GetCStr() : nullptr; }
|
||||
virtual bool HasCustomPaint() const { return false; }
|
||||
virtual bool Paint(QPainter *painter, const QStyleOptionViewItem &option, const C4Value &val) const { return false; }
|
||||
virtual C4PropertyPath GetPathForProperty(struct C4ConsoleQtPropListModelProperty *editor_prop) const;
|
||||
|
@ -563,7 +565,6 @@ class C4PropertyDelegateGraph : public C4PropertyDelegateShape
|
|||
bool horizontal_fix = false;
|
||||
bool vertical_fix = false;
|
||||
bool structure_fix = false;
|
||||
C4RefCntPointer<C4String> update_callback;
|
||||
|
||||
void DoPaint(QPainter *painter, const QRect &inner_rect) const override;
|
||||
protected:
|
||||
|
@ -707,7 +708,7 @@ public:
|
|||
};
|
||||
private:
|
||||
C4Value target_value; // Target value for which properties are listed (either proplist or array)
|
||||
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 and framed in editor
|
||||
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
|
||||
std::list<TargetStackEntry> target_path_stack; // stack of target paths descended into by setting child properties
|
||||
|
@ -730,6 +731,7 @@ public:
|
|||
void DescendPath(const C4Value &new_value, C4PropList *new_info_proplist, const C4PropertyPath &new_path); // Add proplist to stack
|
||||
void AscendPath(); // go back one element in target path stack
|
||||
void UpdateValue(bool select_default);
|
||||
void DoOnUpdateCall(const C4PropertyPath &updated_path, const C4PropertyDelegate *delegate);
|
||||
|
||||
private:
|
||||
int32_t UpdateValuePropList(C4PropList *target_proplist, int32_t *default_selection_group, int32_t *default_selection_index);
|
||||
|
|
|
@ -271,6 +271,7 @@ C4StringTable::C4StringTable()
|
|||
P[P_VerticalFix] = "VerticalFix";
|
||||
P[P_StructureFix] = "StructureFix";
|
||||
P[P_OnUpdate] = "OnUpdate";
|
||||
P[P_EditorPropertyChanged] = "EditorPropertyChanged";
|
||||
P[P_Min] = "Min";
|
||||
P[P_Max] = "Max";
|
||||
P[P_Set] = "Set";
|
||||
|
|
|
@ -495,6 +495,7 @@ enum C4PropertyName
|
|||
P_VerticalFix,
|
||||
P_StructureFix,
|
||||
P_OnUpdate,
|
||||
P_EditorPropertyChanged,
|
||||
P_Min,
|
||||
P_Max,
|
||||
P_Set,
|
||||
|
|
Loading…
Reference in New Issue