##// END OF EJS Templates
Merge branch 'feature/VariousCorrections' into develop
Alexandre Leroux -
r288:1ae4a887fc77 merge
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 183 connect(timeWidget, SIGNAL(timeUpdated(SqpDateTime)), &sqpApp->timeController(),
184 184 SLOT(onTimeToUpdate(SqpDateTime)));
185 185
186 qRegisterMetaType<SqpDateTime>();
187 186 connect(&sqpApp->timeController(), SIGNAL(timeUpdated(SqpDateTime)),
188 187 &sqpApp->variableController(), SLOT(onDateTimeOnSelection(SqpDateTime)));
189 188
190 189 // Widgets / widgets connections
191 qRegisterMetaType<std::shared_ptr<Variable> >();
192 190
193 191 // For the following connections, we use DirectConnection to allow each widget that can
194 192 // potentially attach a menu to the variable's menu to do so before this menu is displayed.
@@ -26,12 +26,14 class DataSeries : public IDataSeries {
26 26 public:
27 27 /// @sa IDataSeries::xAxisData()
28 28 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
29 const std::shared_ptr<ArrayData<1> > xAxisData() const { return m_XAxisData; }
29 30
30 31 /// @sa IDataSeries::xAxisUnit()
31 32 Unit xAxisUnit() const override { return m_XAxisUnit; }
32 33
33 34 /// @return the values dataset
34 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35 std::shared_ptr<ArrayData<Dim> > valuesData() { return m_ValuesData; }
36 const std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
35 37
36 38 /// @sa IDataSeries::valuesUnit()
37 39 Unit valuesUnit() const override { return m_ValuesUnit; }
@@ -60,6 +62,27 protected:
60 62 {
61 63 }
62 64
65 /// Copy ctor
66 explicit DataSeries(const DataSeries<Dim> &other)
67 : m_XAxisData{std::make_shared<ArrayData<1> >(*other.m_XAxisData)},
68 m_XAxisUnit{other.m_XAxisUnit},
69 m_ValuesData{std::make_shared<ArrayData<Dim> >(*other.m_ValuesData)},
70 m_ValuesUnit{other.m_ValuesUnit}
71 {
72 }
73
74 /// Assignment operator
75 template <int D>
76 DataSeries &operator=(DataSeries<D> other)
77 {
78 std::swap(m_XAxisData, other.m_XAxisData);
79 std::swap(m_XAxisUnit, other.m_XAxisUnit);
80 std::swap(m_ValuesData, other.m_ValuesData);
81 std::swap(m_ValuesUnit, other.m_ValuesUnit);
82
83 return *this;
84 }
85
63 86 private:
64 87 std::shared_ptr<ArrayData<1> > m_XAxisData;
65 88 Unit m_XAxisUnit;
@@ -5,6 +5,8
5 5
6 6 #include <QObject>
7 7
8 #include <Common/MetaTypes.h>
9
8 10 #include <Data/SqpDateTime.h>
9 11
10 12 class DataProviderParameters;
@@ -24,7 +26,7 class IDataProvider : public QObject {
24 26 public:
25 27 virtual ~IDataProvider() noexcept = default;
26 28
27 virtual std::unique_ptr<IDataSeries>
29 virtual std::shared_ptr<IDataSeries>
28 30 retrieveData(const DataProviderParameters &parameters) const = 0;
29 31
30 32
@@ -33,7 +35,8 public:
33 35 signals:
34 36 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, const SqpDateTime &dateTime);
35 37 };
38
36 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 42 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,10 +1,10
1 1 #ifndef SCIQLOP_IDATASERIES_H
2 2 #define SCIQLOP_IDATASERIES_H
3 3
4 #include <Common/MetaTypes.h>
4 5
5 6 #include <memory>
6 7
7 #include <QObject>
8 8 #include <QString>
9 9
10 10 template <int Dim>
@@ -41,14 +41,19 public:
41 41 /// Returns the x-axis dataset
42 42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
43 43
44 /// Returns the x-axis dataset (as const)
45 virtual const std::shared_ptr<ArrayData<1> > xAxisData() const = 0;
46
44 47 virtual Unit xAxisUnit() const = 0;
45 48
46 49 virtual Unit valuesUnit() const = 0;
47 50
48 51 virtual void merge(IDataSeries *dataSeries) = 0;
52
53 virtual std::unique_ptr<IDataSeries> clone() const = 0;
49 54 };
50 55
51 56 // Required for using shared_ptr in signals/slots
52 Q_DECLARE_METATYPE(std::shared_ptr<IDataSeries>)
57 SCIQLOP_REGISTER_META_TYPE(IDATASERIES_PTR_REGISTRY, std::shared_ptr<IDataSeries>)
53 58
54 59 #endif // SCIQLOP_IDATASERIES_H
@@ -23,6 +23,8 public:
23 23 * @param value the value data
24 24 */
25 25 void setData(int index, double x, double value) noexcept;
26
27 std::unique_ptr<IDataSeries> clone() const;
26 28 };
27 29
28 30 #endif // SCIQLOP_SCALARSERIES_H
@@ -6,6 +6,8
6 6 #include <QDateTime>
7 7 #include <QDebug>
8 8
9 #include <Common/MetaTypes.h>
10
9 11 /**
10 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 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 44 #endif // SCIQLOP_SQPDATETIME_H
@@ -3,10 +3,10
3 3
4 4 #include <Data/SqpDateTime.h>
5 5
6
7 6 #include <QLoggingCategory>
8 7 #include <QObject>
9 8
9 #include <Common/MetaTypes.h>
10 10 #include <Common/spimpl.h>
11 11
12 12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
@@ -36,10 +36,9 public:
36 36
37 37 bool contains(const SqpDateTime &dateTime);
38 38 bool intersect(const SqpDateTime &dateTime);
39 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
40 39
41 40 public slots:
42 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
43 42
44 43 signals:
45 44 void updated();
@@ -50,6 +49,6 private:
50 49 };
51 50
52 51 // Required for using shared_ptr in signals/slots
53 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
52 SCIQLOP_REGISTER_META_TYPE(VARIABLE_PTR_REGISTRY, std::shared_ptr<Variable>)
54 53
55 54 #endif // SCIQLOP_VARIABLE_H
@@ -30,7 +30,7 public:
30 30 */
31 31 std::shared_ptr<Variable>
32 32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
34 34
35 35 std::shared_ptr<Variable> variable(int index) const;
36 36
@@ -11,3 +11,8 void ScalarSeries::setData(int index, double x, double value) noexcept
11 11 xAxisData()->setData(index, x);
12 12 valuesData()->setData(index, value);
13 13 }
14
15 std::unique_ptr<IDataSeries> ScalarSeries::clone() const
16 {
17 return std::make_unique<ScalarSeries>(*this);
18 }
@@ -55,16 +55,18 void Variable::setDateTime(const SqpDateTime &dateTime) noexcept
55 55 impl->m_DateTime = dateTime;
56 56 }
57 57
58 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
58 void Variable::setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
59 59 {
60 if (!impl->m_DataSeries) {
61 impl->m_DataSeries = std::move(dataSeries);
60 if (!dataSeries) {
61 /// @todo ALX : log
62 return;
62 63 }
63 }
64 64
65 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
66 {
67 if (impl->m_DataSeries) {
65 // Inits the data series of the variable
66 if (!impl->m_DataSeries) {
67 impl->m_DataSeries = dataSeries->clone();
68 }
69 else {
68 70 impl->m_DataSeries->merge(dataSeries.get());
69 71
70 72 emit updated();
@@ -21,7 +21,7 namespace {
21 21
22 22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
23 23 /// will be deleted when the timerange is recovered from SciQlop
24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::shared_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
25 25 const SqpDateTime &dateTime) noexcept
26 26 {
27 27 auto parameters = DataProviderParameters{dateTime};
@@ -104,10 +104,8 void VariableController::createVariable(const QString &name,
104 104
105 105 // store the provider
106 106 impl->m_VariableToProviderMap[newVariable] = provider;
107 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
108 qRegisterMetaType<SqpDateTime>();
109 107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
110 &Variable::onAddDataSeries);
108 &Variable::setDataSeries);
111 109
112 110
113 111 // store in cache
@@ -54,7 +54,7 VariableModel::VariableModel(QObject *parent)
54 54
55 55 std::shared_ptr<Variable>
56 56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
57 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
58 58 {
59 59 auto insertIndex = rowCount();
60 60 beginInsertRows({}, insertIndex, insertIndex);
@@ -41,6 +41,9 public:
41 41 QString name() const override;
42 42
43 43 private:
44 /// @return the layout of tab in which zones are added
45 QLayout &tabLayout() const noexcept;
46
44 47 Ui::VisualizationTabWidget *ui;
45 48
46 49 class VisualizationTabWidgetPrivate;
@@ -23,14 +23,12 public:
23 23 // /////////////////////////////// //
24 24
25 25 // VariableController <-> DataSourceController
26 qRegisterMetaType<std::shared_ptr<IDataProvider> >();
27 26 connect(m_DataSourceController.get(),
28 27 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 28 m_VariableController.get(),
30 29 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
31 30
32 31 // VariableController <-> VisualizationController
33 qRegisterMetaType<std::shared_ptr<Variable> >();
34 32 connect(m_VariableController.get(), SIGNAL(variableCreated(std::shared_ptr<Variable>)),
35 33 m_VisualizationController.get(),
36 34 SIGNAL(variableCreated(std::shared_ptr<Variable>)));
@@ -48,12 +48,12 VisualizationTabWidget::~VisualizationTabWidget()
48 48
49 49 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
50 50 {
51 this->layout()->addWidget(zoneWidget);
51 tabLayout().addWidget(zoneWidget);
52 52 }
53 53
54 54 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
55 55 {
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
56 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(tabLayout()), this};
57 57 this->addZone(zoneWidget);
58 58
59 59 // Creates a new graph into the zone
@@ -68,8 +68,9 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
68 68 visitor->visitEnter(this);
69 69
70 70 // Apply visitor to zone children
71 for (auto i = 0; i < layout()->count(); ++i) {
72 if (auto item = layout()->itemAt(i)) {
71 auto &layout = tabLayout();
72 for (auto i = 0; i < layout.count(); ++i) {
73 if (auto item = layout.itemAt(i)) {
73 74 // Widgets different from zones are not visited (no action)
74 75 if (auto visualizationZoneWidget
75 76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
@@ -96,3 +97,8 QString VisualizationTabWidget::name() const
96 97 {
97 98 return impl->m_Name;
98 99 }
100
101 QLayout &VisualizationTabWidget::tabLayout() const noexcept
102 {
103 return *ui->scrollAreaWidgetContents->layout();
104 }
@@ -10,6 +10,9 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
10 10
11 11 namespace {
12 12
13 /// Minimum height for graph added in zones (in pixels)
14 const auto GRAPH_MINIMUM_HEIGHT = 300;
15
13 16 /// Generates a default name for a new graph, according to the number of graphs already displayed in
14 17 /// the zone
15 18 QString defaultGraphName(const QLayout &layout)
@@ -53,6 +56,11 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
53 56 {
54 57 auto graphWidget = new VisualizationGraphWidget{
55 58 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
59
60 // Set graph properties
61 graphWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
62 graphWidget->setMinimumHeight(GRAPH_MINIMUM_HEIGHT);
63
56 64 this->addGraph(graphWidget);
57 65
58 66 graphWidget->addVariable(variable);
@@ -18,6 +18,18 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
18 18 {
19 19 }
20 20
21 void visitRootEnter()
22 {
23 // Creates the root menu
24 m_MenuBuilder.addMenu(QObject::tr("Plot"));
25 }
26
27 void visitRootLeave()
28 {
29 // Closes the root menu
30 m_MenuBuilder.closeMenu();
31 }
32
21 33 void visitNodeEnter(const IVisualizationWidget &container)
22 34 {
23 35 // Opens a new menu associated to the node
@@ -60,12 +72,16 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
60 72 {
61 73 // VisualizationWidget is not intended to accommodate a variable
62 74 Q_UNUSED(widget)
75
76 impl->visitRootEnter();
63 77 }
64 78
65 79 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
66 80 {
67 81 // VisualizationWidget is not intended to accommodate a variable
68 82 Q_UNUSED(widget)
83
84 impl->visitRootLeave();
69 85 }
70 86
71 87 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
@@ -13,7 +13,47
13 13 <property name="windowTitle">
14 14 <string>Form</string>
15 15 </property>
16 <layout class="QVBoxLayout" name="verticalLayout"/>
16 <layout class="QVBoxLayout" name="verticalLayout">
17 <property name="leftMargin">
18 <number>0</number>
19 </property>
20 <property name="topMargin">
21 <number>0</number>
22 </property>
23 <property name="rightMargin">
24 <number>0</number>
25 </property>
26 <property name="bottomMargin">
27 <number>0</number>
28 </property>
29 <item>
30 <widget class="QScrollArea" name="scrollArea">
31 <property name="styleSheet">
32 <string notr="true">background-color: transparent;</string>
33 </property>
34 <property name="frameShape">
35 <enum>QFrame::NoFrame</enum>
36 </property>
37 <property name="frameShadow">
38 <enum>QFrame::Sunken</enum>
39 </property>
40 <property name="widgetResizable">
41 <bool>true</bool>
42 </property>
43 <widget class="QWidget" name="scrollAreaWidgetContents">
44 <property name="geometry">
45 <rect>
46 <x>0</x>
47 <y>0</y>
48 <width>400</width>
49 <height>300</height>
50 </rect>
51 </property>
52 <layout class="QVBoxLayout" name="verticalLayout_3"/>
53 </widget>
54 </widget>
55 </item>
56 </layout>
17 57 </widget>
18 58 <resources/>
19 59 <connections/>
@@ -13,7 +13,7 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
13 13 class CosinusProvider : public IDataProvider {
14 14 public:
15 15 /// @sa IDataProvider::retrieveData()
16 std::unique_ptr<IDataSeries>
16 std::shared_ptr<IDataSeries>
17 17 retrieveData(const DataProviderParameters &parameters) const override;
18 18
19 19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
@@ -9,47 +9,11
9 9
10 10 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
11 11
12 std::unique_ptr<IDataSeries>
12 std::shared_ptr<IDataSeries>
13 13 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
14 14 {
15 15 auto dateTime = parameters.m_Time;
16 16
17 // Gets the timerange from the parameters
18 auto start = dateTime.m_TStart;
19 auto end = dateTime.m_TEnd;
20
21
22 // We assure that timerange is valid
23 if (end < start) {
24 std::swap(start, end);
25 }
26
27 // Generates scalar series containing cosinus values (one value per second)
28 auto scalarSeries
29 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
30
31 auto dataIndex = 0;
32 for (auto time = start; time < end; ++time, ++dataIndex) {
33 scalarSeries->setData(dataIndex, time, std::cos(time));
34 }
35
36 return scalarSeries;
37 }
38
39 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
40 {
41 // NOTE: Try to use multithread if possible
42 for (const auto &dateTime : dateTimeList) {
43
44 auto scalarSeries = this->retrieveDataSeries(dateTime);
45
46 emit dataProvided(scalarSeries, dateTime);
47 }
48 }
49
50
51 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
52 {
53 17 auto dataIndex = 0;
54 18
55 19 // Gets the timerange from the parameters
@@ -72,3 +36,12 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTi
72 36 }
73 37 return scalarSeries;
74 38 }
39
40 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
41 {
42 // NOTE: Try to use multithread if possible
43 for (const auto &dateTime : dateTimeList) {
44 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
45 emit dataProvided(scalarSeries, dateTime);
46 }
47 }
General Comments 0
You need to be logged in to leave comments. Login now