From 87c09c0ab5e1334e9877ee6fd7adeb1eb70d5929 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 6 May 2017 13:15:16 +0200 Subject: options: don't create QSettings all the time Update usages. --- migration/20160906_00-mappings.cpp | 40 +++++++++++++++++--------------------- migration/migration.cpp | 25 ++++++++++++++---------- 2 files changed, 33 insertions(+), 32 deletions(-) (limited to 'migration') diff --git a/migration/20160906_00-mappings.cpp b/migration/20160906_00-mappings.cpp index 58674843..a5184825 100644 --- a/migration/20160906_00-mappings.cpp +++ b/migration/20160906_00-mappings.cpp @@ -36,31 +36,30 @@ struct mappings_from_2_3_0_rc11 : migration "rz", "rz_alt", }; - std::shared_ptr settings_ = options::group::ini_file(); - QSettings& settings(*settings_); - - for (const char* name : names) - { - QList points; + return group::with_settings_object([&](QSettings& settings) { + for (const char* name : names) + { + QList points; - settings.beginGroup(QString("Curves-%1").arg(name)); + settings.beginGroup(QString("Curves-%1").arg(name)); - const int max = settings.value("point-count", 0).toInt(); + const int max = settings.value("point-count", 0).toInt(); - for (int i = 0; i < max; i++) - { - QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(), - settings.value(QString("point-%1-y").arg(i), 0).toDouble()); + for (int i = 0; i < max; i++) + { + QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(), + settings.value(QString("point-%1-y").arg(i), 0).toDouble()); - points.append(new_point); - } + points.append(new_point); + } - settings.endGroup(); + settings.endGroup(); - ret.append(points); - } + ret.append(points); + } - return ret; + return ret; + }); } QString unique_date() const override { return "20160909_00"; } @@ -94,9 +93,6 @@ struct mappings_from_2_3_0_rc11 : migration const QList> old_mappings = get_old_splines(); Mappings m = get_new_mappings(); - std::shared_ptr s_ = options::group::ini_file(); - QSettings& s = *s_; - for (int i = 0; i < 12; i++) { spline& spl = (i % 2) == 0 ? m(i / 2).spline_main : m(i / 2).spline_alt; @@ -104,7 +100,7 @@ struct mappings_from_2_3_0_rc11 : migration const QList& points = old_mappings[i]; for (const QPointF& pt : points) spl.add_point(pt); - spl.save(s); + spl.save(); } } }; diff --git a/migration/migration.cpp b/migration/migration.cpp index bb8386fc..747ea06b 100644 --- a/migration/migration.cpp +++ b/migration/migration.cpp @@ -78,11 +78,11 @@ QString migrator::last_migration_time() { QString ret; - std::shared_ptr s(options::group::ini_file()); - - s->beginGroup("migrations"); - ret = s->value("last-migration-at", "19700101_00").toString(); - s->endGroup(); + options::group::with_settings_object([&](QSettings& s) { + s.beginGroup("migrations"); + ret = s.value("last-migration-at", "19700101_00").toString(); + s.endGroup(); + }); return ret; } @@ -102,11 +102,16 @@ QString migrator::time_after_migrations() void migrator::set_last_migration_time(const QString& val) { - std::shared_ptr s(options::group::ini_file()); - - s->beginGroup("migrations"); - s->setValue("last-migration-at", val); - s->endGroup(); + options::group::with_settings_object([&](QSettings& s) { + s.beginGroup("migrations"); + const QString old_value = s.value("last-migration-at", "").toString(); + if (val != old_value) + { + s.setValue("last-migration-at", val); + options::group::mark_ini_modified(); + } + s.endGroup(); + }); } std::vector migrator::sorted_migrations() -- cgit v1.2.3