##// END OF EJS Templates
Keep the selection zones when a graph is dropped in another synchro zone
trabillard -
r1088:1eed201e150e
parent child
Show More
@@ -51,6 +51,12 public:
51 51 SqpRange graphRange() const noexcept;
52 52 void setGraphRange(const SqpRange &range);
53 53
54 /// Returns the ranges of all the selection zones on the graph
55 QVector<SqpRange> selectionZoneRanges() const;
56
57 /// Adds new selection zones in the graph
58 void addSelectionZones(const QVector<SqpRange> &ranges);
59
54 60 /// Undo the last zoom done with a zoom box
55 61 void undoZoom();
56 62
@@ -60,6 +60,9 public:
60 60 VisualizationGraphWidget *createGraph(const QList<std::shared_ptr<Variable> > variables,
61 61 int index);
62 62
63 /// Returns the first graph in the zone or nullptr if there is no graph inside
64 VisualizationGraphWidget *firstGraph() const;
65
63 66 // IVisualizationWidget interface
64 67 void accept(IVisualizationWidgetVisitor *visitor) override;
65 68 bool canDrop(const Variable &variable) const override;
@@ -19,7 +19,7 VisualizationDragWidget::VisualizationDragWidget(QWidget *parent)
19 19 {
20 20 }
21 21
22 virtual QPixmap VisualizationDragWidget::customDragPixmap(const QPoint &dragPosition)
22 QPixmap VisualizationDragWidget::customDragPixmap(const QPoint &dragPosition)
23 23 {
24 24 Q_UNUSED(dragPosition);
25 25 return QPixmap();
@@ -335,6 +335,27 void VisualizationGraphWidget::setGraphRange(const SqpRange &range)
335 335 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END");
336 336 }
337 337
338 QVector<SqpRange> VisualizationGraphWidget::selectionZoneRanges() const
339 {
340 QVector<SqpRange> ranges;
341 for (auto zone : impl->m_SelectionZones) {
342 ranges << zone->range();
343 }
344
345 return ranges;
346 }
347
348 void VisualizationGraphWidget::addSelectionZones(const QVector<SqpRange> &ranges)
349 {
350 for (const auto &range : ranges) {
351 auto zone = new VisualizationSelectionZoneItem(&plot());
352 zone->setRange(range.m_TStart, range.m_TEnd);
353 impl->m_SelectionZones << zone;
354 }
355
356 plot().replot(QCustomPlot::rpQueuedReplot);
357 }
358
338 359 void VisualizationGraphWidget::undoZoom()
339 360 {
340 361 auto zoom = impl->m_ZoomStack.pop();
@@ -255,7 +255,16 void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph(
255 255 helper.delayedCloseWidget(graphWidget);
256 256 }
257 257
258 tabWidget->createZone(variables, index);
258 auto zoneWidget = tabWidget->createZone(variables, index);
259 auto firstGraph = zoneWidget->firstGraph();
260 if (firstGraph) {
261 firstGraph->addSelectionZones(graphWidget->selectionZoneRanges());
262 }
263 else {
264 qCWarning(LOG_VisualizationZoneWidget())
265 << tr("VisualizationTabWidget::dropGraph, no graph added in the widget.");
266 Q_ASSERT(false);
267 }
259 268 }
260 269 else {
261 270 // The graph is empty, create an empty zone and move the graph inside
@@ -72,21 +72,6 struct VisualizationZoneWidget::VisualizationZoneWidgetPrivate {
72 72 QUuid m_SynchronisationGroupId;
73 73 std::unique_ptr<IGraphSynchronizer> m_Synchronizer;
74 74
75 // Returns the first graph in the zone or nullptr if there is no graph inside
76 VisualizationGraphWidget *firstGraph(const VisualizationZoneWidget *zoneWidget) const
77 {
78 VisualizationGraphWidget *firstGraph = nullptr;
79 auto layout = zoneWidget->ui->dragDropContainer->layout();
80 if (layout->count() > 0) {
81 if (auto visualizationGraphWidget
82 = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
83 firstGraph = visualizationGraphWidget;
84 }
85 }
86
87 return firstGraph;
88 }
89
90 75 void dropGraph(int index, VisualizationZoneWidget *zoneWidget);
91 76 void dropVariables(const QList<std::shared_ptr<Variable> > &variables, int index,
92 77 VisualizationZoneWidget *zoneWidget);
@@ -286,7 +271,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
286 271 &VisualizationZoneWidget::onVariableAboutToBeRemoved);
287 272
288 273 auto range = SqpRange{};
289 if (auto firstGraph = impl->firstGraph(this)) {
274 if (auto firstGraph = this->firstGraph()) {
290 275 // Case of a new graph in a existant zone
291 276 range = firstGraph->graphRange();
292 277 }
@@ -318,6 +303,20 VisualizationZoneWidget::createGraph(const QList<std::shared_ptr<Variable> > var
318 303 return graphWidget;
319 304 }
320 305
306 VisualizationGraphWidget *VisualizationZoneWidget::firstGraph() const
307 {
308 VisualizationGraphWidget *firstGraph = nullptr;
309 auto layout = ui->dragDropContainer->layout();
310 if (layout->count() > 0) {
311 if (auto visualizationGraphWidget
312 = qobject_cast<VisualizationGraphWidget *>(layout->itemAt(0)->widget())) {
313 firstGraph = visualizationGraphWidget;
314 }
315 }
316
317 return firstGraph;
318 }
319
321 320 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
322 321 {
323 322 if (visitor) {
@@ -361,7 +360,7 QMimeData *VisualizationZoneWidget::mimeData(const QPoint &position) const
361 360 auto mimeData = new QMimeData;
362 361 mimeData->setData(MIME_TYPE_ZONE, QByteArray{});
363 362
364 if (auto firstGraph = impl->firstGraph(this)) {
363 if (auto firstGraph = this->firstGraph()) {
365 364 auto timeRangeData = TimeController::mimeDataForTimeRange(firstGraph->graphRange());
366 365 mimeData->setData(MIME_TYPE_TIME_RANGE, timeRangeData);
367 366 }
@@ -547,7 +546,8 void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph(
547 546 }
548 547
549 548 // Creates the new graph in the zone
550 zoneWidget->createGraph(variables, index);
549 auto newGraphWidget = zoneWidget->createGraph(variables, index);
550 newGraphWidget->addSelectionZones(graphWidget->selectionZoneRanges());
551 551 }
552 552 else {
553 553 // The drop occurred in the same zone or the graph is empty
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

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