##// 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,6 +166,11 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
157 166 Q_ASSERT(parentDragDropContainer);
158 167
159 168 auto nbGraph = parentDragDropContainer->countDragWidget();
169
170 const auto& variables = graphWidget->variables();
171
172 if (!variables.isEmpty())
173 {
160 174 if (nbGraph == 1)
161 175 {
162 176 //This is the only graph in the previous zone, close the zone
@@ -168,9 +182,24 void VisualizationTabWidget::dropMimeData(int index, const QMimeData *mimeData)
168 182 graphWidget->close();
169 183 }
170 184
171 const auto& variables = graphWidget->variables();
172 185 createZone(variables, index);
173 186 }
187 else
188 {
189 //The graph is empty, create an empty zone and move the graph inside
190
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 }
202 }
174 203 else if (mimeData->hasFormat(DragDropHelper::MIME_TYPE_ZONE))
175 204 {
176 205 //Simple move of the zone, no variable operation associated
@@ -360,9 +360,7 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
360 360
361 361 const auto& variables = graphWidget->variables();
362 362
363 if (!variables.empty())
364 {
365 if (parentDragDropContainer != ui->dragDropContainer)
363 if (parentDragDropContainer != ui->dragDropContainer && !variables.isEmpty())
366 364 {
367 365 //The drop didn't occur in the same zone
368 366
@@ -384,11 +382,25 void VisualizationZoneWidget::dropMimeData(int index, const QMimeData *mimeData)
384 382 }
385 383 else
386 384 {
387 //The drop occurred in the same zone
385 //The drop occurred in the same zone or the graph is empty
388 386 //Simple move of the graph, no variable operation associated
389 387 parentDragDropContainer->layout()->removeWidget(graphWidget);
390 ui->dragDropContainer->insertDragWidget(index, 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 }
391 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