mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-25 22:50:25 -05:00
Summary plot: select plot before building the right-click context menu
Select the summary plot as the current item before any menu commands are created, so every command in the context menu operates on that plot. This is the root fix for plot-level commands (New Analysis Plot, correlation plots, etc.) that derive their enablement from the selected plot: previously the selection could be left on an ensemble realization's summary case, disabling them. Because the plot is now selected, the Show Plot Data / Edit Plot / Split / Delete commands resolve the plot from the selection, so passing it as user data is no longer needed. The RicShowPlotDataCtxFeature and RicEditSummaryPlotCtxFeature subclasses existed only to force isCommandEnabled to true for the context menu; they are now obsolete and removed, and the menu uses the base RicShowPlotData and RicEditSummaryPlot features directly. Also highlight the curve under the cursor before showing the menu, giving the same visual feedback as a left-click. Separate highlighting from selection: extract the visual-only part of selectClosestPlotItem into applyHighlightForClosestItem, shared by selectClosestPlotItem (left-click: highlight + select) and the new highlightClosestPlotItem (highlight only). The context menu uses the highlight-only path, so it does not change the selection. Add highlightClosestPlotItemAtPosition that takes widget coordinates and converts them to canvas coordinates internally, so the caller does not depend on qwt headers.
This commit is contained in:
1 parent
8606fa002e
commit
c6591eac95
9 files changed
+108
-150
No files matched your search
@@ -995,6 +995,81 @@ std::pair<RiuPlotCurve*, int> RiuQwtPlotWidget::findClosestCurve( const QPoint&
|
||||
return std::make_pair( plotCurve, closestCurvePoint );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::highlightClosestPlotItemAtPosition( const QPoint& widgetPos )
|
||||
{
|
||||
// highlightClosestPlotItem expects canvas coordinates, while widgetPos is given in widget coordinates.
|
||||
QPoint canvasPos = qwtPlot()->canvas()->mapFromGlobal( mapToGlobal( widgetPos ) );
|
||||
highlightClosestPlotItem( canvasPos );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Applies the visual highlight for the closest plot item, without changing the project tree / selection manager
|
||||
/// selection. Shared by selectClosestPlotItem (which additionally updates the selection) and highlightClosestPlotItem.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::applyHighlightForClosestItem( QwtPlotItem* closestItem, const std::vector<RimPlotCurve*>& curvesToHighlight )
|
||||
{
|
||||
bool updateCurveOrder = false;
|
||||
resetPlotItemHighlighting( updateCurveOrder );
|
||||
|
||||
if ( !curvesToHighlight.empty() )
|
||||
{
|
||||
if ( RimSummaryEnsembleTools::isEnsembleCurve( curvesToHighlight.front() ) )
|
||||
{
|
||||
auto summaryCases = RimSummaryEnsembleTools::summaryCasesFromCurves( curvesToHighlight );
|
||||
RimSummaryEnsembleTools::highlightCurvesForSummaryCases( summaryCases );
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightCurvesUpdateOrder( curvesToHighlight );
|
||||
}
|
||||
}
|
||||
else if ( closestItem )
|
||||
{
|
||||
// Currently used from the matrix plot to highlight the selected cell in the matrix plot, see
|
||||
// RimCorrelationMatrixPlot::createMatrix()
|
||||
highlightPlotShapeItems( { closestItem } );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuQwtPlotWidget::highlightClosestPlotItem( const QPoint& pos )
|
||||
{
|
||||
QwtPlotItem* closestItem = nullptr;
|
||||
double distanceFromClick = std::numeric_limits<double>::infinity();
|
||||
int closestCurvePoint = -1;
|
||||
|
||||
findClosestPlotItem( pos, &closestItem, &closestCurvePoint, &distanceFromClick );
|
||||
|
||||
if ( closestItem )
|
||||
{
|
||||
RimPlotCurve* closestCurve = nullptr;
|
||||
if ( auto curve = dynamic_cast<RiuPlotCurve*>( closestItem ) )
|
||||
{
|
||||
closestCurve = curve->ownerRimCurve();
|
||||
}
|
||||
|
||||
std::vector<RimPlotCurve*> curvesToHighlight;
|
||||
if ( closestCurve && distanceFromClick < 100 )
|
||||
{
|
||||
curvesToHighlight.push_back( closestCurve );
|
||||
}
|
||||
|
||||
applyHighlightForClosestItem( closestItem, curvesToHighlight );
|
||||
}
|
||||
else
|
||||
{
|
||||
RimSummaryEnsembleTools::resetHighlightAllPlots();
|
||||
}
|
||||
|
||||
// Always do a replot, as the reset operation also requires replot
|
||||
replot();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -1042,28 +1117,13 @@ void RiuQwtPlotWidget::selectClosestPlotItem( const QPoint& pos, bool toggleItem
|
||||
}
|
||||
}
|
||||
|
||||
bool updateCurveOrder = false;
|
||||
resetPlotItemHighlighting( updateCurveOrder );
|
||||
if ( !curvesToSelect.empty() && RimSummaryEnsembleTools::isEnsembleCurve( curvesToSelect.front() ) )
|
||||
{
|
||||
auto summaryCases = RimSummaryEnsembleTools::summaryCasesFromCurves( curvesToSelect );
|
||||
RimSummaryEnsembleTools::selectSummaryCasesInProjectTree( summaryCases );
|
||||
}
|
||||
|
||||
if ( !curvesToSelect.empty() )
|
||||
{
|
||||
if ( RimSummaryEnsembleTools::isEnsembleCurve( curvesToSelect.front() ) )
|
||||
{
|
||||
auto summaryCases = RimSummaryEnsembleTools::summaryCasesFromCurves( curvesToSelect );
|
||||
RimSummaryEnsembleTools::selectSummaryCasesInProjectTree( summaryCases );
|
||||
RimSummaryEnsembleTools::highlightCurvesForSummaryCases( summaryCases );
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightCurvesUpdateOrder( curvesToSelect );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Currently used from the matrix plot to highlight the selected cell in the matrix plot, see
|
||||
// RimCorrelationMatrixPlot::createMatrix()
|
||||
highlightPlotShapeItems( { closestItem } );
|
||||
}
|
||||
applyHighlightForClosestItem( closestItem, curvesToSelect );
|
||||
|
||||
auto plotItem = std::make_shared<RiuQwtPlotItem>( closestItem );
|
||||
emit plotItemSelected( plotItem, toggleItemInSelection, distanceFromClick < 10 ? closestCurvePoint : -1 );
|
||||
|
||||
Reference in new issue
Block a user