summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2014-10-04 17:28:49 +0200
committerStanislaw Halik <sthalik@misaki.pl>2014-10-04 17:28:49 +0200
commit97bd173ee4b6f30c12ca590e213b21bbc83f8617 (patch)
tree41c6c2dc601ef78816c1fc27af1f0ba8b4d4ed0d /qfunctionconfigurator
parentb8c5e24223988c84331693371bb9b0d71b7ef821 (diff)
flush before windows breaks and data lossage
Diffstat (limited to 'qfunctionconfigurator')
-rw-r--r--qfunctionconfigurator/functionconfig.cpp24
-rw-r--r--qfunctionconfigurator/functionconfig.h81
-rw-r--r--qfunctionconfigurator/qfunctionconfigurator.cpp2
-rw-r--r--qfunctionconfigurator/qfunctionconfigurator.h6
4 files changed, 40 insertions, 73 deletions
diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp
index 159f350e..f39562c1 100644
--- a/qfunctionconfigurator/functionconfig.cpp
+++ b/qfunctionconfigurator/functionconfig.cpp
@@ -17,12 +17,12 @@
#include <cmath>
#include <QPixmap>
-void FunctionConfig::setTrackingActive(bool blnActive)
+void Map::setTrackingActive(bool blnActive)
{
activep = blnActive;
}
-FunctionConfig::FunctionConfig() :
+Map::Map() :
_mutex(QMutex::Recursive),
data(0),
activep(false),
@@ -31,7 +31,7 @@ FunctionConfig::FunctionConfig() :
{
}
-float FunctionConfig::getValue(float x) {
+float Map::getValue(float x) {
QMutexLocker foo(&_mutex);
int x2 = (int) (std::min<float>(std::max<float>(x, -360), 360) * MEMOIZE_PRECISION);
float ret = getValueInternal(x2);
@@ -40,13 +40,13 @@ float FunctionConfig::getValue(float x) {
return ret;
}
-bool FunctionConfig::getLastPoint(QPointF& point ) {
+bool Map::getLastPoint(QPointF& point ) {
QMutexLocker foo(&_mutex);
point = last_input_value;
return activep;
}
-float FunctionConfig::getValueInternal(int x) {
+float Map::getValueInternal(int x) {
float sign = x < 0 ? -1 : 1;
x = x < 0 ? -x : x;
float ret;
@@ -75,7 +75,7 @@ static bool sortFn(const QPointF& one, const QPointF& two) {
return one.x() < two.x();
}
-void FunctionConfig::reload() {
+void Map::reload() {
if (input.size())
qStableSort(input.begin(), input.end(), sortFn);
@@ -132,7 +132,7 @@ void FunctionConfig::reload() {
}
}
-void FunctionConfig::removePoint(int i) {
+void Map::removePoint(int i) {
QMutexLocker foo(&_mutex);
if (i >= 0 && i < input.size())
{
@@ -141,13 +141,13 @@ void FunctionConfig::removePoint(int i) {
}
}
-void FunctionConfig::addPoint(QPointF pt) {
+void Map::addPoint(QPointF pt) {
QMutexLocker foo(&_mutex);
input.append(pt);
reload();
}
-void FunctionConfig::movePoint(int idx, QPointF pt) {
+void Map::movePoint(int idx, QPointF pt) {
QMutexLocker foo(&_mutex);
if (idx >= 0 && idx < input.size())
{
@@ -156,13 +156,13 @@ void FunctionConfig::movePoint(int idx, QPointF pt) {
}
}
-const QList<QPointF> FunctionConfig::getPoints() {
+const QList<QPointF> Map::getPoints() {
QMutexLocker foo(&_mutex);
// NB can't pass by reference
return input;
}
-void FunctionConfig::loadSettings(QSettings& settings, const QString& title) {
+void Map::loadSettings(QSettings& settings, const QString& title) {
QMutexLocker foo(&_mutex);
QPointF newPoint;
@@ -187,7 +187,7 @@ void FunctionConfig::loadSettings(QSettings& settings, const QString& title) {
reload();
}
-void FunctionConfig::saveSettings(QSettings& settings, const QString& title) {
+void Map::saveSettings(QSettings& settings, const QString& title) {
QMutexLocker foo(&_mutex);
settings.beginGroup(QString("Curves-%1").arg(title));
int max = input.size();
diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h
index 66e7f3e8..ccfd1ba3 100644
--- a/qfunctionconfigurator/functionconfig.h
+++ b/qfunctionconfigurator/functionconfig.h
@@ -13,88 +13,55 @@
#include <QString>
#include <QSettings>
#include <QMutex>
-#include "facetracknoir/plugin-api.hpp"
#include <vector>
+#include "../facetracknoir/plugin-api.hpp"
+#include "../facetracknoir/qcopyable-mutex.hpp"
#define MEMOIZE_PRECISION 100
-class MyMutex {
-private:
- QMutex inner;
-
-public:
- QMutex* operator->() { return &inner; }
- QMutex* operator->() const { return &const_cast<MyMutex*>(this)->inner; }
-
- MyMutex operator=(const MyMutex& datum)
- {
- auto mode =
- datum->isRecursive()
- ? QMutex::Recursive
- : QMutex::NonRecursive;
-
- return MyMutex(mode);
- }
-
- MyMutex(const MyMutex& datum)
- {
- *this = datum;
- }
-
- MyMutex(QMutex::RecursionMode mode = QMutex::NonRecursive) :
- inner(mode)
- {
- }
-
- QMutex* operator&()
- {
- return &inner;
- }
-};
-
-class OPENTRACK_EXPORT FunctionConfig {
+class OPENTRACK_EXPORT Map {
private:
void reload();
float getValueInternal(int x);
-
+
MyMutex _mutex;
- QList<QPointF> input;
+ QList<QPointF> input;
std::vector<float> data;
- QPointF last_input_value;
+ QPointF last_input_value;
volatile bool activep;
- int max_x;
- int max_y;
+ int max_x;
+ int max_y;
public:
int maxInput() const { return max_x; }
int maxOutput() const { return max_y; }
- FunctionConfig();
- FunctionConfig(int maxx, int maxy)
+ Map();
+ Map(int maxx, int maxy)
{
setMaxInput(maxx);
setMaxOutput(maxy);
}
float getValue(float x);
- bool getLastPoint(QPointF& point);
- void removePoint(int i);
+ bool getLastPoint(QPointF& point);
+ void removePoint(int i);
void removeAllPoints() {
QMutexLocker foo(&_mutex);
input.clear();
reload();
}
- void addPoint(QPointF pt);
- void movePoint(int idx, QPointF pt);
- const QList<QPointF> getPoints();
- void setMaxInput(int MaxInput) {
- max_x = MaxInput;
- }
- void setMaxOutput(int MaxOutput) {
- max_y = MaxOutput;
- }
+ void addPoint(QPointF pt);
+ void movePoint(int idx, QPointF pt);
+ const QList<QPointF> getPoints();
+ void setMaxInput(int MaxInput) {
+ max_x = MaxInput;
+ }
+ void setMaxOutput(int MaxOutput) {
+ max_y = MaxOutput;
+ }
- void saveSettings(QSettings& settings, const QString& title);
- void loadSettings(QSettings& settings, const QString& title);
+ void saveSettings(QSettings& settings, const QString& title);
+ void loadSettings(QSettings& settings, const QString& title);
- void setTrackingActive(bool blnActive);
+ void setTrackingActive(bool blnActive);
};
diff --git a/qfunctionconfigurator/qfunctionconfigurator.cpp b/qfunctionconfigurator/qfunctionconfigurator.cpp
index 1e5b957c..57d1500a 100644
--- a/qfunctionconfigurator/qfunctionconfigurator.cpp
+++ b/qfunctionconfigurator/qfunctionconfigurator.cpp
@@ -37,7 +37,7 @@ QFunctionConfigurator::QFunctionConfigurator(QWidget *parent) :
setMouseTracking(true);
}
-void QFunctionConfigurator::setConfig(FunctionConfig* config, const QString& name) {
+void QFunctionConfigurator::setConfig(Map* config, const QString& name) {
QSettings settings("opentrack");
QString currentFile = settings.value ( "SettingsFile", QCoreApplication::applicationDirPath() + "/settings/default.ini" ).toString();
QSettings iniFile( currentFile, QSettings::IniFormat );
diff --git a/qfunctionconfigurator/qfunctionconfigurator.h b/qfunctionconfigurator/qfunctionconfigurator.h
index facc5bbe..e35d0bc3 100644
--- a/qfunctionconfigurator/qfunctionconfigurator.h
+++ b/qfunctionconfigurator/qfunctionconfigurator.h
@@ -20,8 +20,8 @@ class OPENTRACK_EXPORT QFunctionConfigurator : public QWidget
public:
QFunctionConfigurator(QWidget *parent = 0);
- FunctionConfig* config();
- void setConfig(FunctionConfig* config, const QString &name);
+ Map* config();
+ void setConfig(Map* config, const QString &name);
QColor colorBezier() const
{
@@ -65,7 +65,7 @@ private:
QPointF pixel_coord_to_point (const QPointF& point);
QPointF point_to_pixel (const QPointF& point);
- FunctionConfig* _config;
+ Map* _config;
// bounds of the rectangle user can interact with
QRectF pixel_bounds;