Files
ResInsight/ApplicationLibCode/Commands/SummaryPlotCommands/RicToggleAxisAutoZoomFeature.cpp
T
Magne Sjaastad 3284fd200a #14539 Add shared-axis, pinned-range indicators and Auto Zoom command for axis objects
Replace the chain/padlock icon with a simple two-headed-arrow icon
(SharedAxis.svg) for linked time/property axes.

Add a pinned-range project-tree tag shown when an axis range is
user-defined, using the standard gray pinned.svg icon. The tag
refreshes immediately regardless of the code path that changes the
range/auto-zoom state (Zoom All, data source changes, axis linking,
UI edits), and clicking the tag releases the user-defined range so
the axis auto-zooms again.

Add RicToggleAxisAutoZoomFeature, a checkable context-menu command
on Y-axis and time-axis objects that toggles auto-zoom and keeps the
pinned/user-defined-range tag in sync in both directions.

Move axis-specific context-menu entries out of RimContextCommandBuilder
into appendMenuItems() overrides on RimPlotAxisProperties and
RimSummaryTimeAxisProperties, per the project convention of keeping
object-specific menu logic in the object.

Fix RimSummaryPlot::timeAxisSettingsChanged() to actually re-apply
auto-scale to the plot widget when auto-zoom is re-enabled on the
time axis; previously only the property was updated, and no
recompute of the plotted range was triggered.
2026-09-09 12:08:10 +02:00

72 lines
2.9 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RicToggleAxisAutoZoomFeature.h"
#include "RimPlotAxisPropertiesInterface.h"
#include "cafSelectionManagerTools.h"
#include <QAction>
CAF_CMD_SOURCE_INIT( RicToggleAxisAutoZoomFeature, "RicToggleAxisAutoZoomFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicToggleAxisAutoZoomFeature::isCommandEnabled() const
{
auto* axisProperties = caf::firstAncestorOfTypeFromSelectedObject<RimPlotAxisPropertiesInterface>();
return ( axisProperties != nullptr );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleAxisAutoZoomFeature::onActionTriggered( bool isChecked )
{
auto* axisProperties = caf::firstAncestorOfTypeFromSelectedObject<RimPlotAxisPropertiesInterface>();
if ( !axisProperties ) return;
bool enableAutoZoom = !axisProperties->isAutoZoom();
axisProperties->setAutoZoom( enableAutoZoom );
// The range is defined by the user unless auto-zoom is (re-)enabled, matching the behavior of the
// "Set Range Automatically" checkbox in the property editor. This also makes sure the pinned tag
// in the project tree is updated to reflect the new state.
axisProperties->setRangeUserDefined( !enableAutoZoom );
axisProperties->settingsChanged.send();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicToggleAxisAutoZoomFeature::setupActionLook( QAction* actionToSetup )
{
actionToSetup->setText( "Auto Zoom" );
actionToSetup->setIcon( QIcon( ":/ZoomAll.svg" ) );
actionToSetup->setCheckable( true );
auto* axisProperties = caf::firstAncestorOfTypeFromSelectedObject<RimPlotAxisPropertiesInterface>();
if ( axisProperties )
{
actionToSetup->setChecked( axisProperties->isAutoZoom() );
}
}