forked from Mirrors/openclonk
Qt Editor: Fix enum child delegate value setting if a Set path is defined on the parent proplist
parent
58faf41068
commit
1f3e457ec2
|
@ -29,7 +29,7 @@
|
|||
|
||||
/* Property path for property setting synchronization */
|
||||
|
||||
C4PropertyPath::C4PropertyPath(C4PropList *target)
|
||||
C4PropertyPath::C4PropertyPath(C4PropList *target) : get_path_type(PPT_Root), set_path_type(PPT_Root)
|
||||
{
|
||||
// Build string to set target: supports objects only
|
||||
if (target)
|
||||
|
@ -37,13 +37,13 @@ C4PropertyPath::C4PropertyPath(C4PropList *target)
|
|||
C4Object *obj = target->GetObject();
|
||||
if (obj)
|
||||
{
|
||||
path.Format("Object(%d)", (int)obj->Number);
|
||||
root = path;
|
||||
get_path.Format("Object(%d)", (int)obj->Number);
|
||||
root = get_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
C4PropertyPath::C4PropertyPath(C4Effect *fx, C4Object *target_obj)
|
||||
C4PropertyPath::C4PropertyPath(C4Effect *fx, C4Object *target_obj) : get_path_type(PPT_Root), set_path_type(PPT_Root)
|
||||
{
|
||||
// Effect property path: Represent as GetEffect("name", Object(%d), index)
|
||||
if (!fx || !target_obj) return;
|
||||
|
@ -51,31 +51,37 @@ C4PropertyPath::C4PropertyPath(C4Effect *fx, C4Object *target_obj)
|
|||
int32_t index = 0;
|
||||
for (C4Effect *ofx = target_obj->pEffects; ofx; ofx = ofx->pNext)
|
||||
if (ofx == fx) break; else if (!strcmp(ofx->GetName(), name)) ++index;
|
||||
path.Format("GetEffect(\"%s\", Object(%d), %d)", name, (int)target_obj->Number, (int)index);
|
||||
get_path.Format("GetEffect(\"%s\", Object(%d), %d)", name, (int)target_obj->Number, (int)index);
|
||||
root.Format("Object(%d)", (int)target_obj->Number);
|
||||
}
|
||||
|
||||
C4PropertyPath::C4PropertyPath(const C4PropertyPath &parent, int32_t elem_index) : root(parent.root)
|
||||
{
|
||||
path.Format("%s[%d]", parent.GetPath(), (int)elem_index);
|
||||
path_type = PPT_Index;
|
||||
get_path.Format("%s[%d]", parent.GetGetPath(), (int)elem_index);
|
||||
get_path_type = set_path_type = PPT_Index;
|
||||
}
|
||||
|
||||
C4PropertyPath::C4PropertyPath(const C4PropertyPath &parent, const char *child_property, C4PropertyPath::PathType path_type)
|
||||
: path_type(path_type), root(parent.root)
|
||||
C4PropertyPath::C4PropertyPath(const C4PropertyPath &parent, const char *child_property)
|
||||
: get_path_type(PPT_Property), set_path_type(PPT_Property), root(parent.root)
|
||||
{
|
||||
get_path.Format("%s.%s", parent.GetGetPath(), child_property);
|
||||
}
|
||||
|
||||
void C4PropertyPath::SetSetPath(const C4PropertyPath &parent, const char *child_property, C4PropertyPath::PathType path_type)
|
||||
{
|
||||
set_path_type = path_type;
|
||||
if (path_type == PPT_Property)
|
||||
path.Format("%s.%s", parent.GetPath(), child_property);
|
||||
set_path.Format("%s.%s", parent.GetGetPath(), child_property);
|
||||
else if (path_type == PPT_SetFunction)
|
||||
path.Format("%s->%s", parent.GetPath(), child_property);
|
||||
set_path.Format("%s->%s", parent.GetGetPath(), child_property);
|
||||
else if (path_type == PPT_GlobalSetFunction)
|
||||
{
|
||||
path.Copy(parent.GetPath());
|
||||
set_path.Copy(parent.GetGetPath());
|
||||
argument.Copy(child_property);
|
||||
}
|
||||
else if (path_type == PPT_RootSetFunction)
|
||||
{
|
||||
path.Format("%s->%s", parent.GetRoot(), child_property);
|
||||
set_path.Format("%s->%s", parent.GetRoot(), child_property);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -86,13 +92,14 @@ C4PropertyPath::C4PropertyPath(const C4PropertyPath &parent, const char *child_p
|
|||
void C4PropertyPath::SetProperty(const char *set_string) const
|
||||
{
|
||||
// Compose script to update property
|
||||
const char *set_path_c = GetSetPath();
|
||||
StdStrBuf script;
|
||||
if (path_type == PPT_SetFunction || path_type == PPT_RootSetFunction)
|
||||
script.Format("%s(%s)", path.getData(), set_string);
|
||||
else if (path_type == PPT_GlobalSetFunction)
|
||||
script.Format("%s(%s,%s)", argument.getData(), path.getData(), set_string);
|
||||
if (set_path_type == PPT_SetFunction || set_path_type == PPT_RootSetFunction)
|
||||
script.Format("%s(%s)", set_path_c, set_string);
|
||||
else if (set_path_type == PPT_GlobalSetFunction)
|
||||
script.Format("%s(%s,%s)", argument.getData(), set_path_c, set_string);
|
||||
else
|
||||
script.Format("%s=%s", path.getData(), set_string);
|
||||
script.Format("%s=%s", set_path_c, set_string);
|
||||
// Execute synced scripted
|
||||
::Console.EditCursor.EMControl(CID_Script, new C4ControlScript(script.getData(), 0, false));
|
||||
}
|
||||
|
@ -104,15 +111,15 @@ void C4PropertyPath::SetProperty(const C4Value &to_val) const
|
|||
|
||||
C4Value C4PropertyPath::ResolveValue() const
|
||||
{
|
||||
if (!path.getLength()) return C4VNull;
|
||||
return AulExec.DirectExec(::ScriptEngine.GetPropList(), path.getData(), "resolve property", false, nullptr);
|
||||
if (!get_path.getLength()) return C4VNull;
|
||||
return AulExec.DirectExec(::ScriptEngine.GetPropList(), get_path.getData(), "resolve property", false, nullptr);
|
||||
}
|
||||
|
||||
void C4PropertyPath::DoCall(const char *call_string) const
|
||||
{
|
||||
// Compose script call
|
||||
StdStrBuf script;
|
||||
script.Format(call_string, path.getData());
|
||||
script.Format(call_string, get_path.getData());
|
||||
// Execute synced scripted
|
||||
::Console.EditCursor.EMControl(CID_Script, new C4ControlScript(script.getData(), 0, false));
|
||||
}
|
||||
|
@ -210,14 +217,17 @@ C4PropertyPath C4PropertyDelegate::GetPathForProperty(C4ConsoleQtPropListModelPr
|
|||
|
||||
C4PropertyPath C4PropertyDelegate::GetPathForProperty(const C4PropertyPath &parent_path, const char *default_subpath) const
|
||||
{
|
||||
// Get path
|
||||
C4PropertyPath subpath;
|
||||
if (GetSetFunction())
|
||||
subpath = C4PropertyPath(parent_path, GetSetFunction(), set_function_type);
|
||||
if (default_subpath && *default_subpath)
|
||||
subpath = C4PropertyPath(parent_path, default_subpath);
|
||||
else
|
||||
if (default_subpath && *default_subpath)
|
||||
subpath = C4PropertyPath(parent_path, default_subpath);
|
||||
else
|
||||
subpath = parent_path;
|
||||
subpath = parent_path;
|
||||
// Set path
|
||||
if (GetSetFunction())
|
||||
{
|
||||
subpath.SetSetPath(parent_path, GetSetFunction(), set_function_type);
|
||||
}
|
||||
return subpath;
|
||||
}
|
||||
|
||||
|
@ -960,8 +970,7 @@ void C4PropertyDelegateEnum::SetModelData(QObject *aeditor, const C4PropertyPath
|
|||
if (editor->option_changed) SetOptionValue(property_path, option);
|
||||
// Value from a parameter.
|
||||
// Using a setter function?
|
||||
if (option.adelegate->GetSetFunction())
|
||||
use_path = C4PropertyPath(use_path, option.adelegate->GetSetFunction(), C4PropertyPath::PPT_SetFunction);
|
||||
use_path = option.adelegate->GetPathForProperty(use_path, nullptr);
|
||||
option.adelegate->SetModelData(editor->parameter_widget, use_path, prop_shape);
|
||||
}
|
||||
else
|
||||
|
@ -1374,7 +1383,7 @@ C4PropertyDelegateShape::C4PropertyDelegateShape(const class C4PropertyDelegateF
|
|||
|
||||
void C4PropertyDelegateShape::SetModelData(QObject *editor, const C4PropertyPath &property_path, C4ConsoleQtShape *prop_shape) const
|
||||
{
|
||||
if (prop_shape) property_path.SetProperty(prop_shape->GetValue());
|
||||
if (prop_shape && prop_shape->GetParentDelegate() == this) property_path.SetProperty(prop_shape->GetValue());
|
||||
}
|
||||
|
||||
bool C4PropertyDelegateShape::Paint(QPainter *painter, const QStyleOptionViewItem &option, const C4Value &val) const
|
||||
|
@ -1652,7 +1661,7 @@ bool C4ConsoleQtPropListModel::AddPropertyGroup(C4PropList *add_proplist, int32_
|
|||
prop->shape_property_path = new_shape_property_path;
|
||||
if (new_shape_delegate)
|
||||
{
|
||||
C4ConsoleQtShape *shape = ::Console.EditCursor.GetShapes()->CreateShape(base_effect_object ? base_effect_object : target_proplist->GetObject(), new_shape_delegate->GetCreationProps().getPropList(), v);
|
||||
C4ConsoleQtShape *shape = ::Console.EditCursor.GetShapes()->CreateShape(base_effect_object ? base_effect_object : target_proplist->GetObject(), new_shape_delegate->GetCreationProps().getPropList(), v, new_shape_delegate);
|
||||
C4PropertyDelegateFactory *factory = this->delegate_factory;
|
||||
connect(shape, &C4ConsoleQtShape::ShapeDragged, new_shape_delegate, [factory, new_shape_delegate, shape, prop]() {
|
||||
new_shape_delegate->SetModelData(nullptr, prop->shape_property_path, shape);
|
||||
|
|
|
@ -34,7 +34,7 @@ struct C4ConsoleQtPropListModelProperty;
|
|||
class C4PropertyPath
|
||||
{
|
||||
// TODO: For now just storing the path. May want to keep the path info later to allow validation/updating of values
|
||||
StdCopyStrBuf path, argument;
|
||||
StdCopyStrBuf get_path, argument, set_path;
|
||||
StdCopyStrBuf root;
|
||||
|
||||
public:
|
||||
|
@ -46,25 +46,27 @@ public:
|
|||
PPT_SetFunction = 3,
|
||||
PPT_GlobalSetFunction = 4,
|
||||
PPT_RootSetFunction = 5,
|
||||
} path_type;
|
||||
} get_path_type, set_path_type;
|
||||
public:
|
||||
C4PropertyPath() {}
|
||||
C4PropertyPath(C4PropList *target);
|
||||
C4PropertyPath(C4Effect *fx, C4Object *target_obj);
|
||||
C4PropertyPath(const char *path) : path(path), root(path), path_type(PPT_Root) {}
|
||||
C4PropertyPath(const char *path) : get_path(path), root(path), get_path_type(PPT_Root), set_path_type(PPT_Root) {}
|
||||
C4PropertyPath(const C4PropertyPath &parent, int32_t elem_index);
|
||||
C4PropertyPath(const C4PropertyPath &parent, const char *child_property, PathType path_type = PPT_Property);
|
||||
void Clear() { path.Clear(); }
|
||||
const char *GetPath() const { return path.getData(); }
|
||||
C4PropertyPath(const C4PropertyPath &parent, const char *child_property);
|
||||
void SetSetPath(const C4PropertyPath &parent, const char *child_property, PathType path_type);
|
||||
void Clear() { get_path.Clear(); set_path.Clear(); }
|
||||
const char *GetGetPath() const { return get_path.getData(); }
|
||||
const char *GetSetPath() const { return set_path ? set_path.getData() : get_path.getData(); }
|
||||
const char *GetRoot() const { return root.getData(); } // Parent-most path (usually the object)
|
||||
bool IsEmpty() const { return path.getLength() <= 0; }
|
||||
bool IsEmpty() const { return get_path.getLength() <= 0; }
|
||||
|
||||
C4Value ResolveValue() const;
|
||||
void SetProperty(const char *set_string) const;
|
||||
void SetProperty(const C4Value &to_val) const;
|
||||
void DoCall(const char *call_string) const; // Perform a script call where %s is replaced by the current path
|
||||
|
||||
bool operator ==(const C4PropertyPath &v) const { return path == v.path; }
|
||||
bool operator ==(const C4PropertyPath &v) const { return get_path == v.get_path; }
|
||||
};
|
||||
|
||||
class C4PropertyDelegate : public QObject
|
||||
|
@ -564,7 +566,7 @@ public:
|
|||
class C4ValueArray *GetTargetArray() const { return target_value.getArray(); }
|
||||
class C4PropList *GetBasePropList() const { return base_proplist.getPropList(); }
|
||||
int32_t GetTargetPathStackSize() const { return target_path_stack.size(); }
|
||||
const char *GetTargetPathText() const { return target_path.GetPath(); }
|
||||
const char *GetTargetPathText() const { return target_path.GetGetPath(); }
|
||||
bool IsArray() const { return !!target_value.getArray(); }
|
||||
void AddArrayElement();
|
||||
void RemoveArrayElement();
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
/* Generic shape */
|
||||
|
||||
C4ConsoleQtShape::C4ConsoleQtShape(C4Object *for_obj, C4PropList *props)
|
||||
: is_relative(true), dragging_border(-1), border_color(0xffff0000)
|
||||
C4ConsoleQtShape::C4ConsoleQtShape(C4Object *for_obj, C4PropList *props, const class C4PropertyDelegateShape *parent_delegate)
|
||||
: is_relative(true), dragging_border(-1), border_color(0xffff0000), parent_delegate(parent_delegate)
|
||||
{
|
||||
rel_obj.SetPropList(for_obj);
|
||||
if (props)
|
||||
|
@ -68,8 +68,8 @@ int32_t C4ConsoleQtShape::AbsY(int32_t rel_y) const
|
|||
|
||||
/* Rectangular shape*/
|
||||
|
||||
C4ConsoleQtRect::C4ConsoleQtRect(C4Object *for_obj, C4PropList *props, const C4Value &val)
|
||||
: C4ConsoleQtShape(for_obj, props), left(0), top(0), right(10), bottom(10), store_as_proplist(false), properties_lowercase(false)
|
||||
C4ConsoleQtRect::C4ConsoleQtRect(C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate)
|
||||
: C4ConsoleQtShape(for_obj, props, parent_delegate), left(0), top(0), right(10), bottom(10), store_as_proplist(false), properties_lowercase(false)
|
||||
{
|
||||
// Def props
|
||||
if (props)
|
||||
|
@ -187,8 +187,8 @@ C4Value C4ConsoleQtRect::GetValue() const
|
|||
|
||||
/* Circle shape */
|
||||
|
||||
C4ConsoleQtCircle::C4ConsoleQtCircle(class C4Object *for_obj, C4PropList *props, const C4Value &val)
|
||||
: C4ConsoleQtShape(for_obj, props), radius(10), cx(0), cy(0), can_move_center(false)
|
||||
C4ConsoleQtCircle::C4ConsoleQtCircle(class C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate)
|
||||
: C4ConsoleQtShape(for_obj, props, parent_delegate), radius(10), cx(0), cy(0), can_move_center(false)
|
||||
{
|
||||
if (props)
|
||||
{
|
||||
|
@ -287,13 +287,13 @@ C4Value C4ConsoleQtCircle::GetValue() const
|
|||
|
||||
/* Shape list */
|
||||
|
||||
C4ConsoleQtShape *C4ConsoleQtShapes::CreateShape(class C4Object *for_obj, C4PropList *props, const C4Value &val)
|
||||
C4ConsoleQtShape *C4ConsoleQtShapes::CreateShape(class C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate)
|
||||
{
|
||||
C4String *type = props->GetPropertyStr(P_Type);
|
||||
if (!type) return nullptr;
|
||||
C4ConsoleQtShape *shape = nullptr;
|
||||
if (type->GetData() == "rect") shape = new C4ConsoleQtRect(for_obj, props, val);
|
||||
else if (type->GetData() == "circle") shape = new C4ConsoleQtCircle(for_obj, props, val);
|
||||
if (type->GetData() == "rect") shape = new C4ConsoleQtRect(for_obj, props, val, parent_delegate);
|
||||
else if (type->GetData() == "circle") shape = new C4ConsoleQtCircle(for_obj, props, val, parent_delegate);
|
||||
return shape;
|
||||
}
|
||||
|
||||
|
|
|
@ -33,12 +33,13 @@ protected:
|
|||
bool is_relative;
|
||||
int32_t dragging_border;
|
||||
uint32_t border_color;
|
||||
const class C4PropertyDelegateShape *parent_delegate;
|
||||
|
||||
protected:
|
||||
// Return shape color, or dragged border color if index is the border currently being dragged
|
||||
uint32_t GetBorderColor(int32_t border_index, bool dragging_border_is_bitmask) const;
|
||||
public:
|
||||
C4ConsoleQtShape(class C4Object *for_obj, C4PropList *props);
|
||||
C4ConsoleQtShape(class C4Object *for_obj, C4PropList *props, const class C4PropertyDelegateShape *parent_delegate);
|
||||
|
||||
virtual bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border) = 0;
|
||||
virtual void Draw(class C4TargetFacet &cgo, float line_width) = 0;
|
||||
|
@ -56,6 +57,8 @@ public:
|
|||
// Return current shape as C4Value to be stored back to property
|
||||
virtual C4Value GetValue() const = 0;
|
||||
|
||||
const class C4PropertyDelegateShape *GetParentDelegate() const { return parent_delegate; }
|
||||
|
||||
signals:
|
||||
void ShapeDragged();
|
||||
};
|
||||
|
@ -68,7 +71,7 @@ private:
|
|||
bool store_as_proplist;
|
||||
bool properties_lowercase;
|
||||
public:
|
||||
C4ConsoleQtRect(class C4Object *for_obj, C4PropList *props, const C4Value &val);
|
||||
C4ConsoleQtRect(class C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate);
|
||||
|
||||
bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border) override;
|
||||
void Draw(class C4TargetFacet &cgo, float line_width) override;
|
||||
|
@ -85,7 +88,7 @@ private:
|
|||
int32_t cx, cy;
|
||||
bool can_move_center;
|
||||
public:
|
||||
C4ConsoleQtCircle(class C4Object *for_obj, C4PropList *props, const C4Value &val);
|
||||
C4ConsoleQtCircle(class C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate);
|
||||
|
||||
bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border) override;
|
||||
void Draw(class C4TargetFacet &cgo, float line_width) override;
|
||||
|
@ -105,7 +108,7 @@ class C4ConsoleQtShapes
|
|||
public:
|
||||
C4ConsoleQtShapes() : dragging_shape(nullptr), drag_x(0), drag_y(0), drag_cursor(Qt::CursorShape::ArrowCursor) { }
|
||||
|
||||
C4ConsoleQtShape *CreateShape(class C4Object *for_obj, C4PropList *props, const C4Value &val);
|
||||
C4ConsoleQtShape *CreateShape(class C4Object *for_obj, C4PropList *props, const C4Value &val, const class C4PropertyDelegateShape *parent_delegate);
|
||||
void AddShape(C4ConsoleQtShape *shape);
|
||||
void RemoveShape(C4ConsoleQtShape *shape);
|
||||
void ClearShapes();
|
||||
|
|
Loading…
Reference in New Issue