Summary context menu cleanup and fixes (#9165)

* Make summary plot ctx menu items show up for the plot you right-click on, not the one selected in the project tree.
This commit is contained in:
jonjenssen 2022-08-08 13:34:27 +02:00 committed by GitHub
parent eedebd71a5
commit c3f538c1dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 296 additions and 58 deletions

View File

@ -20,6 +20,7 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@ -44,6 +45,7 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicExportObjectAndFieldKeywordsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicSaveProjectNoGlobalPathsFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowClassNamesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowPlotDataCtxFeature.cpp
) )
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 "RicShowPlotDataCtxFeature.h"
CAF_CMD_SOURCE_INIT( RicShowPlotDataCtxFeature, "RicShowPlotDataCtxFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicShowPlotDataCtxFeature::isCommandEnabled()
{
return true;
}

View File

@ -0,0 +1,32 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicShowPlotDataFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicShowPlotDataCtxFeature : public RicShowPlotDataFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
};

View File

@ -25,6 +25,7 @@
#include "RimGridCrossPlot.h" #include "RimGridCrossPlot.h"
#include "RimGridCrossPlotCurve.h" #include "RimGridCrossPlotCurve.h"
#include "RimPlot.h"
#include "RimProject.h" #include "RimProject.h"
#include "RimSummaryCrossPlot.h" #include "RimSummaryCrossPlot.h"
#include "RimSummaryPlot.h" #include "RimSummaryPlot.h"
@ -173,30 +174,26 @@ bool RicShowPlotDataFeature::isCommandEnabled()
return true; return true;
} }
auto selectedSummaryPlots = caf::selectedObjectsByType<RimSummaryPlot*>(); std::vector<RimPlot*> selection;
if ( selectedSummaryPlots.size() > 0 ) getSelection( selection );
int validPlots = 0;
for ( auto plot : selection )
{ {
for ( auto c : selectedSummaryPlots ) if ( dynamic_cast<RimSummaryCrossPlot*>( plot ) )
{ {
if ( dynamic_cast<RimSummaryCrossPlot*>( c ) ) return false;
{
return false;
}
} }
return true; if ( dynamic_cast<RimSummaryPlot*>( plot ) != nullptr ||
( dynamic_cast<RimWellLogPlot*>( plot ) != nullptr || dynamic_cast<RimGridCrossPlot*>( plot ) != nullptr ||
dynamic_cast<RimVfpPlot*>( plot ) != nullptr ) )
{
validPlots++;
}
} }
return ( validPlots > 0 );
auto wellLogPlots = caf::selectedObjectsByType<RimWellLogPlot*>();
if ( wellLogPlots.size() > 0 ) return true;
auto gridCrossPlots = caf::selectedObjectsByType<RimGridCrossPlot*>();
if ( gridCrossPlots.size() > 0 ) return true;
auto vfpPlots = caf::selectedObjectsByType<RimVfpPlot*>();
if ( vfpPlots.size() > 0 ) return true;
return false;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -220,10 +217,45 @@ void RicShowPlotDataFeature::onActionTriggered( bool isChecked )
this->disableModelChangeContribution(); this->disableModelChangeContribution();
std::vector<RimSummaryPlot*> selectedSummaryPlots = caf::selectedObjectsByType<RimSummaryPlot*>(); std::vector<RimPlot*> selection;
std::vector<RimWellLogPlot*> wellLogPlots = caf::selectedObjectsByType<RimWellLogPlot*>(); getSelection( selection );
std::vector<RimGridCrossPlot*> crossPlots = caf::selectedObjectsByType<RimGridCrossPlot*>();
std::vector<RimVfpPlot*> vfpPlots = caf::selectedObjectsByType<RimVfpPlot*>(); std::vector<RimSummaryPlot*> selectedSummaryPlots;
std::vector<RimWellLogPlot*> wellLogPlots;
std::vector<RimGridCrossPlot*> crossPlots;
std::vector<RimVfpPlot*> vfpPlots;
for ( auto plot : selection )
{
auto sumPlot = dynamic_cast<RimSummaryPlot*>( plot );
if ( sumPlot )
{
selectedSummaryPlots.push_back( sumPlot );
continue;
}
auto wellPlot = dynamic_cast<RimWellLogPlot*>( plot );
if ( wellPlot )
{
wellLogPlots.push_back( wellPlot );
continue;
}
auto xPlot = dynamic_cast<RimGridCrossPlot*>( plot );
if ( xPlot )
{
crossPlots.push_back( xPlot );
continue;
}
auto vfpPlot = dynamic_cast<RimVfpPlot*>( plot );
if ( vfpPlot )
{
vfpPlots.push_back( vfpPlot );
continue;
}
}
if ( selectedSummaryPlots.empty() && wellLogPlots.empty() && crossPlots.empty() && vfpPlots.empty() ) if ( selectedSummaryPlots.empty() && wellLogPlots.empty() && crossPlots.empty() && vfpPlots.empty() )
{ {
CVF_ASSERT( false ); CVF_ASSERT( false );
@ -303,3 +335,24 @@ void RicShowPlotDataFeature::showTextWindow( const QString& title, const QString
plotwindow->addToTemporaryWidgets( textWiget ); plotwindow->addToTemporaryWidgets( textWiget );
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RicShowPlotDataFeature::getSelection( std::vector<RimPlot*>& selection )
{
if ( sender() )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<void*>() )
{
RimPlot* plot = static_cast<RimPlot*>( userData.value<void*>() );
if ( plot ) selection.push_back( plot );
}
}
if ( selection.empty() )
{
caf::SelectionManager::instance()->objectsByType( &selection );
}
}

View File

@ -21,8 +21,10 @@
#include "cafCmdFeature.h" #include "cafCmdFeature.h"
#include <functional> #include <functional>
#include <vector>
class RiuTabbedTextProvider; class RiuTabbedTextProvider;
class RimPlot;
//================================================================================================== //==================================================================================================
/// ///
@ -36,6 +38,9 @@ protected:
void onActionTriggered( bool isChecked ) override; void onActionTriggered( bool isChecked ) override;
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
private:
void getSelection( std::vector<RimPlot*>& selection );
public: public:
static void showTabbedTextWindow( RiuTabbedTextProvider* textProvider ); static void showTabbedTextWindow( RiuTabbedTextProvider* textProvider );
static void showTextWindow( const QString& title, const QString& text ); static void showTextWindow( const QString& title, const QString& text );

View File

@ -46,7 +46,7 @@ bool RicSplitMultiPlotFeature::isCommandEnabled()
return ( ( plot->summaryCurves().size() > 1 ) || ( plot->curveSets().size() > 1 ) ); return ( ( plot->summaryCurves().size() > 1 ) || ( plot->curveSets().size() > 1 ) );
} }
return false; return true;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -44,6 +44,8 @@ set(SOURCE_GROUP_HEADER_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.h ${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubPlotCtxFeature.h
${CMAKE_CURRENT_LIST_DIR}/RicEditSummaryPlotCtxFeature.h
) )
set(SOURCE_GROUP_SOURCE_FILES set(SOURCE_GROUP_SOURCE_FILES
@ -92,6 +94,8 @@ set(SOURCE_GROUP_SOURCE_FILES
${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicNewPlotAxisPropertiesFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicShowSummaryPlotManagerFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.cpp ${CMAKE_CURRENT_LIST_DIR}/RicPasteSummaryMultiPlotFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicDeleteSubPlotCtxFeature.cpp
${CMAKE_CURRENT_LIST_DIR}/RicEditSummaryPlotCtxFeature.cpp
) )
list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES}) list(APPEND COMMAND_CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 "RicDeleteSubPlotCtxFeature.h"
CAF_CMD_SOURCE_INIT( RicDeleteSubPlotCtxFeature, "RicDeleteSubPlotCtxFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicDeleteSubPlotCtxFeature::isCommandEnabled()
{
return true;
}

View File

@ -0,0 +1,32 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "WellLogCommands/RicDeleteSubPlotFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicDeleteSubPlotCtxFeature : public RicDeleteSubPlotFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
};

View File

@ -0,0 +1,29 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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 "RicEditSummaryPlotCtxFeature.h"
CAF_CMD_SOURCE_INIT( RicEditSummaryPlotCtxFeature, "RicEditSummaryPlotCtxFeature" );
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RicEditSummaryPlotCtxFeature::isCommandEnabled()
{
return true;
}

View File

@ -0,0 +1,32 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2022 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RicEditSummaryPlotFeature.h"
//==================================================================================================
///
//==================================================================================================
class RicEditSummaryPlotCtxFeature : public RicEditSummaryPlotFeature
{
CAF_CMD_HEADER_INIT;
protected:
bool isCommandEnabled() override;
};

View File

@ -133,6 +133,16 @@ RimSummaryPlot* RicEditSummaryPlotFeature::selectedSummaryPlot()
{ {
RimSummaryPlot* sumPlot = nullptr; RimSummaryPlot* sumPlot = nullptr;
if ( sender() )
{
QVariant userData = this->userData();
if ( !userData.isNull() && userData.canConvert<void*>() )
{
RimSummaryPlot* plot = static_cast<RimSummaryPlot*>( userData.value<void*>() );
if ( plot ) return plot;
}
}
caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() ); caf::PdmObject* selObj = dynamic_cast<caf::PdmObject*>( caf::SelectionManager::instance()->selectedItem() );
if ( selObj ) if ( selObj )
{ {

View File

@ -43,5 +43,5 @@ protected:
void setupActionLook( QAction* actionToSetup ) override; void setupActionLook( QAction* actionToSetup ) override;
private: private:
static RimSummaryPlot* selectedSummaryPlot(); RimSummaryPlot* selectedSummaryPlot();
}; };

View File

@ -44,29 +44,10 @@ bool RicDeleteSubPlotFeature::isCommandEnabled()
{ {
if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return false; if ( RicWellLogPlotCurveFeatureImpl::parentWellAllocationPlot() ) return false;
std::vector<caf::PdmObject*> selection; std::vector<RimPlot*> selection;
caf::SelectionManager::instance()->objectsByType( &selection ); getSelection( selection );
if ( selection.size() > 0 ) return ( selection.size() > 0 );
{
if ( dynamic_cast<RimMultiPlot*>( selection.front() ) ) return false;
size_t plotsSelected = 0;
for ( caf::PdmObject* object : selection )
{
RimMultiPlot* multiPlot = nullptr;
RimWellLogPlot* wellLogPlot = nullptr;
object->firstAncestorOrThisOfType( multiPlot );
object->firstAncestorOrThisOfType( wellLogPlot );
if ( dynamic_cast<RimPlotWindow*>( object ) && ( multiPlot || wellLogPlot ) )
{
plotsSelected++;
}
}
return plotsSelected == selection.size();
}
return false;
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------

View File

@ -59,7 +59,17 @@ void RiuSummaryPlot::showContextMenu( QPoint pos )
QMenu menu; QMenu menu;
caf::CmdFeatureMenuBuilder menuBuilder; caf::CmdFeatureMenuBuilder menuBuilder;
menuBuilder << "RicShowPlotDataFeature"; RimSummaryPlot* plot = dynamic_cast<RimSummaryPlot*>( plotWidget()->plotDefinition() );
if ( plot )
{
QVariant plotVariant( QVariant::fromValue( static_cast<void*>( plot ) ) );
menuBuilder.addCmdFeatureWithUserData( "RicShowPlotDataCtxFeature", "Show Plot Data", plotVariant );
menuBuilder.addCmdFeatureWithUserData( "RicEditSummaryPlotCtxFeature", "Edit Plot", plotVariant );
menuBuilder.addCmdFeatureWithUserData( "RicSplitMultiPlotFeature", "Split into Multiple Plots", plotVariant );
menuBuilder.addSeparator();
menuBuilder.addCmdFeatureWithUserData( "RicDeleteSubPlotCtxFeature", "Delete Plot", plotVariant );
}
menuBuilder.addSeparator();
double distanceFromClick = std::numeric_limits<double>::infinity(); double distanceFromClick = std::numeric_limits<double>::infinity();
@ -192,16 +202,6 @@ void RiuSummaryPlot::showContextMenu( QPoint pos )
} }
} }
menuBuilder.addSeparator();
RimSummaryPlot* plot = dynamic_cast<RimSummaryPlot*>( plotWidget()->plotDefinition() );
if ( plot )
{
QVariant plotVariant( QVariant::fromValue( static_cast<void*>( plot ) ) );
menuBuilder.addCmdFeatureWithUserData( "RicSplitMultiPlotFeature", "Split into Multiple Plots", plotVariant );
menuBuilder.addCmdFeatureWithUserData( "RicDeleteSubPlotFeature", "Delete Plot", plotVariant );
}
menuBuilder.appendToMenu( &menu ); menuBuilder.appendToMenu( &menu );
if ( !menu.actions().empty() ) if ( !menu.actions().empty() )