From 5ced7e1d2f7c27e077027c55d55ee1610478d48b Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Thu, 10 Oct 2024 11:40:39 +0200 Subject: [PATCH] Add pin icon and rename to Pin Field to Quick Access --- ApplicationExeCode/Resources/ResInsight.qrc | 1 + ApplicationExeCode/Resources/pin.svg | 4 + .../RicAddFieldToQuickAccessFeature.cpp | 29 +++++-- .../RimContextCommandBuilder.cpp | 2 + .../ProjectDataModel/RimFieldReference.cpp | 87 +++++++++++++++++-- .../ProjectDataModel/RimFieldReference.h | 18 ++-- .../RimPinnedFieldCollection.cpp | 6 +- .../UserInterface/RiuDockWidgetTools.cpp | 18 ++++ .../UserInterface/RiuDockWidgetTools.h | 2 + .../UserInterface/RiuMainWindow.cpp | 3 +- 10 files changed, 143 insertions(+), 27 deletions(-) create mode 100644 ApplicationExeCode/Resources/pin.svg diff --git a/ApplicationExeCode/Resources/ResInsight.qrc b/ApplicationExeCode/Resources/ResInsight.qrc index efe7e9278b..87939b1318 100644 --- a/ApplicationExeCode/Resources/ResInsight.qrc +++ b/ApplicationExeCode/Resources/ResInsight.qrc @@ -290,6 +290,7 @@ cloud-and-server.svg Cloud.svg CloudBlobs.svg + pin.svg fs_CellFace.glsl diff --git a/ApplicationExeCode/Resources/pin.svg b/ApplicationExeCode/Resources/pin.svg new file mode 100644 index 0000000000..d18608c5c9 --- /dev/null +++ b/ApplicationExeCode/Resources/pin.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ApplicationLibCode/Commands/ToolCommands/RicAddFieldToQuickAccessFeature.cpp b/ApplicationLibCode/Commands/ToolCommands/RicAddFieldToQuickAccessFeature.cpp index e2351254c6..c0a7184eb0 100644 --- a/ApplicationLibCode/Commands/ToolCommands/RicAddFieldToQuickAccessFeature.cpp +++ b/ApplicationLibCode/Commands/ToolCommands/RicAddFieldToQuickAccessFeature.cpp @@ -18,15 +18,12 @@ #include "RicAddFieldToQuickAccessFeature.h" -/* -#include "RiaApplication.h" +#include "RimFieldReference.h" +#include "RimPinnedFieldCollection.h" -#include "Rim3dOverlayInfoConfig.h" -#include "RimGridView.h" +#include "cafPdmUiPropertyViewDialog.h" -#include "RiuViewer.h" -#include "RiuViewerCommands.h" -*/ +#include "Riu3DMainWindowTools.h" #include @@ -41,6 +38,20 @@ void RicAddFieldToQuickAccessFeature::onActionTriggered( bool isChecked ) if ( objects.empty() ) return; auto firstObject = objects.front(); + + RimFieldReference fieldRef; + fieldRef.setObject( firstObject ); + + caf::PdmUiPropertyViewDialog propertyDialog( Riu3DMainWindowTools::mainWindowWidget(), &fieldRef, "Select Field", "" ); + if ( propertyDialog.exec() == QDialog::Accepted ) + { + auto field = fieldRef.field(); + if ( field ) + { + RimPinnedFieldCollection::instance()->addField( field ); + RimPinnedFieldCollection::instance()->updateAllRequiredEditors(); + } + } } //-------------------------------------------------------------------------------------------------- @@ -48,6 +59,6 @@ void RicAddFieldToQuickAccessFeature::onActionTriggered( bool isChecked ) //-------------------------------------------------------------------------------------------------- void RicAddFieldToQuickAccessFeature::setupActionLook( QAction* actionToSetup ) { - actionToSetup->setText( "Add Field To Quick Access" ); - // actionToSetup->setIcon( QIcon( ":/SummaryEnsemble.svg" ) ); + actionToSetup->setText( "Pin Field To Quick Access" ); + actionToSetup->setIcon( QIcon( ":/pin.svg" ) ); } diff --git a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp index 927648c78b..3eb927ad90 100644 --- a/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimContextCommandBuilder.cpp @@ -1125,6 +1125,8 @@ caf::CmdFeatureMenuBuilder RimContextCommandBuilder::commandsFromSelection() menuBuilder << "RicPasteAsciiDataCurveFeature"; menuBuilder << "RicPasteSummaryCaseFeature"; menuBuilder.addSeparator(); + menuBuilder << "RicAddFieldToQuickAccessFeature"; + menuBuilder.addSeparator(); menuBuilder << "RicCopyReferencesToClipboardFeature"; menuBuilder << "RicLinkViewFeature"; diff --git a/ApplicationLibCode/ProjectDataModel/RimFieldReference.cpp b/ApplicationLibCode/ProjectDataModel/RimFieldReference.cpp index 723a9a0657..bcddbd466e 100644 --- a/ApplicationLibCode/ProjectDataModel/RimFieldReference.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimFieldReference.cpp @@ -31,6 +31,20 @@ RimFieldReference::RimFieldReference() CAF_PDM_InitFieldNoDefault( &m_fieldName, "FieldName", "FieldName" ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFieldReference::setObject( caf::PdmObject* object ) +{ + m_object = object; + + std::vector fieldNames = RimFieldReference::fieldNames( object ); + if ( !fieldNames.empty() ) + { + m_fieldName = fieldNames[0]; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -38,10 +52,29 @@ void RimFieldReference::setField( caf::PdmFieldHandle* field ) { if ( !field ) return; - auto ownerObject = field->ownerObject(); + auto ownerObject = dynamic_cast( field->ownerObject() ); if ( !ownerObject ) return; - setField( field->ownerObject(), field->keyword() ); + setField( ownerObject, field->keyword() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimFieldReference::fieldNames( caf::PdmObject* object ) +{ + std::vector names; + + if ( object ) + { + auto allFields = object->fields(); + for ( auto field : allFields ) + { + names.push_back( field->keyword() ); + } + } + + return names; } //-------------------------------------------------------------------------------------------------- @@ -49,12 +82,44 @@ void RimFieldReference::setField( caf::PdmFieldHandle* field ) //-------------------------------------------------------------------------------------------------- void RimFieldReference::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) { - if ( field() ) +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QList RimFieldReference::calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) +{ + QList options; + + if ( fieldNeedingOptions == &m_fieldName ) { - uiOrdering.add( field() ); + auto fieldNames = RimFieldReference::fieldNames( m_object ); + for ( const auto& name : fieldNames ) + { + options.push_back( caf::PdmOptionItemInfo( name, name ) ); + } + } + else if ( fieldNeedingOptions == &m_object ) + { + if ( m_objectsForSelection.empty() ) + { + if ( m_object ) + { + QString text = m_object()->uiName(); + options.push_back( caf::PdmOptionItemInfo( text, m_object ) ); + } + } + else + { + for ( auto obj : m_objectsForSelection ) + { + QString text = obj->uiName(); + options.push_back( caf::PdmOptionItemInfo( text, obj ) ); + } + } } - uiOrdering.skipRemainingFields(); + return options; } //-------------------------------------------------------------------------------------------------- @@ -70,7 +135,7 @@ caf::PdmFieldHandle* RimFieldReference::field() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::PdmObjectHandle* RimFieldReference::object() const +caf::PdmObject* RimFieldReference::object() const { return m_object; } @@ -78,7 +143,15 @@ caf::PdmObjectHandle* RimFieldReference::object() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RimFieldReference::setField( caf::PdmObjectHandle* object, const QString& fieldName ) +void RimFieldReference::setObjectsForSelection( const std::vector& objectsForSelection ) +{ + m_objectsForSelection = objectsForSelection; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimFieldReference::setField( caf::PdmObject* object, const QString& fieldName ) { m_object = object; m_fieldName = fieldName; diff --git a/ApplicationLibCode/ProjectDataModel/RimFieldReference.h b/ApplicationLibCode/ProjectDataModel/RimFieldReference.h index 5435686686..e03e457dbf 100644 --- a/ApplicationLibCode/ProjectDataModel/RimFieldReference.h +++ b/ApplicationLibCode/ProjectDataModel/RimFieldReference.h @@ -37,17 +37,25 @@ class RimFieldReference : public caf::PdmObject public: RimFieldReference(); + void setObject( caf::PdmObject* object ); + void setField( caf::PdmFieldHandle* field ); caf::PdmFieldHandle* field() const; - caf::PdmObjectHandle* object() const; + caf::PdmObject* object() const; + void setObjectsForSelection( const std::vector& objectsForSelection ); private: - void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; + QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; - void setField( caf::PdmObjectHandle* object, const QString& fieldName ); + void setField( caf::PdmObject* object, const QString& fieldName ); + + static std::vector fieldNames( caf::PdmObject* object ); private: - caf::PdmPtrField m_object; - caf::PdmField m_fieldName; + caf::PdmPtrField m_object; + caf::PdmField m_fieldName; + + std::vector m_objectsForSelection; }; diff --git a/ApplicationLibCode/ProjectDataModel/RimPinnedFieldCollection.cpp b/ApplicationLibCode/ProjectDataModel/RimPinnedFieldCollection.cpp index d12d60d24a..4542933259 100644 --- a/ApplicationLibCode/ProjectDataModel/RimPinnedFieldCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/RimPinnedFieldCollection.cpp @@ -131,11 +131,7 @@ void RimPinnedFieldCollection::defineUiOrdering( QString uiConfigName, caf::PdmU for ( auto fieldRef : fieldRefs ) { group->add( fieldRef->field() ); - } - - if ( !fieldRefs.empty() ) - { - group->add( fieldRefs.front()->selectObjectButton(), { .newRow = false } ); + group->add( fieldRef->selectObjectButton(), { .newRow = false } ); } } } diff --git a/ApplicationLibCode/UserInterface/RiuDockWidgetTools.cpp b/ApplicationLibCode/UserInterface/RiuDockWidgetTools.cpp index af8c8d3314..3a3a477b53 100644 --- a/ApplicationLibCode/UserInterface/RiuDockWidgetTools.cpp +++ b/ApplicationLibCode/UserInterface/RiuDockWidgetTools.cpp @@ -139,6 +139,14 @@ QString RiuDockWidgetTools::mainWindowUndoStackName() return "dockUndoStack_mainWindow"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiuDockWidgetTools::mainWindowQuickAccessName() +{ + return "dockQuickAccess_mainWindow"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -147,6 +155,14 @@ QString RiuDockWidgetTools::plotMainWindowPlotManagerName() return "dockSummaryPlotManager"; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RiuDockWidgetTools::plotWindowQuickAccessName() +{ + return "dockQuickAccess_plotWindow"; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -383,6 +399,8 @@ QIcon RiuDockWidgetTools::dockIcon( const QString dockWidgetName ) return QIcon( ":/graph.svg" ); else if ( dockWidgetName == plotMainWindowCloudTreeName() ) return QIcon( ":/Cloud.svg" ); + else if ( dockWidgetName == plotWindowQuickAccessName() || dockWidgetName == mainWindowQuickAccessName() ) + return QIcon( ":/pin.svg" ); return QIcon( ":/view.svg" ); } diff --git a/ApplicationLibCode/UserInterface/RiuDockWidgetTools.h b/ApplicationLibCode/UserInterface/RiuDockWidgetTools.h index 40e8d95e89..55423cac9c 100644 --- a/ApplicationLibCode/UserInterface/RiuDockWidgetTools.h +++ b/ApplicationLibCode/UserInterface/RiuDockWidgetTools.h @@ -58,6 +58,7 @@ public: static QString mainWindowMessagesName(); static QString mainWindowMohrsCirclePlotName(); static QString mainWindowUndoStackName(); + static QString mainWindowQuickAccessName(); static QString mainWindowProjectTreeName(); static QString mainWindowDataSourceTreeName(); @@ -74,6 +75,7 @@ public: static QString plotMainWindowMessagesName(); static QString plotMainWindowUndoStackName(); static QString plotMainWindowPlotManagerName(); + static QString plotWindowQuickAccessName(); static QString dockState3DEclipseName(); static QString dockState3DGeoMechName(); diff --git a/ApplicationLibCode/UserInterface/RiuMainWindow.cpp b/ApplicationLibCode/UserInterface/RiuMainWindow.cpp index 1209845d3f..a7566e6eab 100644 --- a/ApplicationLibCode/UserInterface/RiuMainWindow.cpp +++ b/ApplicationLibCode/UserInterface/RiuMainWindow.cpp @@ -822,7 +822,8 @@ void RiuMainWindow::createDockPanels() } { - auto dockWidget = RiuDockWidgetTools::createDockWidget( "Quick Access", "Quick Access", dockManager() ); + auto dockWidget = + RiuDockWidgetTools::createDockWidget( "Quick Access", RiuDockWidgetTools::mainWindowQuickAccessName(), dockManager() ); m_pinnedFieldView = new caf::PdmUiPropertyView( dockWidget ); dockWidget->setWidget( m_pinnedFieldView );