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 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'spline-widget/functionconfig.cpp') 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)); -- cgit v1.2.3