diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2016-06-12 18:32:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2016-06-14 18:14:46 +0200 |
commit | 0c029da344b45154d4c68debe127d8cdf3843751 (patch) | |
tree | c760accf448eb4d9d8eadd30f43051b3a228c10e /spline-widget | |
parent | 251d2c45a37da6fed01c1f37529c3cd899b434e6 (diff) |
gui, spline-widget, compat/options: ensure no qsettings IO when not modified
Turns out every MainWindow::save() and friends were doing useless IO
several times during each save. I blame the bundle abstraction.
For bundles we track the modified state, but the spline widget needs
equality check since it doesn't use the options api.
It was found by accident when adding qDebug() into the slider_value
{de,}serializer code. The .ini file was being rewritten over and over
again causing hundres of milliseconds pauses on Windows.
Remove the save timer kludge from gui. Saves are now fast.
Diffstat (limited to 'spline-widget')
-rw-r--r-- | spline-widget/functionconfig.cpp | 29 | ||||
-rw-r--r-- | spline-widget/functionconfig.h | 4 |
2 files changed, 31 insertions, 2 deletions
diff --git a/spline-widget/functionconfig.cpp b/spline-widget/functionconfig.cpp index 1acea958..8cfce7ae 100644 --- a/spline-widget/functionconfig.cpp +++ b/spline-widget/functionconfig.cpp @@ -15,6 +15,7 @@ #include <QtAlgorithms> #include <QSettings> #include <QPixmap> +#include <QString> #include <algorithm> #include <cmath> @@ -271,10 +272,36 @@ void Map::loadSettings(QSettings& settings, const QString& title) saved = cur; } +bool Map::State::operator==(const State& other) const +{ + if (input.size() != other.input.size()) + return false; + + const int sz = input.size(); + + using std::fabs; + + for (int i = 0; i < sz; i++) + { + const qreal eps = 1e-3; + + if (fabs(input[i].x() - other.input[i].x()) > eps || + fabs(input[i].y() - other.input[i].y()) > eps) + { + return false; + } + } + return true; +} + void Map::saveSettings(QSettings& settings, const QString& title) { QMutexLocker foo(&_mutex); - settings.beginGroup(QString("Curves-%1").arg(title)); + + if (cur == saved) + return; + + settings.beginGroup(QStringLiteral("Curves-%1").arg(title)); if (cur.input.size() == 0) cur.input.push_back(QPointF(max_x, max_y)); diff --git a/spline-widget/functionconfig.h b/spline-widget/functionconfig.h index 6c039831..5c9eeb2b 100644 --- a/spline-widget/functionconfig.h +++ b/spline-widget/functionconfig.h @@ -28,9 +28,11 @@ class SPLINE_WIDGET_EXPORT Map { private: static constexpr int value_count = 10000; - struct State { + struct State + { QList<QPointF> input; std::vector<float> data; + bool operator==(const State& s) const; }; int precision() const; |