##// END OF EJS Templates
Centralization of qregistermetatype management
Alexandre Leroux -
r285:d6942e8f24d6
parent child
Show More
@@ -0,0 +1,46
1 #ifndef SCIQLOP_METATYPES_H
2 #define SCIQLOP_METATYPES_H
3
4 #include <QMetaType>
5
6 /**
7 * Struct used to create an instance that registers a type in Qt for signals / slots mechanism
8 * @tparam T the type to register
9 */
10 template <typename T>
11 struct MetaTypeRegistry {
12 explicit MetaTypeRegistry() { qRegisterMetaType<T>(); }
13 };
14
15 /**
16 * This macro can be used to :
17 * - declare a type as a Qt meta type
18 * - and register it (through a static instance) at the launch of SciQlop, so it can be passed in
19 * Qt signals/slots
20 *
21 * It can be used both in .h or in .cpp files
22 *
23 * @param NAME name of the instance under which the type will be registered (in uppercase)
24 * @param TYPE type to register
25 *
26 * Example:
27 * ~~~cpp
28 * // The following macro :
29 * // - declares std::shared_ptr<Variable> as a Qt meta type
30 * // - registers it through an instance named VAR_SHARED_PTR
31 * SCIQLOP_REGISTER_META_TYPE(VAR_SHARED_PTR, std::shared_ptr<Variable>)
32 *
33 * // The following macro :
34 * // - declares a raw pointer of Variable as a Qt meta type
35 * // - registers it through an instance named VAR_RAW_PTR
36 * SCIQLOP_REGISTER_META_TYPE(VAR_RAW_PTR, Variable*)
37 * ~~~
38 *
39 */
40 // clang-format off
41 #define SCIQLOP_REGISTER_META_TYPE(NAME, TYPE) \
42 Q_DECLARE_METATYPE(TYPE) \
43 const auto NAME = MetaTypeRegistry<TYPE>{}; \
44 // clang-format on
45
46 #endif // SCIQLOP_METATYPES_H
@@ -183,12 +183,10 MainWindow::MainWindow(QWidget *parent)
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
184 SLOT(onTimeToUpdate(SqpDateTime)));
184 SLOT(onTimeToUpdate(SqpDateTime)));
185
185
186 qRegisterMetaType<SqpDateTime>();
187 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
186 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
188 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
187 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
189
188
190 // Widgets / widgets connections
189 // Widgets / widgets connections
191 qRegisterMetaType<std::shared_ptr<Variable> >();
192
190
193 // For the following connections, we use DirectConnection to allow each widget that can
191 // For the following connections, we use DirectConnection to allow each widget that can
194 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
192 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
@@ -5,6 +5,8
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 #include <Common/MetaTypes.h>
9
8 #include <Data/SqpDateTime.h>
10 #include <Data/SqpDateTime.h>
9
11
10 class DataProviderParameters;
12 class DataProviderParameters;
@@ -33,7 +35,8 public:
33 signals:
35 signals:
34 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
35 };
37 };
38
36 // Required for using shared_ptr in signals/slots
39 // Required for using shared_ptr in signals/slots
37 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
40 SCIQLOP_REGISTER_META_TYPE(IDATAPROVIDER_PTR_REGISTRY, std::shared_ptr<IDataProvider>)
38
41
39 #endif // SCIQLOP_IDATAPROVIDER_H
42 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,10 +1,10
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <Common/MetaTypes.h>
4
5
5 #include <memory>
6 #include <memory>
6
7
7 #include <QObject>
8 #include <QString>
8 #include <QString>
9
9
10 template <int Dim>
10 template <int Dim>
@@ -49,6 +49,6 public:
49 };
49 };
50
50
51 // Required for using shared_ptr in signals/slots
51 // Required for using shared_ptr in signals/slots
52 Q_DECLARE_METATYPE(std::shared_ptr<IDataSeries>)
52 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
53
53
54 #endif // SCIQLOP_IDATASERIES_H
54 #endif // SCIQLOP_IDATASERIES_H
@@ -6,6 +6,8
6 #include <QDateTime>
6 #include <QDateTime>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 #include <Common/MetaTypes.h>
10
9 /**
11 /**
10 * @brief The SqpDateTime struct holds the information of time parameters
12 * @brief The SqpDateTime struct holds the information of time parameters
11 */
13 */
@@ -37,6 +39,6 inline QDebug operator<<(QDebug d, SqpDateTime obj)
37 }
39 }
38
40
39 // Required for using shared_ptr in signals/slots
41 // Required for using shared_ptr in signals/slots
40 Q_DECLARE_METATYPE(SqpDateTime)
42 SCIQLOP_REGISTER_META_TYPE(SQPDATETIME_REGISTRY, SqpDateTime)
41
43
42 #endif // SCIQLOP_SQPDATETIME_H
44 #endif // SCIQLOP_SQPDATETIME_H
@@ -3,10 +3,10
3
3
4 #include <Data/SqpDateTime.h>
4 #include <Data/SqpDateTime.h>
5
5
6
7 #include <QLoggingCategory>
6 #include <QLoggingCategory>
8 #include <QObject>
7 #include <QObject>
9
8
9 #include <Common/MetaTypes.h>
10 #include <Common/spimpl.h>
10 #include <Common/spimpl.h>
11
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
@@ -50,6 +50,6 private:
50 };
50 };
51
51
52 // Required for using shared_ptr in signals/slots
52 // Required for using shared_ptr in signals/slots
53 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
53 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
54
54
55 #endif // SCIQLOP_VARIABLE_H
55 #endif // SCIQLOP_VARIABLE_H
@@ -104,8 +104,6 void VariableController::createVariable(const QString &name,
104
104
105 // store the provider
105 // store the provider
106 impl->m_VariableToProviderMap[newVariable] = provider;
106 impl->m_VariableToProviderMap[newVariable] = provider;
107 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
108 qRegisterMetaType<SqpDateTime>();
109 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
110 &Variable::onAddDataSeries);
108 &Variable::onAddDataSeries);
111
109
@@ -23,14 +23,12 public:
23 // /////////////////////////////// //
23 // /////////////////////////////// //
24
24
25 // VariableController <-> DataSourceController
25 // VariableController <-> DataSourceController
26 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
27 connect(m_DataSourceController.get(),
26 connect(m_DataSourceController.get(),
28 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 m_VariableController.get(),
28 m_VariableController.get(),
30 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
31
30
32 // VariableController <-> VisualizationController
31 // VariableController <-> VisualizationController
33 qRegisterMetaType<std::shared_ptr<Variable> >();
34 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
35 m_VisualizationController.get(),
33 m_VisualizationController.get(),
36 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
General Comments 0
You need to be logged in to leave comments. Login now