summaryrefslogtreecommitdiffhomepage
path: root/opentrack-compat/options.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-06-12 18:32:49 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-06-14 18:14:46 +0200
commit0c029da344b45154d4c68debe127d8cdf3843751 (patch)
treec760accf448eb4d9d8eadd30f43051b3a228c10e /opentrack-compat/options.cpp
parent251d2c45a37da6fed01c1f37529c3cd899b434e6 (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 'opentrack-compat/options.cpp')
-rw-r--r--opentrack-compat/options.cpp32
1 files changed, 21 insertions, 11 deletions
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<QSettings> group::ini_file()
return std::make_shared<QSettings>();
}
-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<QVariant>(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;
}