diff --git a/app/src/MainWindow.cpp b/app/src/MainWindow.cpp index d89ff54..6fbd08b 100644 --- a/app/src/MainWindow.cpp +++ b/app/src/MainWindow.cpp @@ -183,12 +183,10 @@ MainWindow::MainWindow(QWidget *parent) connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(), SLOT(onTimeToUpdate(SqpDateTime))); - qRegisterMetaType(); connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime))); // Widgets / widgets connections - qRegisterMetaType >(); // For the following connections, we use DirectConnection to allow each widget that can // potentially attach a menu to the variable's menu to do so before this menu is displayed. diff --git a/core/include/Common/MetaTypes.h b/core/include/Common/MetaTypes.h new file mode 100644 index 0000000..1fb61b0 --- /dev/null +++ b/core/include/Common/MetaTypes.h @@ -0,0 +1,46 @@ +#ifndef SCIQLOP_METATYPES_H +#define SCIQLOP_METATYPES_H + +#include + +/** + * Struct used to create an instance that registers a type in Qt for signals / slots mechanism + * @tparam T the type to register + */ +template +struct MetaTypeRegistry { + explicit MetaTypeRegistry() { qRegisterMetaType(); } +}; + +/** + * This macro can be used to : + * - declare a type as a Qt meta type + * - and register it (through a static instance) at the launch of SciQlop, so it can be passed in + * Qt signals/slots + * + * It can be used both in .h or in .cpp files + * + * @param NAME name of the instance under which the type will be registered (in uppercase) + * @param TYPE type to register + * + * Example: + * ~~~cpp + * // The following macro : + * // - declares std::shared_ptr as a Qt meta type + * // - registers it through an instance named VAR_SHARED_PTR + * SCIQLOP_REGISTER_META_TYPE(VAR_SHARED_PTR, std::shared_ptr) + * + * // The following macro : + * // - declares a raw pointer of Variable as a Qt meta type + * // - registers it through an instance named VAR_RAW_PTR + * SCIQLOP_REGISTER_META_TYPE(VAR_RAW_PTR, Variable*) + * ~~~ + * + */ +// clang-format off +#define SCIQLOP_REGISTER_META_TYPE(NAME, TYPE) \ +Q_DECLARE_METATYPE(TYPE) \ +const auto NAME = MetaTypeRegistry{}; \ +// clang-format on + +#endif // SCIQLOP_METATYPES_H diff --git a/core/include/Data/IDataProvider.h b/core/include/Data/IDataProvider.h index cde7f5e..4eafa26 100644 --- a/core/include/Data/IDataProvider.h +++ b/core/include/Data/IDataProvider.h @@ -5,6 +5,8 @@ #include +#include + #include class DataProviderParameters; @@ -33,7 +35,8 @@ public: signals: void dataProvided(std::shared_ptr dateSerie, const SqpDateTime &dateTime); }; + // Required for using shared_ptr in signals/slots -Q_DECLARE_METATYPE(std::shared_ptr) +SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr) #endif // SCIQLOP_IDATAPROVIDER_H diff --git a/core/include/Data/IDataSeries.h b/core/include/Data/IDataSeries.h index bbea31f..08336ec 100644 --- a/core/include/Data/IDataSeries.h +++ b/core/include/Data/IDataSeries.h @@ -1,10 +1,10 @@ #ifndef SCIQLOP_IDATASERIES_H #define SCIQLOP_IDATASERIES_H +#include #include -#include #include template @@ -49,6 +49,6 @@ public: }; // Required for using shared_ptr in signals/slots -Q_DECLARE_METATYPE(std::shared_ptr) +SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr) #endif // SCIQLOP_IDATASERIES_H diff --git a/core/include/Data/SqpDateTime.h b/core/include/Data/SqpDateTime.h index c0f73c1..0a936e2 100644 --- a/core/include/Data/SqpDateTime.h +++ b/core/include/Data/SqpDateTime.h @@ -6,6 +6,8 @@ #include #include +#include + /** * @brief The SqpDateTime struct holds the information of time parameters */ @@ -37,6 +39,6 @@ inline QDebug operator<<(QDebug d, SqpDateTime obj) } // Required for using shared_ptr in signals/slots -Q_DECLARE_METATYPE(SqpDateTime) +SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime) #endif // SCIQLOP_SQPDATETIME_H diff --git a/core/include/Variable/Variable.h b/core/include/Variable/Variable.h index 21ea2e7..a1f13f1 100644 --- a/core/include/Variable/Variable.h +++ b/core/include/Variable/Variable.h @@ -3,10 +3,10 @@ #include - #include #include +#include #include Q_DECLARE_LOGGING_CATEGORY(LOG_Variable) @@ -50,6 +50,6 @@ private: }; // Required for using shared_ptr in signals/slots -Q_DECLARE_METATYPE(std::shared_ptr) +SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr) #endif // SCIQLOP_VARIABLE_H diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index b348b95..11e0b3b 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -104,8 +104,6 @@ void VariableController::createVariable(const QString &name, // store the provider impl->m_VariableToProviderMap[newVariable] = provider; - qRegisterMetaType >(); - qRegisterMetaType(); connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(), &Variable::onAddDataSeries); diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index 4a57fa0..4c221ba 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -23,14 +23,12 @@ public: // /////////////////////////////// // // VariableController <-> DataSourceController - qRegisterMetaType >(); connect(m_DataSourceController.get(), SIGNAL(variableCreationRequested(const QString &, std::shared_ptr)), m_VariableController.get(), SLOT(createVariable(const QString &, std::shared_ptr))); // VariableController <-> VisualizationController - qRegisterMetaType >(); connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr)), m_VisualizationController.get(), SIGNAL(variableCreated(std::shared_ptr)));