@@ -47,6 +47,13 public: | |||||
47 | */ |
|
47 | */ | |
48 | VisualizationZoneWidget *createZone(const QList<std::shared_ptr<Variable>>& variables, int index); |
|
48 | VisualizationZoneWidget *createZone(const QList<std::shared_ptr<Variable>>& variables, int index); | |
49 |
|
49 | |||
|
50 | /** | |||
|
51 | * Creates a zone which is empty (no variables). The zone is inserted at the specified index. | |||
|
52 | * @param index The index where the zone should be inserted in the layout | |||
|
53 | * @return the pointer to the created zone | |||
|
54 | */ | |||
|
55 | VisualizationZoneWidget *createEmptyZone(int index); | |||
|
56 | ||||
50 | // IVisualizationWidget interface |
|
57 | // IVisualizationWidget interface | |
51 | void accept(IVisualizationWidgetVisitor *visitor) override; |
|
58 | void accept(IVisualizationWidgetVisitor *visitor) override; | |
52 | bool canDrop(const Variable &variable) const override; |
|
59 | bool canDrop(const Variable &variable) const override; |
@@ -5,6 +5,8 | |||||
5 | #include "Visualization/VisualizationZoneWidget.h" |
|
5 | #include "Visualization/VisualizationZoneWidget.h" | |
6 | #include "Visualization/VisualizationGraphWidget.h" |
|
6 | #include "Visualization/VisualizationGraphWidget.h" | |
7 |
|
7 | |||
|
8 | #include "Variable/VariableController.h" | |||
|
9 | ||||
8 | #include "SqpApplication.h" |
|
10 | #include "SqpApplication.h" | |
9 | #include "DragDropHelper.h" |
|
11 | #include "DragDropHelper.h" | |
10 |
|
12 | |||
@@ -90,8 +92,7 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Vari | |||||
90 |
|
92 | |||
91 | VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) |
|
93 | VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::shared_ptr<Variable> > &variables, int index) | |
92 | { |
|
94 | { | |
93 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; |
|
95 | auto zoneWidget = createEmptyZone(index); | |
94 | this->insertZone(index, zoneWidget); |
|
|||
95 |
|
96 | |||
96 | // Creates a new graph into the zone |
|
97 | // Creates a new graph into the zone | |
97 | zoneWidget->createGraph(variables, index); |
|
98 | zoneWidget->createGraph(variables, index); | |
@@ -99,6 +100,14 VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::sha | |||||
99 | return zoneWidget; |
|
100 | return zoneWidget; | |
100 | } |
|
101 | } | |
101 |
|
102 | |||
|
103 | VisualizationZoneWidget *VisualizationTabWidget::createEmptyZone(int index) | |||
|
104 | { | |||
|
105 | auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*ui->dragDropContainer->layout()), this}; | |||
|
106 | this->insertZone(index, zoneWidget); | |||
|
107 | ||||
|
108 | return zoneWidget; | |||
|
109 | } | |||
|
110 | ||||
102 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) |
|
111 | void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor) | |
103 | { |
|
112 | { | |
104 | if (visitor) { |
|
113 | if (visitor) { | |
@@ -157,19 +166,39 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData) | |||||
157 | Q_ASSERT(parentDragDropContainer); |
|
166 | Q_ASSERT(parentDragDropContainer); | |
158 |
|
167 | |||
159 | auto nbGraph = parentDragDropContainer->countDragWidget(); |
|
168 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
160 | if (nbGraph == 1) |
|
169 | ||
|
170 | const auto& variables = graphWidget->variables(); | |||
|
171 | ||||
|
172 | if (!variables.isEmpty()) | |||
161 | { |
|
173 | { | |
162 | //This is the only graph in the previous zone, close the zone |
|
174 | if (nbGraph == 1) | |
163 | graphWidget->parentZoneWidget()->close(); |
|
175 | { | |
|
176 | //This is the only graph in the previous zone, close the zone | |||
|
177 | graphWidget->parentZoneWidget()->close(); | |||
|
178 | } | |||
|
179 | else | |||
|
180 | { | |||
|
181 | //Close the graph | |||
|
182 | graphWidget->close(); | |||
|
183 | } | |||
|
184 | ||||
|
185 | createZone(variables, index); | |||
164 | } |
|
186 | } | |
165 | else |
|
187 | else | |
166 | { |
|
188 | { | |
167 | //Close the graph |
|
189 | //The graph is empty, create an empty zone and move the graph inside | |
168 | graphWidget->close(); |
|
|||
169 | } |
|
|||
170 |
|
190 | |||
171 |
|
|
191 | auto parentZoneWidget = graphWidget->parentZoneWidget(); | |
172 | createZone(variables, index); |
|
192 | ||
|
193 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |||
|
194 | ||||
|
195 | auto zoneWidget = createEmptyZone(index); | |||
|
196 | zoneWidget->addGraph(graphWidget); | |||
|
197 | ||||
|
198 | //Close the old zone if it was the only graph inside | |||
|
199 | if (nbGraph == 1) | |||
|
200 | parentZoneWidget->close(); | |||
|
201 | } | |||
173 | } |
|
202 | } | |
174 | else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) |
|
203 | else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE)) | |
175 | { |
|
204 | { |
@@ -226,7 +226,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
226 | if (layout->count() > 0) { |
|
226 | if (layout->count() > 0) { | |
227 | // Case of a new graph in a existant zone |
|
227 | // Case of a new graph in a existant zone | |
228 | if (auto visualizationGraphWidget |
|
228 | if (auto visualizationGraphWidget | |
229 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { |
|
229 | = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) { | |
230 | range = visualizationGraphWidget->graphRange(); |
|
230 | range = visualizationGraphWidget->graphRange(); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
@@ -243,7 +243,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
243 | if (auto dataSeries = variable->dataSeries()) { |
|
243 | if (auto dataSeries = variable->dataSeries()) { | |
244 | dataSeries->lockRead(); |
|
244 | dataSeries->lockRead(); | |
245 | auto valuesBounds |
|
245 | auto valuesBounds | |
246 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); |
|
246 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); | |
247 | auto end = dataSeries->cend(); |
|
247 | auto end = dataSeries->cend(); | |
248 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
248 | if (valuesBounds.first != end && valuesBounds.second != end) { | |
249 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
249 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |
@@ -360,35 +360,47 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData) | |||||
360 |
|
360 | |||
361 | const auto& variables = graphWidget->variables(); |
|
361 | const auto& variables = graphWidget->variables(); | |
362 |
|
362 | |||
363 | if (!variables.empty()) |
|
363 | if (parentDragDropContainer != ui->dragDropContainer && !variables.isEmpty()) | |
364 | { |
|
364 | { | |
365 | if (parentDragDropContainer != ui->dragDropContainer) |
|
365 | //The drop didn't occur in the same zone | |
366 | { |
|
|||
367 | //The drop didn't occur in the same zone |
|
|||
368 |
|
366 | |||
369 |
|
|
367 | auto previousParentZoneWidget = graphWidget->parentZoneWidget(); | |
370 |
|
|
368 | auto nbGraph = parentDragDropContainer->countDragWidget(); | |
371 |
|
|
369 | if (nbGraph == 1) | |
372 |
|
|
370 | { | |
373 |
|
|
371 | //This is the only graph in the previous zone, close the zone | |
374 |
|
|
372 | previousParentZoneWidget->close(); | |
375 | } |
|
|||
376 | else |
|
|||
377 | { |
|
|||
378 | //Close the graph |
|
|||
379 | graphWidget->close(); |
|
|||
380 | } |
|
|||
381 |
|
||||
382 | //Creates the new graph in the zone |
|
|||
383 | createGraph(variables, index); |
|
|||
384 | } |
|
373 | } | |
385 | else |
|
374 | else | |
386 | { |
|
375 | { | |
387 | //The drop occurred in the same zone |
|
376 | //Close the graph | |
388 | //Simple move of the graph, no variable operation associated |
|
377 | graphWidget->close(); | |
389 | parentDragDropContainer->layout()->removeWidget(graphWidget); |
|
|||
390 | ui->dragDropContainer->insertDragWidget(index, graphWidget); |
|
|||
391 | } |
|
378 | } | |
|
379 | ||||
|
380 | //Creates the new graph in the zone | |||
|
381 | createGraph(variables, index); | |||
|
382 | } | |||
|
383 | else | |||
|
384 | { | |||
|
385 | //The drop occurred in the same zone or the graph is empty | |||
|
386 | //Simple move of the graph, no variable operation associated | |||
|
387 | parentDragDropContainer->layout()->removeWidget(graphWidget); | |||
|
388 | ||||
|
389 | if (variables.isEmpty() && parentDragDropContainer != ui->dragDropContainer) | |||
|
390 | { | |||
|
391 | // The graph is empty and dropped in a different zone. | |||
|
392 | // Take the range of the first graph in the zone (if existing). | |||
|
393 | auto layout = ui->dragDropContainer->layout(); | |||
|
394 | if (layout->count() > 0) | |||
|
395 | { | |||
|
396 | if (auto visualizationGraphWidget = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) | |||
|
397 | { | |||
|
398 | graphWidget->setGraphRange(visualizationGraphWidget->graphRange()); | |||
|
399 | } | |||
|
400 | } | |||
|
401 | } | |||
|
402 | ||||
|
403 | ui->dragDropContainer->insertDragWidget(index, graphWidget); | |||
392 | } |
|
404 | } | |
393 | } |
|
405 | } | |
394 | } |
|
406 | } |
General Comments 0
You need to be logged in to leave comments.
Login now