diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-27 12:35:05 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-28 03:06:37 +0200 |
commit | 4b68e4e6104ff4b9c1e6857cf22edc568e68ec5e (patch) | |
tree | 1481341dde394227f6ec147b8f350f9c81d46b73 | |
parent | 4be9a6542e03b07fc6edeeb3b1fb0a7b2b2108eb (diff) |
tracker/fusion: use translation-neutral module ident
Also, manage QLibrary lifetime to a minimum. They are
refcounted internally anyway.
Remove bogus assert -- video feed trackers drop
the layout on their own typically.
-rw-r--r-- | tracker-fusion/fusion.cpp | 102 | ||||
-rw-r--r-- | tracker-fusion/fusion.h | 27 |
2 files changed, 76 insertions, 53 deletions
diff --git a/tracker-fusion/fusion.cpp b/tracker-fusion/fusion.cpp index e8e48372..07f6483f 100644 --- a/tracker-fusion/fusion.cpp +++ b/tracker-fusion/fusion.cpp @@ -15,7 +15,12 @@ #include <QMessageBox> #include <QApplication> -static const QString own_name = fusion_metadata().name(); +static const QString own_name = QStringLiteral("fusion"); + +static auto get_modules() +{ + return Modules(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH); +} fusion_tracker::fusion_tracker() : rot_tracker_data{}, @@ -26,63 +31,72 @@ fusion_tracker::fusion_tracker() : fusion_tracker::~fusion_tracker() { + // CAVEAT order matters rot_tracker = nullptr; pos_tracker = nullptr; + rot_dylib = nullptr; pos_dylib = nullptr; if (other_frame) { - assert(other_frame->layout()); - delete other_frame->layout(); + if (other_frame->layout()) + delete other_frame->layout(); other_frame = nullptr; } } +const QString& fusion_tracker::caption() +{ + static const QString caption = tr("Fusion tracker"); + return caption; +} + void fusion_tracker::start_tracker(QFrame* frame) { assert(!rot_tracker && !pos_tracker); assert(!rot_dylib && !pos_dylib); fusion_settings s; - const QString rot_tracker_name = s.rot_tracker_name; - const QString pos_tracker_name = s.pos_tracker_name; + const QString rot_tracker_name = s.rot_tracker_name().toString(); + const QString pos_tracker_name = s.pos_tracker_name().toString(); assert(rot_tracker_name != own_name); assert(pos_tracker_name != own_name); if (rot_tracker_name.isEmpty() || pos_tracker_name.isEmpty()) - { - QMessageBox::warning(nullptr, - "Fusion tracker", "Select rotation and position trackers.", - QMessageBox::Close); - other_frame = nullptr; - return; - } + goto fail; if (rot_tracker_name == pos_tracker_name) { - QMessageBox::warning(nullptr, - "Fusion tracker", "Select different trackers for rotation and position.", + QMessageBox::warning(nullptr, caption(), + tr("Select different trackers for rotation and position."), QMessageBox::Close); - other_frame = nullptr; - return; + goto cleanup; } - for (auto& t : modules.trackers()) { - if (t->name == rot_tracker_name) - { - assert(!rot_dylib); - rot_dylib = t; - } - if (t->name == pos_tracker_name) + Modules libs = get_modules(); + + for (auto& t : libs.trackers()) { - assert(!pos_dylib); - pos_dylib = t; + if (t->module_name == rot_tracker_name) + { + assert(!rot_dylib); + rot_dylib = t; + } + + if (t->module_name == pos_tracker_name) + { + assert(!pos_dylib); + pos_dylib = t; + } } } + if (!rot_dylib || !pos_dylib) + goto fail; + rot_tracker = make_dylib_instance<ITracker>(rot_dylib); pos_tracker = make_dylib_instance<ITracker>(pos_dylib); @@ -95,12 +109,26 @@ void fusion_tracker::start_tracker(QFrame* frame) } else { + other_frame->setVisible(false); + other_frame->setFixedSize(320, 240); // XXX magic frame size + rot_tracker->start_tracker(other_frame.get()); - if (!other_frame->layout()) + + if (other_frame->layout() == nullptr) other_frame = nullptr; + else + other_frame->hide(); + } + return; +fail: + QMessageBox::warning(nullptr, + caption(), tr("Select rotation and position trackers."), + QMessageBox::Close); +cleanup: + other_frame = nullptr; } void fusion_tracker::data(double *data) @@ -127,13 +155,15 @@ fusion_dialog::fusion_dialog() ui.rot_tracker->addItem(""); ui.pos_tracker->addItem(""); - for (auto &m : modules.trackers()) + Modules libs = get_modules(); + + for (auto& m : libs.trackers()) { - if (m->name == own_name) + if (m->module_name == own_name) continue; - ui.rot_tracker->addItem(m->icon, m->name); - ui.pos_tracker->addItem(m->icon, m->name); + ui.rot_tracker->addItem(m->icon, m->name, QVariant(m->module_name)); + ui.pos_tracker->addItem(m->icon, m->name, QVariant(m->module_name)); } ui.rot_tracker->setCurrentIndex(0); @@ -151,9 +181,9 @@ void fusion_dialog::doOK() if (rot_idx == -1 || pos_idx == -1 || rot_idx == pos_idx) { QMessageBox::warning(this, - "Fusion tracker", - "Fusion tracker only works when distinct trackers are selected " - "for rotation and position.", + fusion_tracker::caption(), + tr("Fusion tracker only works when distinct trackers are selected " + "for rotation and position."), QMessageBox::Close); } @@ -173,10 +203,4 @@ fusion_settings::fusion_settings() : { } -has_modules::has_modules() : - modules(OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH) -{ -} - - OPENTRACK_DECLARE_TRACKER(fusion_tracker, fusion_dialog, fusion_metadata)
\ No newline at end of file diff --git a/tracker-fusion/fusion.h b/tracker-fusion/fusion.h index a943fe06..28e584da 100644 --- a/tracker-fusion/fusion.h +++ b/tracker-fusion/fusion.h @@ -1,6 +1,7 @@ #pragma once #include "api/plugin-api.hpp" #include "api/plugin-support.hpp" +#include <QObject> #include <QFrame> #include <QCoreApplication> @@ -9,35 +10,33 @@ using namespace options; struct fusion_settings final : opts { - value<QString> rot_tracker_name; - value<QString> pos_tracker_name; + value<QVariant> rot_tracker_name, pos_tracker_name; fusion_settings(); }; -struct has_modules +class fusion_tracker : public QObject, public ITracker { - Modules modules; - has_modules(); -}; - -struct fusion_tracker : public ITracker, has_modules -{ - fusion_tracker(); - ~fusion_tracker() override; - void start_tracker(QFrame *) override; - void data(double *data) override; + Q_OBJECT double rot_tracker_data[6], pos_tracker_data[6]; std::unique_ptr<QFrame> other_frame; std::shared_ptr<dylib> rot_dylib, pos_dylib; std::shared_ptr<ITracker> rot_tracker, pos_tracker; + +public: + fusion_tracker(); + ~fusion_tracker() override; + void start_tracker(QFrame*) override; + void data(double* data) override; + + static const QString& caption(); }; #include "ui_fusion.h" -class fusion_dialog : public ITrackerDialog, has_modules +class fusion_dialog : public ITrackerDialog { Q_OBJECT |