From 6e752439a11328b6afea20771715c19e80c9ac34 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 9 Sep 2016 20:28:21 +0200 Subject: migrations: rename for 2-digit serial --- migration/20160906_0-mappings.cpp | 104 ----------------------------------- migration/20160906_00-mappings.cpp | 104 +++++++++++++++++++++++++++++++++++ migration/20160906_01-axis-signs.cpp | 73 ++++++++++++++++++++++++ migration/20160906_1-axis-signs.cpp | 73 ------------------------ 4 files changed, 177 insertions(+), 177 deletions(-) delete mode 100644 migration/20160906_0-mappings.cpp create mode 100644 migration/20160906_00-mappings.cpp create mode 100644 migration/20160906_01-axis-signs.cpp delete mode 100644 migration/20160906_1-axis-signs.cpp (limited to 'migration') diff --git a/migration/20160906_0-mappings.cpp b/migration/20160906_0-mappings.cpp deleted file mode 100644 index 060b9967..00000000 --- a/migration/20160906_0-mappings.cpp +++ /dev/null @@ -1,104 +0,0 @@ -#include "migration.hpp" -#include "logic/mappings.hpp" -#include "logic/main-settings.hpp" -#include "options/group.hpp" - -#include -#include - -#include - -#include - -using namespace migrations; - -struct mappings_from_2_3_0_rc11 : migration -{ - static QList> get_old_splines() - { - QList> ret; - - static const char* names[] = - { - "tx", "tx_alt", - "ty", "ty_alt", - "tz", "tz_alt", - "rx", "rx_alt", - "ry", "ry_alt", - "rz", "rz_alt", - }; - - std::shared_ptr settings_ = options::group::ini_file(); - QSettings& settings(*settings_); - - for (const char* name : names) - { - QList points; - - settings.beginGroup(QString("Curves-%1").arg(name)); - - 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()); - - points.append(new_point); - } - - settings.endGroup(); - - ret.append(points); - } - - return ret; - } - - QString unique_date() const override { return "20160909_00"; } - QString name() const override { return "mappings to 2.3.0-rc12"; } - - static Mappings get_new_mappings() - { - main_settings s; - return Mappings(std::vector{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll}); - } - - bool should_run() const override - { - Mappings m = get_new_mappings(); - - // run only if no new splines were set - for (int i = 0; i < 6; i++) - if (m(i).spline_main.get_point_count() || m(i).spline_alt.get_point_count()) - return false; - - // run only if old splines exist - for (const QList& points : get_old_splines()) - if (points.size()) - return true; - - // no splines exit at all - return false; - } - void run() override - { - 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; - spl.removeAllPoints(); - const QList& points = old_mappings[i]; - for (const QPointF& pt : points) - spl.addPoint(pt); - spl.save(s); - } - } -}; - -OPENTRACK_MIGRATION(mappings_from_2_3_0_rc11); diff --git a/migration/20160906_00-mappings.cpp b/migration/20160906_00-mappings.cpp new file mode 100644 index 00000000..060b9967 --- /dev/null +++ b/migration/20160906_00-mappings.cpp @@ -0,0 +1,104 @@ +#include "migration.hpp" +#include "logic/mappings.hpp" +#include "logic/main-settings.hpp" +#include "options/group.hpp" + +#include +#include + +#include + +#include + +using namespace migrations; + +struct mappings_from_2_3_0_rc11 : migration +{ + static QList> get_old_splines() + { + QList> ret; + + static const char* names[] = + { + "tx", "tx_alt", + "ty", "ty_alt", + "tz", "tz_alt", + "rx", "rx_alt", + "ry", "ry_alt", + "rz", "rz_alt", + }; + + std::shared_ptr settings_ = options::group::ini_file(); + QSettings& settings(*settings_); + + for (const char* name : names) + { + QList points; + + settings.beginGroup(QString("Curves-%1").arg(name)); + + 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()); + + points.append(new_point); + } + + settings.endGroup(); + + ret.append(points); + } + + return ret; + } + + QString unique_date() const override { return "20160909_00"; } + QString name() const override { return "mappings to 2.3.0-rc12"; } + + static Mappings get_new_mappings() + { + main_settings s; + return Mappings(std::vector{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll}); + } + + bool should_run() const override + { + Mappings m = get_new_mappings(); + + // run only if no new splines were set + for (int i = 0; i < 6; i++) + if (m(i).spline_main.get_point_count() || m(i).spline_alt.get_point_count()) + return false; + + // run only if old splines exist + for (const QList& points : get_old_splines()) + if (points.size()) + return true; + + // no splines exit at all + return false; + } + void run() override + { + 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; + spl.removeAllPoints(); + const QList& points = old_mappings[i]; + for (const QPointF& pt : points) + spl.addPoint(pt); + spl.save(s); + } + } +}; + +OPENTRACK_MIGRATION(mappings_from_2_3_0_rc11); diff --git a/migration/20160906_01-axis-signs.cpp b/migration/20160906_01-axis-signs.cpp new file mode 100644 index 00000000..7cf0c719 --- /dev/null +++ b/migration/20160906_01-axis-signs.cpp @@ -0,0 +1,73 @@ +// TODO XXX write migration for axis sign going to mappings bundle + +#include "migration.hpp" +#include "options/options.hpp" +#include "logic/main-settings.hpp" + +#include +#include + +using namespace options; +using namespace migrations; + +struct axis_signs_split_rc11 : migration +{ + axis_signs_split_rc11() = default; + + static const char* axis_names[6]; + static const QString fmt; + + QString unique_date() const override + { + return "20160909_01"; + } + + QString name() const override + { + return "asymmetric axis sign to another .ini section"; + } + + bool should_run() const override + { + bundle new_bundle = make_bundle("opentrack-mappings"); + bundle old_bundle = make_bundle("opentrack-ui"); + + for (const char* name : axis_names) + { + // new present, already applied + if (new_bundle->contains(fmt.arg(name))) + return false; + } + + for (const char* name : axis_names) + { + // old present + if (old_bundle->contains(fmt.arg(name))) + return true; + } + + // nothing to copy + return false; + } + + void run() override + { + bundle new_bundle = make_bundle("opentrack-mappings"); + bundle old_bundle = make_bundle("opentrack-ui"); + + for (const char* name : axis_names) + new_bundle->store_kv(fmt.arg(name), QVariant(old_bundle->get(fmt.arg(name)))); + + new_bundle->save(); + } +}; + +const char* axis_signs_split_rc11::axis_names[] = +{ + "yaw", "pitch", "roll", + "x", "y", "z", +}; + +const QString axis_signs_split_rc11::fmt = QStringLiteral("%1-alt-axis-sign"); + +OPENTRACK_MIGRATION(axis_signs_split_rc11); diff --git a/migration/20160906_1-axis-signs.cpp b/migration/20160906_1-axis-signs.cpp deleted file mode 100644 index 7cf0c719..00000000 --- a/migration/20160906_1-axis-signs.cpp +++ /dev/null @@ -1,73 +0,0 @@ -// TODO XXX write migration for axis sign going to mappings bundle - -#include "migration.hpp" -#include "options/options.hpp" -#include "logic/main-settings.hpp" - -#include -#include - -using namespace options; -using namespace migrations; - -struct axis_signs_split_rc11 : migration -{ - axis_signs_split_rc11() = default; - - static const char* axis_names[6]; - static const QString fmt; - - QString unique_date() const override - { - return "20160909_01"; - } - - QString name() const override - { - return "asymmetric axis sign to another .ini section"; - } - - bool should_run() const override - { - bundle new_bundle = make_bundle("opentrack-mappings"); - bundle old_bundle = make_bundle("opentrack-ui"); - - for (const char* name : axis_names) - { - // new present, already applied - if (new_bundle->contains(fmt.arg(name))) - return false; - } - - for (const char* name : axis_names) - { - // old present - if (old_bundle->contains(fmt.arg(name))) - return true; - } - - // nothing to copy - return false; - } - - void run() override - { - bundle new_bundle = make_bundle("opentrack-mappings"); - bundle old_bundle = make_bundle("opentrack-ui"); - - for (const char* name : axis_names) - new_bundle->store_kv(fmt.arg(name), QVariant(old_bundle->get(fmt.arg(name)))); - - new_bundle->save(); - } -}; - -const char* axis_signs_split_rc11::axis_names[] = -{ - "yaw", "pitch", "roll", - "x", "y", "z", -}; - -const QString axis_signs_split_rc11::fmt = QStringLiteral("%1-alt-axis-sign"); - -OPENTRACK_MIGRATION(axis_signs_split_rc11); -- cgit v1.2.3