##// END OF EJS Templates
Manage drag&drop of empty graphs
trabillard -
r844:a582bf0b199a
parent child
Show More
@@ -47,6 +47,13 public:
47 47 */
48 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 57 // IVisualizationWidget interface
51 58 void accept(IVisualizationWidgetVisitor *visitor) override;
52 59 bool canDrop(const Variable &variable) const override;
@@ -5,6 +5,8
5 5 #include "Visualization/VisualizationZoneWidget.h"
6 6 #include "Visualization/VisualizationGraphWidget.h"
7 7
8 #include "Variable/VariableController.h"
9
8 10 #include "SqpApplication.h"
9 11 #include "DragDropHelper.h"
10 12
@@ -90,8 +92,7 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Vari
90 92
91 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};
94 this->insertZone(index, zoneWidget);
95 auto zoneWidget = createEmptyZone(index);
95 96
96 97 // Creates a new graph into the zone
97 98 zoneWidget->createGraph(variables, index);
@@ -99,6 +100,14 VisualizationZoneWidget *VisualizationTabWidget::createZone(const QList<std::sha
99 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 111 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
103 112 {
104 113 if (visitor) {
@@ -157,19 +166,39 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
157 166 Q_ASSERT(parentDragDropContainer);
158 167
159 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
163 graphWidget->parentZoneWidget()->close();
174 if (nbGraph == 1)
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 187 else
166 188 {
167 //Close the graph
168 graphWidget->close();
169 }
189 //The graph is empty, create an empty zone and move the graph inside
170 190
171 const auto& variables = graphWidget->variables();
172 createZone(variables, index);
191 auto parentZoneWidget = graphWidget->parentZoneWidget();
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 203 else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE))
175 204 {
@@ -226,7 +226,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
226 226 if (layout->count() > 0) {
227 227 // Case of a new graph in a existant zone
228 228 if (auto visualizationGraphWidget
229 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
229 = dynamic_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
230 230 range = visualizationGraphWidget->graphRange();
231 231 }
232 232 }
@@ -243,7 +243,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
243 243 if (auto dataSeries = variable->dataSeries()) {
244 244 dataSeries->lockRead();
245 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 247 auto end = dataSeries->cend();
248 248 if (valuesBounds.first != end && valuesBounds.second != end) {
249 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 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)
366 {
367 //The drop didn't occur in the same zone
365 //The drop didn't occur in the same zone
368 366
369 auto previousParentZoneWidget = graphWidget->parentZoneWidget();
370 auto nbGraph = parentDragDropContainer->countDragWidget();
371 if (nbGraph == 1)
372 {
373 //This is the only graph in the previous zone, close the zone
374 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);
367 auto previousParentZoneWidget = graphWidget->parentZoneWidget();
368 auto nbGraph = parentDragDropContainer->countDragWidget();
369 if (nbGraph == 1)
370 {
371 //This is the only graph in the previous zone, close the zone
372 previousParentZoneWidget->close();
384 373 }
385 374 else
386 375 {
387 //The drop occurred in the same zone
388 //Simple move of the graph, no variable operation associated
389 parentDragDropContainer->layout()->removeWidget(graphWidget);
390 ui->dragDropContainer->insertDragWidget(index, graphWidget);
376 //Close the graph
377 graphWidget->close();
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 6
Approved

Status change > Approved

You need to be logged in to leave comments. Login now