##// END OF EJS Templates
Merge pull request 172 from SCIQLOP-Initialisation develop...
leroux -
r321:b1c50789867a merge
parent child
Show More
@@ -17,12 +17,12 struct SqpDateTime {
17 17 /// End time
18 18 double m_TEnd;
19 19
20 bool contains(const SqpDateTime &dateTime)
20 bool contains(const SqpDateTime &dateTime) const noexcept
21 21 {
22 22 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
23 23 }
24 24
25 bool intersect(const SqpDateTime &dateTime)
25 bool intersect(const SqpDateTime &dateTime) const noexcept
26 26 {
27 27 return (m_TEnd >= dateTime.m_TStart && m_TStart <= dateTime.m_TEnd);
28 28 }
@@ -34,8 +34,9 public:
34 34 /// @return the data of the variable, nullptr if there is no data
35 35 IDataSeries *dataSeries() const noexcept;
36 36
37 bool contains(const SqpDateTime &dateTime);
38 bool intersect(const SqpDateTime &dateTime);
37 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
39 40
40 41 public slots:
41 42 void setDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
@@ -25,12 +25,10 public:
25 25 * Creates a new variable in the model
26 26 * @param name the name of the new variable
27 27 * @param dateTime the dateTime of the new variable
28 * @param defaultDataSeries the default data of the new variable
29 28 * @return the pointer to the new variable
30 29 */
31 std::shared_ptr<Variable>
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept;
30 std::shared_ptr<Variable> createVariable(const QString &name,
31 const SqpDateTime &dateTime) noexcept;
34 32
35 33 std::shared_ptr<Variable> variable(int index) const;
36 34
@@ -78,12 +78,17 IDataSeries *Variable::dataSeries() const noexcept
78 78 return impl->m_DataSeries.get();
79 79 }
80 80
81 bool Variable::contains(const SqpDateTime &dateTime)
81 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
82 82 {
83 83 return impl->m_DateTime.contains(dateTime);
84 84 }
85 85
86 bool Variable::intersect(const SqpDateTime &dateTime)
86 bool Variable::intersect(const SqpDateTime &dateTime) const noexcept
87 87 {
88 88 return impl->m_DateTime.intersect(dateTime);
89 89 }
90
91 bool Variable::isInside(const SqpDateTime &dateTime) const noexcept
92 {
93 return dateTime.contains(SqpDateTime{impl->m_DateTime.m_TStart, impl->m_DateTime.m_TEnd});
94 }
@@ -55,7 +55,7 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
55 55 impl->m_VariableToSqpDateTimeListMap.at(variable), 0);
56 56 }
57 57 catch (const std::out_of_range &e) {
58 qCWarning(LOG_VariableCacheController()) << e.what();
58 qCWarning(LOG_VariableCacheController()) << "addDateTime" << e.what();
59 59 }
60 60 }
61 61 }
@@ -71,13 +71,12 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable>
71 71 // list of date time request associated to the variable
72 72 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
73 73 // (with a & b of type SqpDateTime) means ts(b) > te(a)
74
75 try {
76 impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
77 notInCache, 0, dateTime.m_TStart);
74 auto it = impl->m_VariableToSqpDateTimeListMap.find(variable);
75 if (it != impl->m_VariableToSqpDateTimeListMap.end()) {
76 impl->addInCacheDataByStart(dateTime, it->second, notInCache, 0, dateTime.m_TStart);
78 77 }
79 catch (const std::out_of_range &e) {
80 qCWarning(LOG_VariableCacheController()) << e.what();
78 else {
79 notInCache << dateTime;
81 80 }
82 81
83 82 return notInCache;
@@ -99,17 +99,21 void VariableController::createVariable(const QString &name,
99 99 /// - default data are generated for the variable, without taking into account the timerange set
100 100 /// in sciqlop
101 101 auto dateTime = impl->m_TimeController->dateTime();
102 if (auto newVariable = impl->m_VariableModel->createVariable(
103 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
102 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
104 103
105 104 // store the provider
106 105 impl->m_VariableToProviderMap[newVariable] = provider;
107 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
108 &Variable::setDataSeries);
109 106
107 auto addDateTimeAcquired
108 = [this, newVariable](auto dataSeriesAcquired, auto dateTimeToPutInCache) {
110 109
111 // store in cache
112 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
110 impl->m_VariableCacheController->addDateTime(newVariable, dateTimeToPutInCache);
111 newVariable->setDataSeries(dataSeriesAcquired);
112
113 };
114
115 connect(provider.get(), &IDataProvider::dataProvided, addDateTimeAcquired);
116 this->onRequestDataLoading(newVariable, dateTime);
113 117
114 118 // notify the creation
115 119 emit variableCreated(newVariable);
@@ -144,8 +148,6 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
144 148 // Ask the provider for each data on the dateTimeListNotInCache
145 149 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
146 150 std::move(dateTimeListNotInCache));
147 // store in cache
148 impl->m_VariableCacheController->addDateTime(variable, dateTime);
149 151 }
150 152 else {
151 153 emit variable->updated();
@@ -52,9 +52,8 VariableModel::VariableModel(QObject *parent)
52 52 {
53 53 }
54 54
55 std::shared_ptr<Variable>
56 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
57 std::shared_ptr<IDataSeries> defaultDataSeries) noexcept
55 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
56 const SqpDateTime &dateTime) noexcept
58 57 {
59 58 auto insertIndex = rowCount();
60 59 beginInsertRows({}, insertIndex, insertIndex);
@@ -62,7 +61,6 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
62 61 /// @todo For the moment, the other data of the variable is initialized with default values
63 62 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
64 63 QStringLiteral("mission"), dateTime);
65 variable->setDataSeries(std::move(defaultDataSeries));
66 64
67 65 impl->m_Variables.push_back(variable);
68 66
@@ -28,6 +28,7 public:
28 28 virtual ~VisualizationGraphWidget();
29 29
30 30 void addVariable(std::shared_ptr<Variable> variable);
31 void addVariableUsingGraph(std::shared_ptr<Variable> variable);
31 32 /// Removes a variable from the graph
32 33 void removeVariable(std::shared_ptr<Variable> variable) noexcept;
33 34
@@ -52,7 +53,7 private slots:
52 53 /// Slot called when right clicking on the graph (displays a menu)
53 54 void onGraphMenuRequested(const QPoint &pos) noexcept;
54 55
55 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
56 void onRangeChanged(const QCPRange &t1);
56 57
57 58 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
58 59 void onMouseWheel(QWheelEvent *event) noexcept;
@@ -42,7 +42,6 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
42 42 const auto &valuesData = scalarSeries.valuesData()->data();
43 43 const auto count = xData.count();
44 44 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache" << xData.count();
45
46 45 auto xValue = QVector<double>(count);
47 46 auto vValue = QVector<double>(count);
48 47
@@ -63,6 +62,10 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSerie
63 62 << xValue.count();
64 63
65 64 qcpGraph->setData(xValue, vValue);
65
66 // Display all data
67 component->rescaleAxes();
68 component->parentPlot()->replot();
66 69 }
67 70 else {
68 71 /// @todo DEBUG
@@ -97,7 +100,6 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QC
97 100
98 101 // Display all data
99 102 component->rescaleAxes();
100
101 103 plot.replot();
102 104 }
103 105 else {
@@ -49,9 +49,9 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget
49 49 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
50 50 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
51 51 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
52 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
53 &QCPAxis::rangeChanged),
54 this, &VisualizationGraphWidget::onRangeChanged);
52 connect(ui->widget->xAxis,
53 static_cast<void (QCPAxis::*)(const QCPRange &)>(&QCPAxis::rangeChanged), this,
54 &VisualizationGraphWidget::onRangeChanged);
55 55
56 56 // Activates menu when right clicking on the graph
57 57 ui->widget->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -80,6 +80,34 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
80 80 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
81 81 }
82 82
83 void VisualizationGraphWidget::addVariableUsingGraph(std::shared_ptr<Variable> variable)
84 {
85
86 // when adding a variable, we need to set its time range to the current graph range
87 auto grapheRange = ui->widget->xAxis->range();
88 auto dateTime = SqpDateTime{grapheRange.lower, grapheRange.upper};
89 variable->setDateTime(dateTime);
90
91 auto variableDateTimeWithTolerance = dateTime;
92
93 // add 10% tolerance for each side
94 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
95 variableDateTimeWithTolerance.m_TStart -= tolerance;
96 variableDateTimeWithTolerance.m_TEnd += tolerance;
97
98 // Uses delegate to create the qcpplot components according to the variable
99 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
100
101 for (auto createdPlottable : qAsConst(createdPlottables)) {
102 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
103 }
104
105 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
106
107 // CHangement detected, we need to ask controller to request data loading
108 emit requestDataLoading(variable, variableDateTimeWithTolerance);
109 }
110
83 111 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable) noexcept
84 112 {
85 113 // Each component associated to the variable :
@@ -136,23 +164,23 void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept
136 164 }
137 165 }
138 166
139 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
167 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1)
140 168 {
141
142 169 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
143 170
144 171 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
145 172 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
146 173
147 174 auto variable = it->first;
148 auto dateTime = SqpDateTime{t2.lower, t2.upper};
175 auto dateTime = SqpDateTime{t1.lower, t1.upper};
149 176
150 177 if (!variable->contains(dateTime)) {
151 178
152 179 auto variableDateTimeWithTolerance = dateTime;
153 if (variable->intersect(dateTime)) {
180 if (!variable->isInside(dateTime)) {
154 181 auto variableDateTime = variable->dateTime();
155 182 if (variableDateTime.m_TStart < dateTime.m_TStart) {
183 qCDebug(LOG_VisualizationGraphWidget()) << tr("TDetection pan to right:");
156 184
157 185 auto diffEndToKeepDelta = dateTime.m_TEnd - variableDateTime.m_TEnd;
158 186 dateTime.m_TStart = variableDateTime.m_TStart + diffEndToKeepDelta;
@@ -161,7 +189,8 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
161 189 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
162 190 variableDateTimeWithTolerance.m_TEnd += tolerance;
163 191 }
164 if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
192 else if (variableDateTime.m_TEnd > dateTime.m_TEnd) {
193 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection pan to left: ");
165 194 auto diffStartToKeepDelta = variableDateTime.m_TStart - dateTime.m_TStart;
166 195 dateTime.m_TEnd = variableDateTime.m_TEnd - diffStartToKeepDelta;
167 196 // Tolerance have to be added to the left
@@ -169,8 +198,13 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
169 198 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
170 199 variableDateTimeWithTolerance.m_TStart -= tolerance;
171 200 }
201 else {
202 qCWarning(LOG_VisualizationGraphWidget())
203 << tr("Detection anormal zoom detection: ");
204 }
172 205 }
173 206 else {
207 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom out: ");
174 208 // add 10% tolerance for each side
175 209 auto tolerance = 0.1 * (dateTime.m_TEnd - dateTime.m_TStart);
176 210 variableDateTimeWithTolerance.m_TStart -= tolerance;
@@ -181,6 +215,9 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange
181 215 // CHangement detected, we need to ask controller to request data loading
182 216 emit requestDataLoading(variable, variableDateTimeWithTolerance);
183 217 }
218 else {
219 qCDebug(LOG_VisualizationGraphWidget()) << tr("Detection zoom in: ");
220 }
184 221 }
185 222 }
186 223
@@ -137,7 +137,7 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
137 137 if (graphWidget) {
138 138 impl->visitLeaf(
139 139 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
140 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariableUsingGraph(var); });
141 141 }
142 142 else {
143 143 qCCritical(LOG_GenerateVariableMenuOperation(),
General Comments 0
You need to be logged in to leave comments. Login now