From 0c029da344b45154d4c68debe127d8cdf3843751 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 12 Jun 2016 18:32:49 +0200 Subject: 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. --- spline-widget/functionconfig.cpp | 29 ++++++++++++++++++++++++++++- spline-widget/functionconfig.h | 4 +++- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'spline-widget') 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 #include #include +#include #include #include @@ -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 input; std::vector data; + bool operator==(const State& s) const; }; int precision() const; -- cgit v1.2.3