summaryrefslogtreecommitdiffhomepage
path: root/spline-widget/spline.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-08-21 17:34:00 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-08-23 00:05:15 +0200
commitd6dffea39f3546e29a0cf1689d7d83b84dedfd9d (patch)
tree4f1f79d63631aae845dd130cb0b608540dec8fad /spline-widget/spline.hpp
parent550390d6d2f4e7ea21f6fa407e3b054a8ac12fd4 (diff)
spline-widget: multiple fixes
- add missing locking - bundle and settings ptr are never null following initialization; sentinel objects get created if there's no bundle, thus don't branch outside initialization functions. the sentinel object doesn't load or save to the .ini file - connect spline refresh to any bundle change - connect spline widget refresh to spline refresh - few caveat comments - spline_widget::setConfig now only takes the spline as argument, eliminating most of the complex logic there - clarify spline::set_bundle vs newly introduced spline::recompute
Diffstat (limited to 'spline-widget/spline.hpp')
-rw-r--r--spline-widget/spline.hpp82
1 files changed, 48 insertions, 34 deletions
diff --git a/spline-widget/spline.hpp b/spline-widget/spline.hpp
index 5b0b3afc..5d521a6c 100644
--- a/spline-widget/spline.hpp
+++ b/spline-widget/spline.hpp
@@ -8,43 +8,39 @@
#pragma once
-#include <QObject>
-#include <QPointF>
-#include <QString>
-#include <QMutex>
-#include <vector>
-#include <limits>
-#include <memory>
#include "compat/qcopyable-mutex.hpp"
#include "options/options.hpp"
using namespace options;
-#ifdef BUILD_spline_widget
-# define SPLINE_WIDGET_EXPORT Q_DECL_EXPORT
-#else
-# define SPLINE_WIDGET_EXPORT Q_DECL_IMPORT
-#endif
+#include "export.hpp"
-class SPLINE_WIDGET_EXPORT spline final
-{
-private:
- struct settings
- {
- bundle b;
- value<QList<QPointF>> points;
- settings(bundle b) :
- b(b),
- points(b, "points", QList<QPointF>())
- {}
- };
+#include <vector>
+#include <limits>
+#include <memory>
- ptr<settings> s;
+#include <QObject>
+#include <QPointF>
+#include <QString>
+#include <QMetaObject>
- std::vector<float> data;
- using interp_data_t = decltype(data);
+namespace spline_detail {
- static constexpr int value_count = 10000;
+class OPENTRACK_SPLINE_EXPORT settings final : public QObject
+{
+ Q_OBJECT
+public:
+ bundle b;
+ value<QList<QPointF>> points;
+ settings(bundle b);
+signals:
+ void recomputed() const;
+};
+
+}
+class OPENTRACK_SPLINE_EXPORT spline final
+{
+private:
int precision(const QList<QPointF>& points) const;
void update_interp_data();
float getValueInternal(int x);
@@ -53,11 +49,6 @@ private:
static QPointF ensure_in_bounds(const QList<QPointF>& points, int i);
- MyMutex _mutex;
- QPointF last_input_value;
- qreal max_x, max_y;
- volatile bool activep;
-
template<typename t, typename u, typename w>
static inline auto clamp(t val, u min, w max) -> decltype (val * min * max)
{
@@ -68,7 +59,22 @@ private:
return val;
}
+ mem<spline_detail::settings> s;
+ QMetaObject::Connection connection;
+
+ std::vector<float> data;
+ using interp_data_t = decltype(data);
+
+ static constexpr int value_count = 10000;
+
+ MyMutex _mutex;
+ QPointF last_input_value;
+ qreal max_x, max_y;
+ volatile bool activep;
+
public:
+ using settings = spline_detail::settings;
+
void reload();
void save(QSettings& s);
void save();
@@ -78,6 +84,10 @@ public:
qreal maxOutput() const;
spline();
spline(qreal maxx, qreal maxy, const QString& name);
+ ~spline();
+
+ spline& operator=(const spline&) = default;
+ spline(const spline&) = default;
float getValue(double x);
bool getLastPoint(QPointF& point);
@@ -91,7 +101,11 @@ public:
void setMaxOutput(qreal MaxOutput);
void setTrackingActive(bool blnActive);
- bundle get_bundle() { return s->b; }
+ bundle get_bundle();
+ void recompute();
+
+ settings& get_settings();
+ const settings& get_settings() const;
using points_t = decltype(s->points.get());
};