diff --git a/src/QGCSingleton.cc b/src/QGCSingleton.cc index 5cda7a69abf58060a5b853839e37e3a7efdfe448..6b4c98fc3a935364a148a80f86ad9cdb7151a9fa 100644 --- a/src/QGCSingleton.cc +++ b/src/QGCSingleton.cc @@ -29,8 +29,10 @@ #include "QGCSingleton.h" #include "QGCApplication.h" -QGCSingleton::QGCSingleton(QObject* parent) : +QGCSingleton::QGCSingleton(QObject* parent, bool registerSingleton) : QObject(parent) { - qgcApp()->registerSingleton(this); + if (registerSingleton) { + qgcApp()->registerSingleton(this); + } } diff --git a/src/QGCSingleton.h b/src/QGCSingleton.h index 708f1bcdf6bb994d394a498cd59b2860cb85594b..b3975dd2467c6654eabd9cf31ad071cc81f15ec8 100644 --- a/src/QGCSingleton.h +++ b/src/QGCSingleton.h @@ -39,7 +39,9 @@ class QGCSingleton : public QObject public: /// @brief Contructor will register singleton to QGCApplication - QGCSingleton(QObject* parent = NULL); + /// @param parent Parent object + /// @param registerSingleton true: register with QGCApplication, false: do not register (only used for Mock implementations) + QGCSingleton(QObject* parent = NULL, bool registerSingleton = true); /// @brief Implementation should delete the singleton such that next call to instance /// will create a new singleton. diff --git a/src/qgcunittest/MockUASManager.cc b/src/qgcunittest/MockUASManager.cc index 6a0cee67a74c663629a5ddbfba1ed7556bdbdc1d..960bafedec7d74cb3ba62bbcafbabad4b062a885 100644 --- a/src/qgcunittest/MockUASManager.cc +++ b/src/qgcunittest/MockUASManager.cc @@ -24,6 +24,7 @@ #include "MockUASManager.h" MockUASManager::MockUASManager(void) : + UASManagerInterface(NULL, false /* do not register singleton with QGCApplication */), _mockUAS(NULL) { diff --git a/src/uas/UASManagerInterface.h b/src/uas/UASManagerInterface.h index 4bb5d4967dca564c3b56dee37c36e7d74b96915a..bf611c6d72b34e82033844dfc3932eea73fefcb4 100644 --- a/src/uas/UASManagerInterface.h +++ b/src/uas/UASManagerInterface.h @@ -57,7 +57,10 @@ class UASManagerInterface : public QGCSingleton Q_OBJECT public: - UASManagerInterface(QObject* parent = NULL) : QGCSingleton(parent) { } + /// @brief Contructor will register singleton to QGCApplication + /// @param parent Parent object + /// @param registerSingleton true: register with QGCApplication, false: do not register (only used for Mock implementations) + UASManagerInterface(QObject* parent = NULL, bool registerSingleton = true) : QGCSingleton(parent, registerSingleton) { } virtual UASInterface* getActiveUAS() = 0; virtual UASWaypointManager *getActiveUASWaypointManager() = 0;