mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-03 12:16:45 -05:00
Count qwt axes when removing a plot axis
This commit is contained in:
1 parent
d3ce3146fd
commit
cdfc10b833
3 files changed
+44
-12
No files matched your search
@@ -13,6 +13,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicCreatePolygonFeature-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicNewCellIndexFilterFeature-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicExportScheduleFeature-Test.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RiuQwtPlotWidget-Test.cpp
|
||||
)
|
||||
|
||||
list(APPEND SOURCE_FEATURETEST_FILES ${SOURCE_GROUP_SOURCE_FILES})
|
||||
@@ -0,0 +1,40 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2026 Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RiuPlotAxis.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Pruning must keep the axis mapping in sync with the axes owned by qwt. A stale mapping makes
|
||||
/// QwtPlot::axisScaleDraw() return null, which crashed enableAxisNumberLabels().
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST( RiuQwtPlotWidget, PruneAxesKeepsAxisMappingValid )
|
||||
{
|
||||
RiuQwtPlotWidget plotWidget( nullptr );
|
||||
|
||||
plotWidget.pruneAxes( {} );
|
||||
plotWidget.ensureAxisIsCreated( RiuPlotAxis( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, 1 ) );
|
||||
plotWidget.pruneAxes( {} );
|
||||
|
||||
plotWidget.enableAxis( RiuPlotAxis::defaultLeft(), true );
|
||||
EXPECT_TRUE( plotWidget.axisEnabled( RiuPlotAxis::defaultLeft() ) );
|
||||
|
||||
plotWidget.enableAxisNumberLabels( RiuPlotAxis::defaultLeft(), true );
|
||||
}
|
||||
@@ -1689,27 +1689,18 @@ void RiuQwtPlotWidget::onMouseMoveEvent( QMouseEvent* event )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::moveAxis( RiuPlotAxis oldAxis, RiuPlotAxis newAxis )
|
||||
{
|
||||
auto countAxis = [this]( RiaDefines::PlotAxis axis )
|
||||
{
|
||||
int count = 0;
|
||||
for ( auto [plotAxis, qwtMapping] : m_axisMapping )
|
||||
{
|
||||
if ( plotAxis.axis() == axis ) count++;
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
auto isLastItem = [this]( RiuPlotAxis plotAxis, int count )
|
||||
{
|
||||
auto qwtAxis = toQwtPlotAxis( plotAxis );
|
||||
return qwtAxis.id == ( count - 1 );
|
||||
};
|
||||
|
||||
auto removeAxis = [this, countAxis, isLastItem]( RiuPlotAxis plotAxis )
|
||||
auto removeAxis = [this, isLastItem]( RiuPlotAxis plotAxis )
|
||||
{
|
||||
auto qwtAxisPos = RiuQwtPlotTools::toQwtPlotAxisEnum( plotAxis.axis() );
|
||||
|
||||
int count = countAxis( plotAxis.axis() );
|
||||
// Count from qwt, not the mapping. Qwt keeps at least one axis per side, also when unmapped
|
||||
int count = m_plot->axesCount( qwtAxisPos );
|
||||
|
||||
bool isLast = isLastItem( plotAxis, count );
|
||||
if ( isLast )
|
||||
|
||||
Reference in new issue
Block a user