From 19075a214d07b776fbd5288649e67dd7cc108e16 2018-11-01 10:35:54 From: Alexis Jeandet Date: 2018-11-01 10:35:54 Subject: [PATCH] Refac + clang-format Clang format: changed style to have line break on each brace refac: more VisualisationGraphWidget work, zone move still broken Signed-off-by: Alexis Jeandet --- diff --git a/.clang-format b/.clang-format index 02acebe..ddb374f 100644 --- a/.clang-format +++ b/.clang-format @@ -2,7 +2,7 @@ # See http://clang.llvm.org/docs/ClangFormatStyleOptions.html for a definition # of the options Language: Cpp -BasedOnStyle: LLVM +BasedOnStyle: WebKit # Line length ColumnLimit: 100 @@ -12,8 +12,7 @@ IndentWidth: 4 AccessModifierOffset: -4 # -IndentWidth ConstructorInitializerIndentWidth: 8 # 2 * IndentWidth -# Break only before function braces -BreakBeforeBraces: Stroustrup +BreakBeforeBraces: Allman AllowShortFunctionsOnASingleLine: Inline AlwaysBreakTemplateDeclarations: true @@ -22,5 +21,6 @@ BreakBeforeBinaryOperators: true ConstructorInitializerAllOnOneLineOrOnePerLine: true IndentCaseLabels: true MaxEmptyLinesToKeep: 2 -Standard: Cpp03 +Standard: Cpp11 +UseTab: Never diff --git a/CMakeLists.txt b/CMakeLists.txt index b5d4ecd..4706e21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ endif() if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) endif() -set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3") find_package(Qt5 COMPONENTS Core Widgets Network PrintSupport Svg Test REQUIRED) diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 5a2bdcf..04d1701 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -169,9 +169,15 @@ struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { } } - void startDrawingZone(const QPoint &pos, VisualizationGraphWidget *graph) + void selectZone(const QPoint &pos) { - endDrawingZone(graph); + auto zoneAtPos = selectionZoneAt(pos); + setSelectionZonesEditionEnabled(sqpApp->plotsInteractionMode() == SqpApplication::PlotsInteractionMode::SelectionZones); + } + + void startDrawingZone(const QPoint &pos) + { + endDrawingZone(); auto axisPos = posToAxisPos(pos); @@ -180,7 +186,7 @@ struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { m_DrawingZone->setEditionEnabled(false); } - void endDrawingZone(VisualizationGraphWidget *graph) + void endDrawingZone() { if (m_DrawingZone) { auto drawingZoneRange = m_DrawingZone->range(); @@ -189,14 +195,24 @@ struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { addSelectionZone(m_DrawingZone); } else { - graph->plot().removeItem(m_DrawingZone); // the item is deleted by QCustomPlot + m_plot->removeItem(m_DrawingZone); } - graph->plot().replot(QCustomPlot::rpQueuedReplot); + m_plot->replot(QCustomPlot::rpQueuedReplot); m_DrawingZone = nullptr; } } + void moveSelectionZone(const QPoint& destination) + { + /* + * I give up on this for now + * @TODO implement this, the difficulty is that selection zones have their own + * event handling code which seems to rely on QCP GUI event handling propagation + * which was a realy bad design choice. + */ + } + void setSelectionZonesEditionEnabled(bool value) { for (auto s : m_SelectionZones) { @@ -783,13 +799,22 @@ void VisualizationGraphWidget::mouseMoveEvent(QMouseEvent *event) } else if (event->buttons() == Qt::LeftButton) { - impl->moveGraph(event->pos()); + switch (sqpApp->plotsInteractionMode()) + { + case SqpApplication::PlotsInteractionMode::None: + impl->moveGraph(event->pos()); + break; + case SqpApplication::PlotsInteractionMode::SelectionZones: + + break; + default: + break; + } } else { impl->m_RenderingDelegate->updateTooltip(event); } - event->accept(); QWidget::mouseMoveEvent(event); } @@ -801,7 +826,7 @@ void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event) } else if(impl->isDrawingZoneRect()) { - impl->endDrawingZone(this); + impl->endDrawingZone(); } else { @@ -812,36 +837,44 @@ void VisualizationGraphWidget::mouseReleaseEvent(QMouseEvent *event) void VisualizationGraphWidget::mousePressEvent(QMouseEvent *event) { - if (event->button() == Qt::LeftButton) { - if (event->modifiers() == Qt::ControlModifier) { - } - else if (event->modifiers() == Qt::AltModifier) { - - } - else + if (event->button()==Qt::RightButton) + { + onGraphMenuRequested(event->pos()); + } + else + { + auto selectedZone = impl->selectionZoneAt(event->pos()); + switch (sqpApp->plotsInteractionMode()) { - switch (sqpApp->plotsInteractionMode()) + case SqpApplication::PlotsInteractionMode::DragAndDrop : + break; + case SqpApplication::PlotsInteractionMode::SelectionZones : + impl->setSelectionZonesEditionEnabled(true); + if ((event->modifiers() == Qt::ControlModifier) && (selectedZone != nullptr)) { - case SqpApplication::PlotsInteractionMode::DragAndDrop : - break; - case SqpApplication::PlotsInteractionMode::SelectionZones : - if (!impl->selectionZoneAt(event->pos())) { - impl->startDrawingZone(event->pos(), this); + selectedZone->setAssociatedEditedZones(parentVisualizationWidget()->selectionZoneManager().selectedItems()); + } + else + { + if (!selectedZone) + { + parentVisualizationWidget()->selectionZoneManager().clearSelection(); + impl->startDrawingZone(event->pos()); + } + else + { + parentVisualizationWidget()->selectionZoneManager().select({ selectedZone }); } - break; - case SqpApplication::PlotsInteractionMode::ZoomBox : - impl->startDrawingRect(event->pos()); - break; - default: - setCursor(Qt::ClosedHandCursor); - impl->updateMousePosition(event->pos()); } + break; + case SqpApplication::PlotsInteractionMode::ZoomBox : + impl->startDrawingRect(event->pos()); + break; + default: + setCursor(Qt::ClosedHandCursor); + impl->updateMousePosition(event->pos()); } } - else if (event->button()==Qt::RightButton) - { - onGraphMenuRequested(event->pos()); - } QWidget::mousePressEvent(event); } @@ -1128,7 +1161,7 @@ void VisualizationGraphWidget::onMousePress(QMouseEvent *event) noexcept // Starts a new selection zone auto zoneAtPos = impl->selectionZoneAt(event->pos()); if (!zoneAtPos) { - impl->startDrawingZone(event->pos(), this); + impl->startDrawingZone(event->pos()); } } } @@ -1191,7 +1224,7 @@ void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept } } - impl->endDrawingZone(this); + impl->endDrawingZone(); // Selection / Deselection auto isSelectionZoneMode diff --git a/gui/tests/simple_graph/main.cpp b/gui/tests/simple_graph/main.cpp index 2cad822..8b7baa4 100644 --- a/gui/tests/simple_graph/main.cpp +++ b/gui/tests/simple_graph/main.cpp @@ -29,7 +29,6 @@ ALIAS_TEMPLATE_FUNCTION(isReady, static_cast(qApp)->variableCo while (!isReady(var))\ QCoreApplication::processEvents();\ w.addVariable(var, range);\ - GET_CHILD_WIDGET_FOR_GUI_TESTS(w, plot, QCustomPlot, "widget");\ auto cent = center(&w);