diff options
-rw-r--r-- | spline/spline-widget.cpp | 11 | ||||
-rw-r--r-- | spline/spline-widget.hpp | 4 | ||||
-rw-r--r-- | spline/spline.cpp | 11 | ||||
-rw-r--r-- | spline/spline.hpp | 86 |
4 files changed, 77 insertions, 35 deletions
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index 72f6370e..9a0ae08e 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -47,7 +47,7 @@ spline_widget::~spline_widget() QObject::disconnect(connection); } -void spline_widget::setConfig(spline* spl) +void spline_widget::setConfig(base_spline* spl) { if (connection) { @@ -61,8 +61,8 @@ void spline_widget::setConfig(spline* spl) { update_range(); - std::shared_ptr<spline::settings> s = spl->get_settings(); - connection = connect(s.get(), &spline::settings::recomputed, + std::shared_ptr<base_spline::base_settings> s = spl->get_settings(); + connection = connect(s.get(), &spline::base_settings::recomputed, this, [this]() { reload_spline(); }, Qt::QueuedConnection); } @@ -516,11 +516,6 @@ void spline_widget::mouseReleaseEvent(QMouseEvent *e) void spline_widget::reload_spline() { - if (_config) - { - QList<QPointF> pts = _config->get_points(); - _config->ensure_valid(pts); - } // don't recompute here as the value's about to be recomputed in the callee update_range(); update(); diff --git a/spline/spline-widget.hpp b/spline/spline-widget.hpp index d38eeeee..be80f2bc 100644 --- a/spline/spline-widget.hpp +++ b/spline/spline-widget.hpp @@ -40,7 +40,7 @@ public: spline_widget(QWidget *parent = 0); ~spline_widget(); - void setConfig(spline* spl); + void setConfig(base_spline* spl); QColor colorBezier() const; void setColorBezier(QColor color); @@ -85,7 +85,7 @@ private: QPoint point_to_pixel(const QPointF& point); QPointF c; - spline* _config; + base_spline* _config; QPixmap _background; QPixmap _function; diff --git a/spline/spline.cpp b/spline/spline.cpp index 40a9164b..2fe73a01 100644 --- a/spline/spline.cpp +++ b/spline/spline.cpp @@ -301,7 +301,7 @@ void spline::move_point(int idx, QPointF pt) } } -QList<QPointF> spline::get_points() const +spline::points_t spline::get_points() const { QMutexLocker foo(&_mutex); return s->points; @@ -454,16 +454,16 @@ void spline::ensure_valid(QList<QPointF>& the_points) } // the return value is only safe to use with no spline::set_bundle calls -std::shared_ptr<settings> spline::get_settings() +std::shared_ptr<base_settings> spline::get_settings() { QMutexLocker foo(&_mutex); - return s; + return std::static_pointer_cast<base_settings>(s); } -std::shared_ptr<const settings> spline::get_settings() const +std::shared_ptr<const base_settings> spline::get_settings() const { QMutexLocker foo(&_mutex); - return s; + return std::static_pointer_cast<const base_settings>(s); } double spline::bucket_size_coefficient(const QList<QPointF>& points) const @@ -497,3 +497,4 @@ settings::~settings() } } + diff --git a/spline/spline.hpp b/spline/spline.hpp index 47266165..1bfe3b46 100644 --- a/spline/spline.hpp +++ b/spline/spline.hpp @@ -29,23 +29,66 @@ using namespace options; namespace spline_detail { -class OTR_SPLINE_EXPORT settings final : public QObject +class OTR_SPLINE_EXPORT base_settings : public QObject { Q_OBJECT +signals: + void recomputed() const; +}; + +class OTR_SPLINE_EXPORT settings final : public base_settings +{ public: bundle b; value<QList<QPointF>> points; axis_opts opts; settings(bundle b, const QString& axis_name, Axis idx); ~settings() override; -signals: - void recomputed() const; }; } // ns spline_detail -class OTR_SPLINE_EXPORT spline final +struct OTR_SPLINE_EXPORT base_spline_ +{ + virtual inline ~base_spline_(); + + virtual float get_value(double x) = 0; + virtual float get_value_no_save(double x) const = 0; + + warn_result_unused virtual bool get_last_value(QPointF& point) = 0; + virtual void set_tracking_active(bool value) = 0; + + virtual double max_input() const = 0; + virtual double max_output() const = 0; + + using points_t = QList<QPointF>; + + virtual points_t get_points() const = 0; + virtual int get_point_count() const = 0; + + virtual std::shared_ptr<spline_detail::base_settings> get_settings() = 0; + virtual std::shared_ptr<const spline_detail::base_settings> get_settings() const = 0; +}; + +struct OTR_SPLINE_EXPORT spline_modify_mixin +{ + virtual void add_point(QPointF pt) = 0; + virtual void add_point(double x, double y) = 0; + virtual void move_point(int idx, QPointF pt) = 0; + virtual void remove_point(int i) = 0; + virtual void clear() = 0; + + virtual inline ~spline_modify_mixin(); +}; + +class OTR_SPLINE_EXPORT base_spline : public base_spline_, public spline_modify_mixin +{ +public: + using base_settings = spline_detail::base_settings; +}; + +class OTR_SPLINE_EXPORT spline : public base_spline { double bucket_size_coefficient(const QList<QPointF>& points) const; void update_interp_data(); @@ -80,8 +123,8 @@ public: void save(); void set_bundle(bundle b, const QString& axis_name, Axis axis); - double max_input() const; - double max_output() const; + double max_input() const override; + double max_output() const override; spline(); spline(const QString& name, const QString& axis_name, Axis axis); @@ -90,26 +133,29 @@ public: spline& operator=(const spline&) = default; spline(const spline&) = default; - float get_value(double x); - float get_value_no_save(double x) const; - warn_result_unused bool get_last_value(QPointF& point); - void remove_point(int i); - void clear(); + float get_value(double x) override; + float get_value_no_save(double x) const override; + warn_result_unused bool get_last_value(QPointF& point) override; + + void add_point(QPointF pt) override; + void add_point(double x, double y) override; + void move_point(int idx, QPointF pt) override; + void remove_point(int i) override; + void clear() override; - void add_point(QPointF pt); - void add_point(double x, double y); - void move_point(int idx, QPointF pt); - QList<QPointF> get_points() const; + points_t get_points() const override; - void set_tracking_active(bool value); + void set_tracking_active(bool value) override; bundle get_bundle(); void ensure_valid(QList<QPointF>& the_points); - std::shared_ptr<spline_detail::settings> get_settings(); - std::shared_ptr<const spline_detail::settings> get_settings() const; + std::shared_ptr<spline_detail::base_settings> get_settings() override; + std::shared_ptr<const spline_detail::base_settings> get_settings() const override; - using points_t = decltype(s->points()); - int get_point_count() const; + int get_point_count() const override; using settings = spline_detail::settings; }; + +inline base_spline_::~base_spline_() {} +inline spline_modify_mixin::~spline_modify_mixin() {} |