diff --git a/core/tests/Data/TestOptionalAxis.cpp b/core/tests/Data/TestOptionalAxis.cpp index ad4959b..f02f256 100644 --- a/core/tests/Data/TestOptionalAxis.cpp +++ b/core/tests/Data/TestOptionalAxis.cpp @@ -111,8 +111,8 @@ void TestOptionalAxis::testSize_data() QTest::newRow("data1") << axis({}) << 0; QTest::newRow("data2") << axis({1, 2, 3}) << 3; QTest::newRow("data3") << axis({1, 2, 3, 4}) << 4; - QTest::newRow("data4 (axis not defined)") - << OptionalAxis{} << 0; // Expects 0 for undefined axis + QTest::newRow("data4 (axis not defined)") << OptionalAxis{} + << 0; // Expects 0 for undefined axis } void TestOptionalAxis::testSize() @@ -135,8 +135,8 @@ void TestOptionalAxis::testUnit_data() QTest::newRow("data1") << axis(Unit{"Hz"}) << Unit{"Hz"}; QTest::newRow("data2") << axis(Unit{"t", true}) << Unit{"t", true}; - QTest::newRow("data3 (axis not defined)") - << OptionalAxis{} << Unit{}; // Expects default unit for undefined axis + QTest::newRow("data3 (axis not defined)") << OptionalAxis{} + << Unit{}; // Expects default unit for undefined axis } void TestOptionalAxis::testUnit() diff --git a/core/tests/Data/TestScalarSeries.cpp b/core/tests/Data/TestScalarSeries.cpp index 75b1bb6..f747ff9 100644 --- a/core/tests/Data/TestScalarSeries.cpp +++ b/core/tests/Data/TestScalarSeries.cpp @@ -173,18 +173,18 @@ void TestScalarSeries::testMergeWithVector_data() { testMergeDifferentTypes_struct(); - QTest::newRow("mergeVectorInScalar") - << ScalarBuilder{} - .setX({1., 2., 3., 4., 5.}) - .setValues({100., 200., 300., 400., 500.}) - .build() - << VectorBuilder{} - .setX({6., 7., 8., 9., 10.}) - .setXValues({600., 700., 800., 900., 1000.}) - .setYValues({610., 710., 810., 910., 1010.}) - .setZValues({620., 720., 820., 920., 1020.}) - .build() - << DataContainer{1., 2., 3., 4., 5.} << DataContainer{100., 200., 300., 400., 500.}; + QTest::newRow("mergeVectorInScalar") << ScalarBuilder{} + .setX({1., 2., 3., 4., 5.}) + .setValues({100., 200., 300., 400., 500.}) + .build() + << VectorBuilder{} + .setX({6., 7., 8., 9., 10.}) + .setXValues({600., 700., 800., 900., 1000.}) + .setYValues({610., 710., 810., 910., 1010.}) + .setZValues({620., 720., 820., 920., 1020.}) + .build() + << DataContainer{1., 2., 3., 4., 5.} + << DataContainer{100., 200., 300., 400., 500.}; } void TestScalarSeries::testMergeWithVector() @@ -278,12 +278,12 @@ void TestScalarSeries::testPurge_data() .build() << 2. << 4. << DataContainer{2., 3., 4.} << std::vector{{200., 300., 400.}}; - QTest::newRow("purgeScalar1 (min/max swap)") - << ScalarBuilder{} - .setX({1., 2., 3., 4., 5.}) - .setValues({100., 200., 300., 400., 500.}) - .build() - << 4. << 2. << DataContainer{2., 3., 4.} << std::vector{{200., 300., 400.}}; + QTest::newRow("purgeScalar1 (min/max swap)") << ScalarBuilder{} + .setX({1., 2., 3., 4., 5.}) + .setValues({100., 200., 300., 400., 500.}) + .build() + << 4. << 2. << DataContainer{2., 3., 4.} + << std::vector{{200., 300., 400.}}; QTest::newRow("purgeScalar2") << ScalarBuilder{} .setX({1., 2., 3., 4., 5.}) .setValues({100., 200., 300., 400., 500.}) @@ -324,12 +324,12 @@ void TestScalarSeries::testXAxisRange_data() .build() << -1. << 3.2 << DataContainer{1., 2., 3.} << DataContainer{100., 200., 300.}; - QTest::newRow("xAxisRange1 (min/max swap)") - << ScalarBuilder{} - .setX({1., 2., 3., 4., 5.}) - .setValues({100., 200., 300., 400., 500.}) - .build() - << 3.2 << -1. << DataContainer{1., 2., 3.} << DataContainer{100., 200., 300.}; + QTest::newRow("xAxisRange1 (min/max swap)") << ScalarBuilder{} + .setX({1., 2., 3., 4., 5.}) + .setValues({100., 200., 300., 400., 500.}) + .build() + << 3.2 << -1. << DataContainer{1., 2., 3.} + << DataContainer{100., 200., 300.}; QTest::newRow("xAxisRange2") << ScalarBuilder{} .setX({1., 2., 3., 4., 5.}) .setValues({100., 200., 300., 400., 500.}) @@ -401,10 +401,10 @@ void TestScalarSeries::testValuesBounds_data() .setValues({100., 200., 300., 400., 500.}) .build() << 5.1 << 6. << false << nan << nan; - QTest::newRow("scalarBounds5") - << ScalarBuilder{}.setX({1.}).setValues({100.}).build() << 0. << 2. << true << 100. << 100.; - QTest::newRow("scalarBounds6") - << ScalarBuilder{}.setX({}).setValues({}).build() << 0. << 2. << false << nan << nan; + QTest::newRow("scalarBounds5") << ScalarBuilder{}.setX({1.}).setValues({100.}).build() << 0. + << 2. << true << 100. << 100.; + QTest::newRow("scalarBounds6") << ScalarBuilder{}.setX({}).setValues({}).build() << 0. << 2. + << false << nan << nan; // Tests with NaN values: NaN values are not included in min/max search QTest::newRow("scalarBounds7") << ScalarBuilder{} diff --git a/gui/include/DragAndDrop/DragDropHelper.h b/gui/include/DragAndDrop/DragDropHelper.h index c557cb5..7274376 100644 --- a/gui/include/DragAndDrop/DragDropHelper.h +++ b/gui/include/DragAndDrop/DragDropHelper.h @@ -63,6 +63,10 @@ public: void setHightlightedDragWidget(VisualizationDragWidget *dragWidget); VisualizationDragWidget *getHightlightedDragWidget() const; + /// Delays the closing of a widget during a drag&drop operation + void delayedCloseWidget(QWidget *widget); + void doCloseWidgets(); + private: class DragDropHelperPrivate; spimpl::unique_impl_ptr impl; diff --git a/gui/src/DataSource/DataSourceTreeWidget.cpp b/gui/src/DataSource/DataSourceTreeWidget.cpp index 24f7f00..d8bc863 100644 --- a/gui/src/DataSource/DataSourceTreeWidget.cpp +++ b/gui/src/DataSource/DataSourceTreeWidget.cpp @@ -9,7 +9,9 @@ #include -DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) {} +DataSourceTreeWidget::DataSourceTreeWidget(QWidget *parent) : QTreeWidget(parent) +{ +} QMimeData *DataSourceTreeWidget::mimeData(const QList items) const { diff --git a/gui/src/DragAndDrop/DragDropHelper.cpp b/gui/src/DragAndDrop/DragDropHelper.cpp index dd2b000..88a6756 100644 --- a/gui/src/DragAndDrop/DragDropHelper.cpp +++ b/gui/src/DragAndDrop/DragDropHelper.cpp @@ -38,6 +38,8 @@ struct DragDropHelper::DragDropHelperPrivate { QMetaObject::Connection m_DragWidgetDestroyedConnection; QMetaObject::Connection m_HighlightedWidgetDestroyedConnection; + QList m_WidgetToClose; + explicit DragDropHelperPrivate() : m_PlaceHolder{std::make_unique()}, m_DragDropScroller{std::make_unique()}, @@ -95,7 +97,9 @@ struct DragDropHelper::DragDropHelperPrivate { }; -DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl()} {} +DragDropHelper::DragDropHelper() : impl{spimpl::make_unique_impl()} +{ +} DragDropHelper::~DragDropHelper() { @@ -209,6 +213,21 @@ VisualizationDragWidget *DragDropHelper::getHightlightedDragWidget() const return impl->m_HighlightedDragWidget; } +void DragDropHelper::delayedCloseWidget(QWidget *widget) +{ + widget->hide(); + impl->m_WidgetToClose << widget; +} + +void DragDropHelper::doCloseWidgets() +{ + for (auto widget : impl->m_WidgetToClose) { + widget->close(); + } + + impl->m_WidgetToClose.clear(); +} + bool DragDropHelper::checkMimeDataForVisualization(const QMimeData *mimeData, VisualizationDragDropContainer *dropContainer) { diff --git a/gui/src/Variable/VariableInspectorTableView.cpp b/gui/src/Variable/VariableInspectorTableView.cpp index 9d752a1..29352d3 100644 --- a/gui/src/Variable/VariableInspectorTableView.cpp +++ b/gui/src/Variable/VariableInspectorTableView.cpp @@ -3,7 +3,9 @@ #include "DragAndDrop/DragDropHelper.h" #include "SqpApplication.h" -VariableInspectorTableView::VariableInspectorTableView(QWidget *parent) : QTableView(parent) {} +VariableInspectorTableView::VariableInspectorTableView(QWidget *parent) : QTableView(parent) +{ +} void VariableInspectorTableView::startDrag(Qt::DropActions supportedActions) { diff --git a/gui/src/Visualization/VisualizationDragDropContainer.cpp b/gui/src/Visualization/VisualizationDragDropContainer.cpp index 07e5b4e..e8136ba 100644 --- a/gui/src/Visualization/VisualizationDragDropContainer.cpp +++ b/gui/src/Visualization/VisualizationDragDropContainer.cpp @@ -210,8 +210,9 @@ void VisualizationDragDropContainer::startDrag(VisualizationDragWidget *dragWidg // do not add the placeHolder } - // Note: The exec() is blocking on windows but not on linux and macOS - drag->exec(Qt::MoveAction | Qt::CopyAction); + drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::MoveAction); + + helper.doCloseWidgets(); } else { qCWarning(LOG_VisualizationDragDropContainer()) diff --git a/gui/src/Visualization/VisualizationTabWidget.cpp b/gui/src/Visualization/VisualizationTabWidget.cpp index 9c6d8ab..b706f40 100644 --- a/gui/src/Visualization/VisualizationTabWidget.cpp +++ b/gui/src/Visualization/VisualizationTabWidget.cpp @@ -237,11 +237,11 @@ void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph( if (nbGraph == 1) { // This is the only graph in the previous zone, close the zone - graphWidget->parentZoneWidget()->close(); + helper.delayedCloseWidget(graphWidget->parentZoneWidget()); } else { // Close the graph - graphWidget->close(); + helper.delayedCloseWidget(graphWidget); } tabWidget->createZone(variables, index); @@ -258,7 +258,7 @@ void VisualizationTabWidget::VisualizationTabWidgetPrivate::dropGraph( // Close the old zone if it was the only graph inside if (nbGraph == 1) { - parentZoneWidget->close(); + helper.delayedCloseWidget(parentZoneWidget); } } } diff --git a/gui/src/Visualization/VisualizationZoneWidget.cpp b/gui/src/Visualization/VisualizationZoneWidget.cpp index 365012f..f32c34d 100644 --- a/gui/src/Visualization/VisualizationZoneWidget.cpp +++ b/gui/src/Visualization/VisualizationZoneWidget.cpp @@ -452,11 +452,11 @@ void VisualizationZoneWidget::VisualizationZoneWidgetPrivate::dropGraph( auto nbGraph = parentDragDropContainer->countDragWidget(); if (nbGraph == 1) { // This is the only graph in the previous zone, close the zone - previousParentZoneWidget->close(); + helper.delayedCloseWidget(previousParentZoneWidget); } else { // Close the graph - graphWidget->close(); + helper.delayedCloseWidget(graphWidget); } // Creates the new graph in the zone