summaryrefslogtreecommitdiffhomepage
path: root/spline
diff options
context:
space:
mode:
Diffstat (limited to 'spline')
-rw-r--r--spline/spline-widget.cpp20
-rw-r--r--spline/spline.cpp42
-rw-r--r--spline/spline.hpp13
3 files changed, 42 insertions, 33 deletions
diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp
index 7aeaf590..2120d0ae 100644
--- a/spline/spline-widget.cpp
+++ b/spline/spline-widget.cpp
@@ -345,7 +345,7 @@ void spline_widget::drawLine(QPainter& painter, const QPointF& start, const QPoi
void spline_widget::mousePressEvent(QMouseEvent *e)
{
- if (!config || !isEnabled() || !is_in_bounds(e->localPos()) || preview_only)
+ if (!config || !isEnabled() || !is_in_bounds(e->position()) || preview_only)
return;
const double min_dist = min_pt_distance();
@@ -360,7 +360,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
for (int i = 0; i < points.size(); i++)
{
- if (point_within_pixel(points[i], e->localPos()))
+ if (point_within_pixel(points[i], e->position()))
{
is_touching_point = true;
moving_control_point_idx = i;
@@ -371,7 +371,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
if (!is_touching_point)
{
bool too_close = false;
- const QPointF pos = pixel_to_point(e->localPos());
+ const QPointF pos = pixel_to_point(e->position());
for (QPointF const& point : points)
{
@@ -385,7 +385,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
if (!too_close)
{
- config->add_point(pixel_to_point(e->localPos()));
+ config->add_point(pixel_to_point(e->position()));
show_tooltip(e->pos());
}
}
@@ -399,7 +399,7 @@ void spline_widget::mousePressEvent(QMouseEvent *e)
{
for (int i = 0; i < points.size(); i++)
{
- if (point_within_pixel(points[i], e->localPos()))
+ if (point_within_pixel(points[i], e->position()))
{
config->remove_point(i);
draw_function = true;
@@ -434,7 +434,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e)
if (i >= 0 && i < sz)
{
const double min_dist = min_pt_distance();
- QPointF new_pt = pixel_to_point(e->localPos());
+ QPointF new_pt = pixel_to_point(e->position());
const bool has_prev = i > 0, has_next = i + 1 < points.size();
@@ -469,7 +469,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e)
else if (sz)
{
int i;
- bool is_on_point = is_on_pt(e->localPos(), &i);
+ bool is_on_point = is_on_pt(e->position(), &i);
if (is_on_point)
{
@@ -479,7 +479,7 @@ void spline_widget::mouseMoveEvent(QMouseEvent *e)
else
{
setCursor(Qt::ArrowCursor);
- if (is_in_bounds(e->localPos()))
+ if (is_in_bounds(e->position()))
show_tooltip(e->pos());
else
QToolTip::hideText();
@@ -498,13 +498,13 @@ void spline_widget::mouseReleaseEvent(QMouseEvent *e)
if (e->button() == Qt::LeftButton)
{
{
- if (is_on_pt(e->localPos(), nullptr))
+ if (is_on_pt(e->position(), nullptr))
setCursor(Qt::CrossCursor);
else
setCursor(Qt::ArrowCursor);
}
- if (is_in_bounds(e->localPos()))
+ if (is_in_bounds(e->position()))
show_tooltip(e->pos());
else
QToolTip::hideText();
diff --git a/spline/spline.cpp b/spline/spline.cpp
index 21044b34..d5708476 100644
--- a/spline/spline.cpp
+++ b/spline/spline.cpp
@@ -31,7 +31,7 @@ spline::spline(const QString& name, const QString& axis_name, Axis axis)
spline::~spline()
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
disconnect_signals();
}
@@ -41,7 +41,7 @@ void spline::set_tracking_active(bool value) const
{
std::shared_ptr<settings> S;
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
activep = value;
}
@@ -50,7 +50,7 @@ void spline::set_tracking_active(bool value) const
bundle spline::get_bundle()
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
return s->b;
}
@@ -58,7 +58,7 @@ void spline::clear()
{
std::shared_ptr<settings> S;
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
s->points = {};
points = {};
@@ -69,7 +69,7 @@ void spline::clear()
double spline::get_value(double x) const
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
const double ret = get_value_no_save(x);
last_input_value = { std::fabs(x), std::fabs((double)ret) };
@@ -78,7 +78,7 @@ double spline::get_value(double x) const
double spline::get_value_no_save(double x) const
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
double q = x * bucket_size_coefficient(points);
int xi = (int)q;
@@ -91,7 +91,7 @@ double spline::get_value_no_save(double x) const
bool spline::get_last_value(QPointF& point)
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
point = last_input_value;
return activep && point.y() >= 0;
}
@@ -129,7 +129,7 @@ void spline::ensure_in_bounds(const QList<QPointF>& points, int i, f& x, f& y)
int spline::element_count(const QList<QPointF>& points, double max_input)
{
- const unsigned sz = (unsigned)points.size();
+ const int sz = points.size();
for (int k = sz-1; k >= 0; k--)
{
const QPointF& pt = points[k];
@@ -248,14 +248,14 @@ void spline::remove_point(int i)
{
std::shared_ptr<settings> S;
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
const int sz = element_count(points, max_input());
if (i >= 0 && i < sz)
{
- points.erase(points.begin() + i);
+ points.erase(points.cbegin() + i);
s->points = points;
update_interp_data();
}
@@ -268,7 +268,7 @@ void spline::add_point(QPointF pt)
{
std::shared_ptr<settings> S;
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
points.push_back(pt);
std::stable_sort(points.begin(), points.end(), sort_fn);
@@ -287,7 +287,7 @@ void spline::move_point(int idx, QPointF pt)
{
std::shared_ptr<settings> S;
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
const int sz = element_count(points, max_input());
@@ -310,19 +310,19 @@ const points_t& spline::get_points() const
int spline::get_point_count() const
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
return element_count(points, clamp_x);
}
void spline::reload()
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
s->b->reload();
}
void spline::save()
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
s->b->save();
}
@@ -338,7 +338,7 @@ void spline::invalidate_settings()
{
std::shared_ptr<settings> S;
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
S = s;
invalidate_settings_();
}
@@ -353,7 +353,7 @@ void spline::set_bundle(bundle b, const QString& axis_name, Axis axis)
std::shared_ptr<settings> S;
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
disconnect_signals();
s = std::make_shared<settings>(b, axis_name, axis);
@@ -373,7 +373,7 @@ void spline::set_bundle(bundle b, const QString& axis_name, Axis axis)
double spline::max_input() const
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
if (clamp_x == axis_opts::x1000)
return std::fmax(1, points.empty() ? 0 : points[points.size() - 1].x());
return std::fabs((double)clamp_x);
@@ -381,7 +381,7 @@ double spline::max_input() const
double spline::max_output() const
{
- QMutexLocker l(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
if (clamp_y == axis_opts::x1000 && !points.empty())
return std::fmax(1, points.empty() ? 0 : points[points.size() - 1].y());
return std::fabs((double)clamp_y);
@@ -446,13 +446,13 @@ void spline::ensure_valid(points_t& list) const
std::shared_ptr<base_settings> spline::get_settings()
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
return std::static_pointer_cast<base_settings>(s);
}
std::shared_ptr<const base_settings> spline::get_settings() const
{
- QMutexLocker foo(&mtx);
+ [[maybe_unused]] QMutexLocker l(*mtx);
return std::static_pointer_cast<const base_settings>(s);
}
diff --git a/spline/spline.hpp b/spline/spline.hpp
index e4f64069..4aeaec2f 100644
--- a/spline/spline.hpp
+++ b/spline/spline.hpp
@@ -11,7 +11,6 @@
#include "options/options.hpp"
#include "axis-opts.hpp"
#include "export.hpp"
-#include "compat/mutex.hpp"
#include <cstddef>
#include <vector>
@@ -21,6 +20,7 @@
#include <QObject>
#include <QPointF>
#include <QString>
+#include <QRecursiveMutex>
#include <QMetaObject>
namespace spline_detail {
@@ -103,6 +103,15 @@ struct OTR_SPLINE_EXPORT base_spline : base_spline_, spline_modify_mixin, spline
~base_spline() override;
};
+struct mutex
+{
+ mutable QRecursiveMutex inner;
+ auto* operator*() { return &inner; }
+ auto* operator->() { return &inner; }
+ mutex() = default;
+ mutex(const mutex&) {}
+};
+
class OTR_SPLINE_EXPORT spline : public base_spline
{
using f = float;
@@ -118,12 +127,12 @@ class OTR_SPLINE_EXPORT spline : public base_spline
void disconnect_signals();
void invalidate_settings_();
- mutex mtx { mutex::Recursive };
std::shared_ptr<settings> s;
QMetaObject::Connection conn_points, conn_maxx, conn_maxy;
std::shared_ptr<QObject> ctx { std::make_shared<QObject>() };
+ mutable mutex mtx;
mutable QPointF last_input_value{-1, -1};
mutable std::vector<float> data = std::vector<float>(value_count, magic_fill_value);
mutable points_t points;