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. --- opentrack-compat/options.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'opentrack-compat/options.cpp') diff --git a/opentrack-compat/options.cpp b/opentrack-compat/options.cpp index 55a4b795..785698de 100644 --- a/opentrack-compat/options.cpp +++ b/opentrack-compat/options.cpp @@ -88,7 +88,7 @@ const mem group::ini_file() return std::make_shared(); } -impl_bundle::impl_bundle(const QString &group_name) +impl_bundle::impl_bundle(const QString& group_name) : mtx(QMutex::Recursive), group_name(group_name), @@ -101,20 +101,25 @@ void impl_bundle::reload() { { QMutexLocker l(&mtx); - saved = group(group_name); - transient = saved; - modified = false; + if (modified) + { + saved = group(group_name); + transient = saved; + modified = false; + } } emit reloading(); } -void impl_bundle::store_kv(const QString &name, const QVariant &datum) +void impl_bundle::store_kv(const QString& name, const QVariant& datum) { QMutexLocker l(&mtx); auto old = transient.get(name); if (!transient.contains(name) || datum != old) { + if (!modified) + qDebug() << "bundle" << group_name << "modified" << "key" << name << "to" << datum << "from" << old; modified = true; transient.put(name, datum); } @@ -128,13 +133,20 @@ bool impl_bundle::contains(const QString &name) const void impl_bundle::save() { + bool modified_ = false; { QMutexLocker l(&mtx); - modified = false; - saved = transient; - transient.save(); + if (modified) + { + qDebug() << "bundle" << group_name << "saved"; + modified_ = true; + modified = false; + saved = transient; + transient.save(); + } } - emit saving(); + if (modified_) + emit saving(); } bool impl_bundle::modifiedp() const @@ -220,7 +232,6 @@ custom_type_initializer custom_type_initializer::singleton = custom_type_initial QDataStream& operator <<(QDataStream& out, const options::slider_value& v) { out << v.cur() << v.min() << v.max(); - qDebug() << "out cur" << v.cur(); return out; } @@ -231,6 +242,5 @@ QDataStream& operator >>(QDataStream& in, options::slider_value& v) in >> min; in >> max; v = options::slider_value(cur, min, max); - qDebug() << "in cur" << v.cur(); return in; } -- cgit v1.2.3