summaryrefslogtreecommitdiffhomepage
path: root/qfunctionconfigurator
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2015-07-26 11:26:13 +0200
committerStanislaw Halik <sthalik@misaki.pl>2015-07-26 11:26:13 +0200
commitde900bb1159af9f85d6f874925648844566363e3 (patch)
tree01131089850a8d6a17bb57f3b73183a76676b9de /qfunctionconfigurator
parentf54f96a67572d770d3eceb33d5df18f0b64016ce (diff)
qfc: reload spline data lazily
Diffstat (limited to 'qfunctionconfigurator')
-rw-r--r--qfunctionconfigurator/functionconfig.cpp22
-rw-r--r--qfunctionconfigurator/functionconfig.h5
2 files changed, 18 insertions, 9 deletions
diff --git a/qfunctionconfigurator/functionconfig.cpp b/qfunctionconfigurator/functionconfig.cpp
index cf2516ca..dc50a4d1 100644
--- a/qfunctionconfigurator/functionconfig.cpp
+++ b/qfunctionconfigurator/functionconfig.cpp
@@ -19,12 +19,18 @@ Map::Map() :
_mutex(QMutex::Recursive),
activep(false),
max_x(0),
- max_y(0)
+ max_y(0),
+ lazy_reload(true)
{
}
Map::num Map::getValue(Map::num x) {
QMutexLocker foo(&_mutex);
+ if (lazy_reload)
+ {
+ lazy_reload = false;
+ reload();
+ }
num q = x * precision();
int xi = (int)q;
num yi = getValueInternal(xi);
@@ -87,7 +93,7 @@ void Map::reload() {
{
for (int k = 0; k < input[0].x() * mult; k++) {
if (k < sz)
- data[k] = input[0].y() * k / (input[0].x() * mult) / max_y * integral_max;
+ data[k] = input[0].y() * k * integral_max / (input[0].x() * mult) / max_y ;
}
}
else if (input[0].x() > 1e-2)
@@ -151,14 +157,15 @@ void Map::removePoint(int i) {
if (i >= 0 && i < cur.input.size())
{
cur.input.removeAt(i);
- reload();
+ lazy_reload = true;
}
}
void Map::addPoint(QPointF pt) {
QMutexLocker foo(&_mutex);
cur.input.append(pt);
- reload();
+ lazy_reload = true;
+ qStableSort(cur.input.begin(), cur.input.end(), sortFn);
}
void Map::movePoint(int idx, QPointF pt) {
@@ -166,7 +173,8 @@ void Map::movePoint(int idx, QPointF pt) {
if (idx >= 0 && idx < cur.input.size())
{
cur.input[idx] = pt;
- reload();
+ lazy_reload = true;
+ // we don't allow points to be reodered, so no sort here
}
}
@@ -179,7 +187,7 @@ void Map::invalidate_unsaved_settings()
{
QMutexLocker foo(&_mutex);
cur = saved;
- reload();
+ lazy_reload = true;
}
void Map::loadSettings(QSettings& settings, const QString& title) {
@@ -208,7 +216,7 @@ void Map::loadSettings(QSettings& settings, const QString& title) {
points.append(QPointF(maxInput(), maxOutput()));
cur.input = points;
- reload();
+ lazy_reload = true;
saved = cur;
}
diff --git a/qfunctionconfigurator/functionconfig.h b/qfunctionconfigurator/functionconfig.h
index 68ec2869..74e20cf0 100644
--- a/qfunctionconfigurator/functionconfig.h
+++ b/qfunctionconfigurator/functionconfig.h
@@ -40,6 +40,7 @@ private:
double max_y;
State cur, saved;
+ bool lazy_reload;
public:
double maxInput() const { return max_x; }
double maxOutput() const { return max_y; }
@@ -48,7 +49,7 @@ public:
{
setMaxInput(maxx);
setMaxOutput(maxy);
- reload();
+ lazy_reload = true;
}
num getValue(num x);
@@ -57,7 +58,7 @@ public:
void removeAllPoints() {
QMutexLocker foo(&_mutex);
cur.input.clear();
- reload();
+ lazy_reload = true;
}
void addPoint(QPointF pt);