@@ -42,7 +42,7 public slots: | |||||
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; |
|
42 | void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
43 |
|
43 | |||
44 | signals: |
|
44 | signals: | |
45 |
void |
|
45 | void updated(); | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | private: |
|
48 | private: |
@@ -30,14 +30,13 public: | |||||
30 | void setTimeController(TimeController *timeController) noexcept; |
|
30 | void setTimeController(TimeController *timeController) noexcept; | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | /// Request the data loading of the variable whithin dateTime |
|
|||
34 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); |
|
|||
35 |
|
||||
36 | signals: |
|
33 | signals: | |
37 | /// Signal emitted when a variable has been created |
|
34 | /// Signal emitted when a variable has been created | |
38 | void variableCreated(std::shared_ptr<Variable> variable); |
|
35 | void variableCreated(std::shared_ptr<Variable> variable); | |
39 |
|
36 | |||
40 | public slots: |
|
37 | public slots: | |
|
38 | /// Request the data loading of the variable whithin dateTime | |||
|
39 | void onRequestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |||
41 | /** |
|
40 | /** | |
42 | * Creates a new variable and adds it to the model |
|
41 | * Creates a new variable and adds it to the model | |
43 | * @param name the name of the new variable |
|
42 | * @param name the name of the new variable |
@@ -67,7 +67,7 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||||
67 | if (impl->m_DataSeries) { |
|
67 | if (impl->m_DataSeries) { | |
68 | impl->m_DataSeries->merge(dataSeries.get()); |
|
68 | impl->m_DataSeries->merge(dataSeries.get()); | |
69 |
|
69 | |||
70 |
emit |
|
70 | emit updated(); | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 |
|
73 |
@@ -9,7 +9,6 | |||||
9 | #include <Time/TimeController.h> |
|
9 | #include <Time/TimeController.h> | |
10 |
|
10 | |||
11 | #include <QDateTime> |
|
11 | #include <QDateTime> | |
12 | #include <QElapsedTimer> |
|
|||
13 | #include <QMutex> |
|
12 | #include <QMutex> | |
14 | #include <QThread> |
|
13 | #include <QThread> | |
15 |
|
14 | |||
@@ -112,7 +111,7 void VariableController::createVariable(const QString &name, | |||||
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 |
|
113 | |||
115 |
void VariableController:: |
|
114 | void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable, | |
116 | const SqpDateTime &dateTime) |
|
115 | const SqpDateTime &dateTime) | |
117 | { |
|
116 | { | |
118 | // we want to load data of the variable for the dateTime. |
|
117 | // we want to load data of the variable for the dateTime. | |
@@ -120,25 +119,19 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable, | |||||
120 | // For the other, we ask the provider to give them. |
|
119 | // For the other, we ask the provider to give them. | |
121 | if (variable) { |
|
120 | if (variable) { | |
122 |
|
121 | |||
123 | QElapsedTimer timer; |
|
|||
124 | timer.start(); |
|
|||
125 | qCInfo(LOG_VariableController()) << "TORM: The slow s0 operation took" << timer.elapsed() |
|
|||
126 | << "milliseconds"; |
|
|||
127 | auto dateTimeListNotInCache |
|
122 | auto dateTimeListNotInCache | |
128 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); |
|
123 | = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime); | |
129 | qCInfo(LOG_VariableController()) << "TORM: The slow s1 operation took" << timer.elapsed() |
|
|||
130 | << "milliseconds"; |
|
|||
131 |
|
124 | |||
|
125 | if (!dateTimeListNotInCache.empty()) { | |||
132 | // Ask the provider for each data on the dateTimeListNotInCache |
|
126 | // Ask the provider for each data on the dateTimeListNotInCache | |
133 |
impl->m_VariableToProviderMap.at(variable)->requestDataLoading( |
|
127 | impl->m_VariableToProviderMap.at(variable)->requestDataLoading( | |
134 |
|
128 | std::move(dateTimeListNotInCache)); | ||
135 | qCInfo(LOG_VariableController()) << "TORM: The slow s2 operation took" << timer.elapsed() |
|
|||
136 | << "milliseconds"; |
|
|||
137 |
|
||||
138 | // store in cache |
|
129 | // store in cache | |
139 | impl->m_VariableCacheController->addDateTime(variable, dateTime); |
|
130 | impl->m_VariableCacheController->addDateTime(variable, dateTime); | |
140 | qCInfo(LOG_VariableController()) << "TORM: The slow s3 operation took" << timer.elapsed() |
|
131 | } | |
141 | << "milliseconds"; |
|
132 | else { | |
|
133 | emit variable->updated(); | |||
|
134 | } | |||
142 | } |
|
135 | } | |
143 | else { |
|
136 | else { | |
144 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
|
137 | qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null"); |
@@ -13,6 +13,7 | |||||
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) |
|
13 | Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget) | |
14 |
|
14 | |||
15 | class QCPRange; |
|
15 | class QCPRange; | |
|
16 | class SqpDateTime; | |||
16 | class Variable; |
|
17 | class Variable; | |
17 |
|
18 | |||
18 | namespace Ui { |
|
19 | namespace Ui { | |
@@ -37,6 +38,9 public: | |||||
37 |
|
38 | |||
38 | void updateDisplay(std::shared_ptr<Variable> variable); |
|
39 | void updateDisplay(std::shared_ptr<Variable> variable); | |
39 |
|
40 | |||
|
41 | signals: | |||
|
42 | void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime); | |||
|
43 | ||||
40 |
|
44 | |||
41 | private: |
|
45 | private: | |
42 | Ui::VisualizationGraphWidget *ui; |
|
46 | Ui::VisualizationGraphWidget *ui; |
@@ -37,30 +37,32 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie | |||||
37 | timer.start(); |
|
37 | timer.start(); | |
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { |
|
38 | if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) { | |
39 | // Clean the graph |
|
39 | // Clean the graph | |
40 | qCDebug(LOG_VisualizationGraphHelper()) << "The slow s1 operation took" << timer.elapsed() |
|
|||
41 | << "milliseconds"; |
|
|||
42 | // NAIVE approch |
|
40 | // NAIVE approch | |
43 | const auto &xData = scalarSeries.xAxisData()->data(); |
|
41 | const auto &xData = scalarSeries.xAxisData()->data(); | |
44 | const auto &valuesData = scalarSeries.valuesData()->data(); |
|
42 | const auto &valuesData = scalarSeries.valuesData()->data(); | |
|
43 | const auto count = xData.count(); | |||
|
44 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count(); | |||
45 |
|
45 | |||
46 | auto xValue = QVector<double>(); |
|
46 | auto xValue = QVector<double>(count); | |
47 | auto vValue = QVector<double>(); |
|
47 | auto vValue = QVector<double>(count); | |
48 |
|
48 | |||
49 | const auto count = xData.count(); |
|
49 | int n = 0; | |
50 | auto ite = 0; |
|
|||
51 | for (auto i = 0; i < count; ++i) { |
|
50 | for (auto i = 0; i < count; ++i) { | |
52 |
const auto x = xData |
|
51 | const auto x = xData[i]; | |
53 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { |
|
52 | if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) { | |
54 |
xValue |
|
53 | xValue[n] = x; | |
55 |
vValue |
|
54 | vValue[n] = valuesData[i]; | |
56 |
++ |
|
55 | ++n; | |
57 | } |
|
56 | } | |
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 | qcpGraph->setData(xValue, vValue); |
|
59 | xValue.resize(n); | |
|
60 | vValue.resize(n); | |||
61 |
|
61 | |||
62 |
qC |
|
62 | qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed" | |
63 |
|
|
63 | << xValue.count(); | |
|
64 | ||||
|
65 | qcpGraph->setData(xValue, vValue); | |||
64 | } |
|
66 | } | |
65 | else { |
|
67 | else { | |
66 | /// @todo DEBUG |
|
68 | /// @todo DEBUG |
@@ -57,6 +57,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget | |||||
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); |
|
57 | ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); | |
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, |
|
58 | connect(ui->widget, &QCustomPlot::customContextMenuRequested, this, | |
59 | &VisualizationGraphWidget::onGraphMenuRequested); |
|
59 | &VisualizationGraphWidget::onGraphMenuRequested); | |
|
60 | ||||
|
61 | connect(this, &VisualizationGraphWidget::requestDataLoading, &sqpApp->variableController(), | |||
|
62 | &VariableController::onRequestDataLoading); | |||
60 | } |
|
63 | } | |
61 |
|
64 | |||
62 |
|
65 | |||
@@ -74,7 +77,7 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable) | |||||
74 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); |
|
77 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
75 | } |
|
78 | } | |
76 |
|
79 | |||
77 |
connect(variable.get(), SIGNAL( |
|
80 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); | |
78 | } |
|
81 | } | |
79 |
|
82 | |||
80 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept |
|
83 | void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept | |
@@ -142,9 +145,6 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange | |||||
142 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { |
|
145 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
143 |
|
146 | |||
144 | auto variable = it->first; |
|
147 | auto variable = it->first; | |
145 | qCInfo(LOG_VisualizationGraphWidget()) |
|
|||
146 | << tr("TORM: VisualizationGraphWidget::onRangeChanged") |
|
|||
147 | << variable->dataSeries()->xAxisData()->size(); |
|
|||
148 | auto dateTime = SqpDateTime{t2.lower, t2.upper}; |
|
148 | auto dateTime = SqpDateTime{t2.lower, t2.upper}; | |
149 |
|
149 | |||
150 | if (!variable->contains(dateTime)) { |
|
150 | if (!variable->contains(dateTime)) { | |
@@ -179,8 +179,7 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange | |||||
179 | variable->setDateTime(dateTime); |
|
179 | variable->setDateTime(dateTime); | |
180 |
|
180 | |||
181 | // CHangement detected, we need to ask controller to request data loading |
|
181 | // CHangement detected, we need to ask controller to request data loading | |
182 | sqpApp->variableController().requestDataLoading(variable, |
|
182 | emit requestDataLoading(variable, variableDateTimeWithTolerance); | |
183 | variableDateTimeWithTolerance); |
|
|||
184 | } |
|
183 | } | |
185 | } |
|
184 | } | |
186 | } |
|
185 | } |
@@ -5,6 +5,8 | |||||
5 |
|
5 | |||
6 | #include <cmath> |
|
6 | #include <cmath> | |
7 |
|
7 | |||
|
8 | #include <QDateTime> | |||
|
9 | ||||
8 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") |
|
10 | Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") | |
9 |
|
11 | |||
10 | std::unique_ptr<IDataSeries> |
|
12 | std::unique_ptr<IDataSeries> | |
@@ -16,6 +18,7 CosinusProvider::retrieveData(const DataProviderParameters ¶meters) const | |||||
16 | auto start = dateTime.m_TStart; |
|
18 | auto start = dateTime.m_TStart; | |
17 | auto end = dateTime.m_TEnd; |
|
19 | auto end = dateTime.m_TEnd; | |
18 |
|
20 | |||
|
21 | ||||
19 | // We assure that timerange is valid |
|
22 | // We assure that timerange is valid | |
20 | if (end < start) { |
|
23 | if (end < start) { | |
21 | std::swap(start, end); |
|
24 | std::swap(start, end); | |
@@ -47,10 +50,12 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeLis | |||||
47 |
|
50 | |||
48 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) |
|
51 | std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime) | |
49 | { |
|
52 | { | |
|
53 | auto dataIndex = 0; | |||
50 |
|
54 | |||
51 | // Gets the timerange from the parameters |
|
55 | // Gets the timerange from the parameters | |
52 | auto start = dateTime.m_TStart; |
|
56 | double freq = 100.0; | |
53 | auto end = dateTime.m_TEnd; |
|
57 | double start = dateTime.m_TStart * freq; // 100 htz | |
|
58 | double end = dateTime.m_TEnd * freq; // 100 htz | |||
54 |
|
59 | |||
55 | // We assure that timerange is valid |
|
60 | // We assure that timerange is valid | |
56 | if (end < start) { |
|
61 | if (end < start) { | |
@@ -61,11 +66,9 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTi | |||||
61 | auto scalarSeries |
|
66 | auto scalarSeries | |
62 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); |
|
67 | = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{}); | |
63 |
|
68 | |||
64 | auto dataIndex = 0; |
|
|||
65 | for (auto time = start; time < end; ++time, ++dataIndex) { |
|
69 | for (auto time = start; time < end; ++time, ++dataIndex) { | |
66 | scalarSeries->setData(dataIndex, time, std::cos(time)); |
|
70 | const auto timeOnFreq = time / freq; | |
|
71 | scalarSeries->setData(dataIndex, timeOnFreq, std::cos(timeOnFreq)); | |||
67 | } |
|
72 | } | |
68 |
|
||||
69 |
|
||||
70 | return scalarSeries; |
|
73 | return scalarSeries; | |
71 | } |
|
74 | } |
General Comments 0
You need to be logged in to leave comments.
Login now