diff --git a/src/live_effects/lpe-bendpath.cpp b/src/live_effects/lpe-bendpath.cpp index 53f27890dd2f502793980465824aef2983ef8e1e..59698fc821d2c48b89a9e5a005c08e3bdd778abf 100644 --- a/src/live_effects/lpe-bendpath.cpp +++ b/src/live_effects/lpe-bendpath.cpp @@ -47,7 +47,7 @@ class KnotHolderEntityWidthBendPath : public LPEKnotHolderEntity { ~KnotHolderEntityWidthBendPath() override { LPEBendPath *lpe = dynamic_cast (_effect); - lpe->_knot_entity = nullptr; + lpe->_knotholder = nullptr; } void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) override; Geom::Point knot_get() const override; @@ -72,13 +72,18 @@ LPEBendPath::LPEBendPath(LivePathEffectObject *lpeobject) : prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); - _knot_entity = nullptr; + _knotholder = nullptr; _provides_knotholder_entities = true; apply_to_clippath_and_mask = true; concatenate_before_pwd2 = true; } -LPEBendPath::~LPEBendPath() = default; +LPEBendPath::~LPEBendPath() { + if (_knotholder) { + _knotholder->clear(); + _knotholder = nullptr; + } +}; bool @@ -101,14 +106,14 @@ LPEBendPath::doBeforeEffect (SPLPEItem const* lpeitem) if (is_load) { bend_path.reload(); } - if (_knot_entity) { + if (_knotholder) { if (hide_knot) { helper_path.clear(); - _knot_entity->knot->hide(); + _knotholder->entity.front()->knot->hide(); } else { - _knot_entity->knot->show(); + _knotholder->entity.front()->knot->show(); } - _knot_entity->update_knot(); + _knotholder->update_knots(); } } @@ -215,13 +220,14 @@ LPEBendPath::addCanvasIndicators(SPLPEItem const */*lpeitem*/, std::vectorcreate(nullptr, item, knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:WidthBend", + _knotholder = knotholder; + KnotHolderEntity *knot_entity = new BeP::KnotHolderEntityWidthBendPath(this); + knot_entity->create(nullptr, item, _knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:WidthBend", _("Change the width")); - knotholder->add(_knot_entity); + _knotholder->add(knot_entity); if (hide_knot) { - _knot_entity->knot->hide(); - _knot_entity->update_knot(); + knot_entity->knot->hide(); + knot_entity->update_knot(); } } diff --git a/src/live_effects/lpe-bendpath.h b/src/live_effects/lpe-bendpath.h index 88b8ca2b43709a8898dce6b5417c86ce505ff119..511ad194d464eaef7bb5e1d6820e271d9de1907b 100644 --- a/src/live_effects/lpe-bendpath.h +++ b/src/live_effects/lpe-bendpath.h @@ -63,7 +63,7 @@ private: BoolParam scale_y_rel; BoolParam vertical_pattern; BoolParam hide_knot; - KnotHolderEntity * _knot_entity; + KnotHolder *_knotholder; Geom::PathVector helper_path; Geom::Piecewise > uskeleton; Geom::Piecewise > n; diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index cf1789835c2c655215c5ed43920105fd19ba7842..03b12e611d35962a524333a9cf5d8ce498d98742 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -282,8 +282,8 @@ Gtk::Widget *LPEFilletChamfer::newWidget() void LPEFilletChamfer::refreshKnots() { - if (nodesatellites_param._knoth) { - nodesatellites_param._knoth->update_knots(); + if (nodesatellites_param._knotholder) { + nodesatellites_param._knotholder->update_knots(); } } diff --git a/src/live_effects/lpe-tiling.cpp b/src/live_effects/lpe-tiling.cpp index ff4c38d039e9e95a3cad9b72a02bfd1c4307b87f..8f738d92146b946973d79556594ac71a78a0b8fa 100644 --- a/src/live_effects/lpe-tiling.cpp +++ b/src/live_effects/lpe-tiling.cpp @@ -162,7 +162,12 @@ LPETiling::LPETiling(LivePathEffectObject *lpeobject) : reset = link_styles; } -LPETiling::~LPETiling() = default; +LPETiling::~LPETiling(){ + if (_knotholder) { + _knotholder->clear(); + _knotholder = nullptr; + } +}; bool LPETiling::doOnOpen(SPLPEItem const *lpeitem) { bool fixed = false; diff --git a/src/live_effects/lpe-tiling.h b/src/live_effects/lpe-tiling.h index 761d3d3c2e51a1c0097ee4e429beb60b45b7f6ce..de49af4c5c74fd23d4f2648748af57c56ef20845 100644 --- a/src/live_effects/lpe-tiling.h +++ b/src/live_effects/lpe-tiling.h @@ -54,7 +54,7 @@ public: void addKnotHolderEntities(KnotHolder * knotholder, SPItem * item) override; protected: void addCanvasIndicators(SPLPEItem const *lpeitem, std::vector &hp_vec) override; - KnotHolder *_knotholder; + KnotHolder *_knotholder = nullptr; double gapx_unit = 0; double gapy_unit = 0; double offset_unit = 0; diff --git a/src/live_effects/parameter/nodesatellitesarray.cpp b/src/live_effects/parameter/nodesatellitesarray.cpp index 2bc4c9fdbeec2ed1f03f50c527ad9e981b8ec1bc..2ca585a389dd9aa26263cbf1b42a6618605156ac 100644 --- a/src/live_effects/parameter/nodesatellitesarray.cpp +++ b/src/live_effects/parameter/nodesatellitesarray.cpp @@ -33,11 +33,29 @@ NodeSatelliteArrayParam::NodeSatelliteArrayParam(const Glib::ustring &label, con const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect) : ArrayParam>(label, tip, key, wr, effect, 0) - , _knoth(nullptr) + , _knotholder(nullptr) { param_widget_is_visible(false); } +NodeSatelliteArrayParam::~NodeSatelliteArrayParam() +{ + // caution: + // we are using this on corners/fillet LPE + // if we do on other LPE and the LPE + // handle its knotholder we need to reset it also in + // effect with something like + // if (param_effect->effectTipe = MY_NEW_LPE) { + // param_effect->knotholder = nullptr + // } + // and do the same in reverse in the same block + // in the destruction of the effect + if (_knotholder) { + _knotholder->clear(); + _knotholder = nullptr; + } +} + void NodeSatelliteArrayParam::set_oncanvas_looks(Inkscape::CanvasItemCtrlShape shape, Inkscape::CanvasItemCtrlMode mode, guint32 color) { @@ -256,8 +274,8 @@ void NodeSatelliteArrayParam::updateAmmount(double amount) void NodeSatelliteArrayParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { - _knoth = knotholder; - addKnotHolderEntities(knotholder, item, true); + _knotholder = knotholder; + addKnotHolderEntities(_knotholder, item, true); } FilletChamferKnotHolderEntity::FilletChamferKnotHolderEntity(NodeSatelliteArrayParam *p, size_t index) diff --git a/src/live_effects/parameter/nodesatellitesarray.h b/src/live_effects/parameter/nodesatellitesarray.h index 1c3761e81e785a9ad948aea681b7125d44152a6a..597f3144bdb79bad5cf6494a71589f9580aab9d0 100644 --- a/src/live_effects/parameter/nodesatellitesarray.h +++ b/src/live_effects/parameter/nodesatellitesarray.h @@ -25,6 +25,7 @@ #include "live_effects/effect-enum.h" #include "live_effects/parameter/array.h" #include "ui/knot/knot-holder-entity.h" +#include "ui/knot/knot-holder.h" namespace Inkscape { @@ -38,6 +39,8 @@ public: NodeSatelliteArrayParam(const Glib::ustring &label, const Glib::ustring &tip, const Glib::ustring &key, Inkscape::UI::Widget::Registry *wr, Effect *effect); + ~NodeSatelliteArrayParam() override; + Gtk::Widget *param_newWidget() override { return nullptr; @@ -69,7 +72,7 @@ public: friend class LPEFilletChamfer; ParamType paramType() const override { return ParamType::NODE_SATELLITE_ARRAY; }; protected: - KnotHolder *_knoth; + KnotHolder *_knotholder = nullptr; private: NodeSatelliteArrayParam(const NodeSatelliteArrayParam &) = delete; @@ -91,7 +94,7 @@ public: FilletChamferKnotHolderEntity(NodeSatelliteArrayParam *p, size_t index); ~FilletChamferKnotHolderEntity() override { - _pparam->_knoth = nullptr; + _pparam->_knotholder = nullptr; } void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) override; diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index c461bbd4d393a1334a7f13fcb66bceaedffd3aac..e786c41895baa12d72a5fd9a87f4103a6aeba00c 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -35,8 +35,16 @@ PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, } PointParam::~PointParam() { - if (handle_tip) + if (handle_tip) { g_free(handle_tip); + } + // this must be changed adding + // entity remove to knotholder in 1.4 + // mr pending + if (_knotholder) { + _knotholder->clear(); + _knotholder = nullptr; + } } void @@ -77,17 +85,18 @@ PointParam::param_update_default(const gchar * default_point) void PointParam::param_hide_knot(bool hide) { - if (_knot_entity) { + if (_knotholder && !_knotholder->entity.empty()) { bool update = false; - if (hide && _knot_entity->knot->flags & SP_KNOT_VISIBLE) { + auto knot = _knotholder->entity.front()->knot; + if (hide && knot->flags & SP_KNOT_VISIBLE) { update = true; - _knot_entity->knot->hide(); - } else if(!hide && !(_knot_entity->knot->flags & SP_KNOT_VISIBLE)) { + knot->hide(); + } else if(!hide && !(knot->flags & SP_KNOT_VISIBLE)) { update = true; - _knot_entity->knot->show(); + knot->show(); } if (update) { - _knot_entity->update_knot(); + _knotholder->update_knots(); } } } @@ -103,9 +112,10 @@ PointParam::param_setValue(Geom::Point newpoint, bool write) param_write_to_repr(str); g_free(str); } - if(_knot_entity && liveupdate){ - _knot_entity->update_knot(); + if(_knotholder && liveupdate){ + _knotholder->update_knots(); } + } bool @@ -186,7 +196,9 @@ PointParam::set_oncanvas_looks(Inkscape::CanvasItemCtrlShape shape, class PointParamKnotHolderEntity : public KnotHolderEntity { public: PointParamKnotHolderEntity(PointParam *p) { this->pparam = p; } - ~PointParamKnotHolderEntity() override { this->pparam->_knot_entity = nullptr;} + ~PointParamKnotHolderEntity() override { + this->pparam->_knotholder = nullptr; + } void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state) override; Geom::Point knot_get() const override; @@ -246,11 +258,12 @@ PointParamKnotHolderEntity::knot_click(guint state) void PointParam::addKnotHolderEntities(KnotHolder *knotholder, SPItem *item) { - _knot_entity = new PointParamKnotHolderEntity(this); + _knotholder = knotholder; + KnotHolderEntity *knot_entity = new PointParamKnotHolderEntity(this); // TODO: can we ditch handleTip() etc. because we have access to handle_tip etc. itself??? - _knot_entity->create(nullptr, item, knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:Point", + knot_entity->create(nullptr, item, _knotholder, Inkscape::CANVAS_ITEM_CTRL_TYPE_LPE, "LPE:Point", handleTip(), knot_color); - knotholder->add(_knot_entity); + _knotholder->add(knot_entity); } } /* namespace LivePathEffect */ diff --git a/src/live_effects/parameter/point.h b/src/live_effects/parameter/point.h index 0f45c6226678ab1329ca3620c372a33dfb50fb2d..dd3ff79fa4d38ab34dc0034c6b75ba69403f36d1 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -69,7 +69,7 @@ private: bool on_button_release(GdkEventButton* button_event); Geom::Point defvalue; bool liveupdate; - KnotHolderEntity * _knot_entity = nullptr; + KnotHolder * _knotholder = nullptr; Inkscape::CanvasItemCtrlShape knot_shape = Inkscape::CANVAS_ITEM_CTRL_SHAPE_DIAMOND; Inkscape::CanvasItemCtrlMode knot_mode = Inkscape::CANVAS_ITEM_CTRL_MODE_XOR; guint32 knot_color = 0xffffff00; diff --git a/src/ui/knot/knot-holder.cpp b/src/ui/knot/knot-holder.cpp index 138d8093278826a31a0f7a8463cd9bc5e059da79..605508d0db4da15fbced7f49dd0a85395145f6bf 100644 --- a/src/ui/knot/knot-holder.cpp +++ b/src/ui/knot/knot-holder.cpp @@ -75,7 +75,12 @@ KnotHolder::KnotHolder(SPDesktop *desktop, SPItem *item, SPKnotHolderReleasedFun KnotHolder::~KnotHolder() { sp_object_unref(item); + clear(); +} +void +KnotHolder::clear() +{ for (auto & i : entity) { delete i; } diff --git a/src/ui/knot/knot-holder.h b/src/ui/knot/knot-holder.h index 0584182a0259fd11f4e6526db1ac70d3ad7da187..22ea853aebcc097a0667c8641b344c783b6ba6dc 100644 --- a/src/ui/knot/knot-holder.h +++ b/src/ui/knot/knot-holder.h @@ -52,7 +52,7 @@ public: virtual ~KnotHolder(); KnotHolder() = delete; // declared but not defined - + void clear(); void update_knots(); void unselect_knots(); void knot_mousedown_handler(SPKnot *knot, unsigned int state);