##// END OF EJS Templates
The mock plugin can now create data with view operation
perrinel -
r235:746eaca503e3
parent child
Show More
@@ -17,7 +17,10 class QString;
17 17 /**
18 18 * @brief The Variable class represents a variable in SciQlop.
19 19 */
20 class Variable {
20 class Variable : public QObject {
21
22 Q_OBJECT
23
21 24 public:
22 25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
23 26 const SqpDateTime &dateTime);
@@ -25,14 +28,20 public:
25 28 QString name() const noexcept;
26 29 QString mission() const noexcept;
27 30 QString unit() const noexcept;
28
29 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
31 SqpDateTime dateTime() const noexcept;
30 32
31 33 /// @return the data of the variable, nullptr if there is no data
32 34 IDataSeries *dataSeries() const noexcept;
33 35
36 bool contains(SqpDateTime dateTime);
37 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
38
34 39 public slots:
35 void onXRangeChanged(SqpDateTime dateTime);
40 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41
42 signals:
43 void dataCacheUpdated();
44
36 45
37 46 private:
38 47 class VariablePrivate;
@@ -1,11 +1,14
1 1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 2 #define SCIQLOP_VARIABLECONTROLLER_H
3 3
4 #include <Data/SqpDateTime.h>
5
4 6 #include <QLoggingCategory>
5 7 #include <QObject>
6 8
7 9 #include <Common/spimpl.h>
8 10
11
9 12 class IDataProvider;
10 13 class TimeController;
11 14 class Variable;
@@ -26,6 +29,10 public:
26 29
27 30 void setTimeController(TimeController *timeController) noexcept;
28 31
32
33 /// Request the data loading of the variable whithin dateTime
34 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
35
29 36 signals:
30 37 /// Signal emitted when a variable has been created
31 38 void variableCreated(std::shared_ptr<Variable> variable);
@@ -45,12 +45,25 QString Variable::unit() const noexcept
45 45 return impl->m_Unit;
46 46 }
47 47
48 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
50 return impl->m_DateTime;
51 }
52
53 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
49 54 {
50 55 if (!impl->m_DataSeries) {
51 56 impl->m_DataSeries = std::move(dataSeries);
52 57 }
53 /// @todo : else, merge the two data series (if possible)
58 }
59
60 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
61 {
62 if (impl->m_DataSeries) {
63 impl->m_DataSeries->merge(dataSeries.get());
64
65 emit dataCacheUpdated();
66 }
54 67 }
55 68
56 69 IDataSeries *Variable::dataSeries() const noexcept
@@ -58,10 +71,8 IDataSeries *Variable::dataSeries() const noexcept
58 71 return impl->m_DataSeries.get();
59 72 }
60 73
61 void Variable::onXRangeChanged(SqpDateTime dateTime)
74 bool Variable::contains(SqpDateTime dateTime)
62 75 {
63 qCInfo(LOG_Variable()) << "onXRangeChanged detected";
64
65 76 if (!impl->m_DateTime.contains(dateTime)) {
66 77 // The current variable dateTime isn't enough to display the dateTime requested.
67 78 // We have to update it to the new dateTime requested.
@@ -70,5 +81,9 void Variable::onXRangeChanged(SqpDateTime dateTime)
70 81 qCInfo(LOG_Variable()) << "NEW DATE NEEDED";
71 82
72 83 impl->m_DateTime = dateTime;
84
85 return false;
73 86 }
87
88 return true;
74 89 }
@@ -1,3 +1,4
1 #include <Variable/Variable.h>
1 2 #include <Variable/VariableCacheController.h>
2 3 #include <Variable/VariableController.h>
3 4 #include <Variable/VariableModel.h>
@@ -8,6 +9,7
8 9 #include <Time/TimeController.h>
9 10
10 11 #include <QDateTime>
12 #include <QElapsedTimer>
11 13 #include <QMutex>
12 14 #include <QThread>
13 15
@@ -44,6 +46,9 struct VariableController::VariableControllerPrivate {
44 46
45 47 TimeController *m_TimeController{nullptr};
46 48 std::unique_ptr<VariableCacheController> m_VariableCacheController;
49
50 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
51 m_VariableToProviderMap;
47 52 };
48 53
49 54 VariableController::VariableController(QObject *parent)
@@ -73,13 +78,6 void VariableController::setTimeController(TimeController *timeController) noexc
73 78 void VariableController::createVariable(const QString &name,
74 79 std::shared_ptr<IDataProvider> provider) noexcept
75 80 {
76 // TORM
77 // auto dateTime = SqpDateTime{
78 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
79 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
80 // / 1000.),
81 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
82 // / 1000.};
83 81
84 82 if (!impl->m_TimeController) {
85 83 qCCritical(LOG_VariableController())
@@ -97,6 +95,14 void VariableController::createVariable(const QString &name,
97 95 if (auto newVariable = impl->m_VariableModel->createVariable(
98 96 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
99 97
98 // store the provider
99 impl->m_VariableToProviderMap[newVariable] = provider;
100 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
101 qRegisterMetaType<SqpDateTime>();
102 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
103 &Variable::onAddDataSeries);
104
105
100 106 // store in cache
101 107 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
102 108
@@ -105,6 +111,41 void VariableController::createVariable(const QString &name,
105 111 }
106 112 }
107 113
114
115 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable,
116 const SqpDateTime &dateTime)
117 {
118 // we want to load data of the variable for the dateTime.
119 // First we check if the cache contains some of them.
120 // For the other, we ask the provider to give them.
121 if (variable) {
122
123 QElapsedTimer timer;
124 timer.start();
125 qCInfo(LOG_VariableController()) << "The slow s0 operation took" << timer.elapsed()
126 << "milliseconds";
127 auto dateTimeListNotInCache
128 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
129 qCInfo(LOG_VariableController()) << "The slow s1 operation took" << timer.elapsed()
130 << "milliseconds";
131
132 // Ask the provider for each data on the dateTimeListNotInCache
133 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache);
134
135 qCInfo(LOG_VariableController()) << "The slow s2 operation took" << timer.elapsed()
136 << "milliseconds";
137
138 // store in cache
139 impl->m_VariableCacheController->addDateTime(variable, dateTime);
140 qCInfo(LOG_VariableController()) << "The slow s3 operation took" << timer.elapsed()
141 << "milliseconds";
142 }
143 else {
144 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
145 }
146 }
147
148
108 149 void VariableController::initialize()
109 150 {
110 151 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
@@ -35,7 +35,7 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
35 35 /// @todo For the moment, the other data of the variable is initialized with default values
36 36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
37 37 QStringLiteral("mission"), dateTime);
38 variable->addDataSeries(std::move(defaultDataSeries));
38 variable->setDataSeries(std::move(defaultDataSeries));
39 39
40 40 impl->m_Variables.push_back(variable);
41 41
@@ -18,6 +18,7 class DataSourceWidget : public QWidget {
18 18
19 19 public:
20 20 explicit DataSourceWidget(QWidget *parent = 0);
21 virtual ~DataSourceWidget() noexcept;
21 22
22 23 public slots:
23 24 /**
@@ -1,6 +1,8
1 1 #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H
2 2 #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H
3 3
4 #include <Data/SqpDateTime.h>
5
4 6 #include <QLoggingCategory>
5 7 #include <QVector>
6 8
@@ -8,6 +10,7
8 10
9 11 Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory)
10 12
13 class IDataSeries;
11 14 class QCPAbstractPlottable;
12 15 class QCustomPlot;
13 16 class Variable;
@@ -27,6 +30,9 struct GraphPlottablesFactory {
27 30 */
28 31 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
29 32 QCustomPlot &plot) noexcept;
33
34 static void updateData(QVector<QCPAbstractPlottable *> plotableVect, IDataSeries *dataSeries,
35 const SqpDateTime &dateTime);
30 36 };
31 37
32 38 #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H
@@ -34,6 +34,9 public:
34 34 void close() override;
35 35 QString name() const override;
36 36
37 void updateDisplay(std::shared_ptr<Variable> variable);
38
39
37 40 private:
38 41 Ui::VisualizationGraphWidget *ui;
39 42
@@ -46,6 +49,8 private slots:
46 49
47 50 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
48 51 void onMouseWheel(QWheelEvent *event) noexcept;
52
53 void onDataCacheVariableUpdated();
49 54 };
50 55
51 56 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -5,6 +5,8
5 5
6 6 #include <Variable/Variable.h>
7 7
8 #include <QElapsedTimer>
9
8 10 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
9 11
10 12 namespace {
@@ -28,15 +30,55 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
28 30 }
29 31 }
30 32
31 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot)
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
35 {
36 QElapsedTimer timer;
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
40 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s1 operation took" << timer.elapsed()
41 << "milliseconds";
42 // NAIVE approch
43 const auto &xData = scalarSeries.xAxisData()->data();
44 const auto &valuesData = scalarSeries.valuesData()->data();
45
46 auto xValue = QVector<double>();
47 auto vValue = QVector<double>();
48
49 const auto count = xData.count();
50 auto ite = 0;
51 for (auto i = 0; i < count; ++i) {
52 const auto x = xData.at(i);
53 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
54 xValue.push_back(x);
55 vValue.push_back(valuesData.at(i));
56 ++ite;
57 }
58 }
59
60 qcpGraph->setData(xValue, vValue);
61
62 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s2 operation took" << timer.elapsed()
63 << "milliseconds";
64 }
65 else {
66 /// @todo DEBUG
67 }
68 }
69
70 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
71 const SqpDateTime &dateTime)
32 72 {
33 73 auto component = plot.addGraph();
34 74
35 75 if (component) {
36 // Graph data
76 // // Graph data
37 77 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
38 78 true);
39 79
80 updateScalarData(component, scalarSeries, dateTime);
81
40 82 // Axes properties
41 83 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
42 84 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
@@ -75,7 +117,7 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<V
75 117 // Gets the data series of the variable to call the creation of the right components
76 118 // according to its type
77 119 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
78 result.append(createScalarSeriesComponent(*scalarSeries, plot));
120 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
79 121 }
80 122 else {
81 123 qCDebug(LOG_GraphPlottablesFactory())
@@ -89,3 +131,21 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<V
89 131
90 132 return result;
91 133 }
134
135 void GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *> plotableVect,
136 IDataSeries *dataSeries, const SqpDateTime &dateTime)
137 {
138 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
139 if (plotableVect.size() == 1) {
140 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
141 }
142 else {
143 qCCritical(LOG_GraphPlottablesFactory()) << QObject::tr(
144 "Can't update Data of a scalarSeries because there is not only one component "
145 "associated");
146 }
147 }
148 else {
149 /// @todo DEBUG
150 }
151 }
@@ -3,7 +3,12
3 3 #include "Visualization/IVisualizationWidgetVisitor.h"
4 4 #include "ui_VisualizationGraphWidget.h"
5 5
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
6 9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
11
7 12 #include <unordered_map>
8 13
9 14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
@@ -21,7 +26,8 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
21 26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
22 27
23 28 // 1 variable -> n qcpplot
24 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 m_VariableToPlotMultiMap;
25 31 };
26 32
27 33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
@@ -58,8 +64,11 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
58 64 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
59 65
60 66 for (auto createdPlottable : qAsConst(createdPlottables)) {
61 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
62 68 }
69
70 connect(variable.get(), &Variable::dataCacheUpdated, this,
71 &VisualizationGraphWidget::onDataCacheVariableUpdated);
63 72 }
64 73
65 74 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
@@ -98,9 +107,20 QString VisualizationGraphWidget::name() const
98 107
99 108 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
100 109 {
101 for (auto it = impl->m_VariableToPlotMap.cbegin(); it != impl->m_VariableToPlotMap.cend();
102 ++it) {
103 it->first->onXRangeChanged(SqpDateTime{t2.lower, t2.upper});
110
111 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
112
113 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
114 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
115 auto variable = it->first;
116 auto tolerance = 0.1 * (t2.upper - t2.lower);
117 auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance};
118
119 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
120 << variable->dataSeries()->xAxisData()->size();
121 if (!variable->contains(dateTime)) {
122 sqpApp->variableController().requestDataLoading(variable, dateTime);
123 }
104 124 }
105 125 }
106 126
@@ -120,3 +140,27 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
120 140
121 141 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
122 142 }
143
144 void VisualizationGraphWidget::onDataCacheVariableUpdated()
145 {
146 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
147 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
148 auto variable = it->first;
149 GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
150 variable->dataSeries(), variable->dateTime());
151 }
152 }
153
154 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
155 {
156 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
157
158 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
159
160 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
161 abstractPlotableVect.push_back(it->second);
162 }
163
164 GraphPlottablesFactory::updateData(abstractPlotableVect, variable->dataSeries(),
165 variable->dateTime());
166 }
General Comments 0
You need to be logged in to leave comments. Login now