mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Make it possible to remove fields
This commit is contained in:
@@ -37,6 +37,12 @@ RimFieldQuickAccess::RimFieldQuickAccess()
|
||||
CAF_PDM_InitField( &m_selectObjectButton, "SelectObject", false, "...", ":/Bullet.png", "Select Object in Property Editor" );
|
||||
m_selectObjectButton.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
|
||||
m_selectObjectButton.xmlCapability()->disableIO();
|
||||
|
||||
CAF_PDM_InitField( &m_removeObjectButton, "RemoveObject", false, "...", ":/Erase.svg", "Remove Item" );
|
||||
m_removeObjectButton.uiCapability()->setUiEditorTypeName( caf::PdmUiToolButtonEditor::uiEditorTypeName() );
|
||||
m_removeObjectButton.xmlCapability()->disableIO();
|
||||
|
||||
m_toBeDeleted = false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -59,7 +65,8 @@ void RimFieldQuickAccess::defineUiOrdering( QString uiConfigName, caf::PdmUiOrde
|
||||
uiOrdering.add( m_fieldReference()->field() );
|
||||
}
|
||||
|
||||
uiOrdering.add( &m_selectObjectButton );
|
||||
uiOrdering.add( &m_selectObjectButton, { .newRow = false } );
|
||||
uiOrdering.add( &m_removeObjectButton, { .newRow = false } );
|
||||
|
||||
uiOrdering.skipRemainingFields();
|
||||
}
|
||||
@@ -77,9 +84,9 @@ caf::PdmFieldHandle* RimFieldQuickAccess::field() const
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmFieldHandle* RimFieldQuickAccess::selectObjectButton()
|
||||
bool RimFieldQuickAccess::toBeDeleted() const
|
||||
{
|
||||
return &m_selectObjectButton;
|
||||
return m_toBeDeleted;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -99,4 +106,11 @@ void RimFieldQuickAccess::fieldChangedByUi( const caf::PdmFieldHandle* changedFi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( changedField == &m_removeObjectButton )
|
||||
{
|
||||
m_removeObjectButton = false;
|
||||
|
||||
m_toBeDeleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
void setField( caf::PdmFieldHandle* field );
|
||||
caf::PdmFieldHandle* field() const;
|
||||
|
||||
caf::PdmFieldHandle* selectObjectButton();
|
||||
bool toBeDeleted() const;
|
||||
|
||||
private:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
@@ -51,4 +51,6 @@ private:
|
||||
caf::PdmChildField<RimFieldReference*> m_fieldReference;
|
||||
|
||||
caf::PdmField<bool> m_selectObjectButton;
|
||||
caf::PdmField<bool> m_removeObjectButton;
|
||||
bool m_toBeDeleted;
|
||||
};
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RimPinnedFieldCollection.h"
|
||||
|
||||
#include "RiaApplication.h"
|
||||
|
||||
#include "RimFieldQuickAccess.h"
|
||||
#include "RimProject.h"
|
||||
|
||||
@@ -78,8 +80,7 @@ void RimPinnedFieldCollection::removeField( caf::PdmFieldHandle* field )
|
||||
{
|
||||
if ( field == fieldRef->field() )
|
||||
{
|
||||
m_fieldReferences.removeChild( fieldRef );
|
||||
delete fieldRef;
|
||||
m_toBeDeleted.insert( fieldRef );
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -90,9 +91,13 @@ void RimPinnedFieldCollection::removeField( caf::PdmFieldHandle* field )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPinnedFieldCollection::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering )
|
||||
{
|
||||
std::map<caf::PdmObjectHandle*, std::vector<RimFieldQuickAccess*>> fieldMap;
|
||||
auto activeView = RiaApplication::instance()->activeGridView();
|
||||
if ( !activeView ) return;
|
||||
|
||||
deleteMarkedObjects();
|
||||
|
||||
std::vector<RimFieldQuickAccess*> fieldsForView;
|
||||
|
||||
// Group fields by object
|
||||
for ( auto fieldRef : m_fieldReferences )
|
||||
{
|
||||
if ( !fieldRef ) continue;
|
||||
@@ -101,37 +106,55 @@ void RimPinnedFieldCollection::defineUiOrdering( QString uiConfigName, caf::PdmU
|
||||
{
|
||||
if ( auto ownerObject = field->ownerObject() )
|
||||
{
|
||||
fieldMap[ownerObject].push_back( fieldRef );
|
||||
auto view = ownerObject->firstAncestorOrThisOfType<RimGridView>();
|
||||
if ( view != activeView )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fieldsForView.push_back( fieldRef );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int groupId = 1;
|
||||
if ( fieldsForView.empty() ) return;
|
||||
|
||||
// Create ui ordering with a group containing fields for each object
|
||||
for ( auto& pair : fieldMap )
|
||||
QString groupName;
|
||||
auto uiCapability = activeView->uiCapability();
|
||||
if ( uiCapability->userDescriptionField() && uiCapability->userDescriptionField()->uiCapability() )
|
||||
{
|
||||
auto object = pair.first;
|
||||
auto fieldRefs = pair.second;
|
||||
groupName = uiCapability->userDescriptionField()->uiCapability()->uiValue().toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
groupName = "Group ";
|
||||
}
|
||||
|
||||
QString groupName;
|
||||
auto uiCapability = object->uiCapability();
|
||||
if ( uiCapability->userDescriptionField() && uiCapability->userDescriptionField()->uiCapability() )
|
||||
{
|
||||
groupName = uiCapability->userDescriptionField()->uiCapability()->uiValue().toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
groupName = "Group " + QString::number( groupId );
|
||||
}
|
||||
auto group = uiOrdering.addNewGroup( groupName );
|
||||
|
||||
auto group = uiOrdering.addNewGroup( groupName );
|
||||
groupId++;
|
||||
|
||||
for ( auto fieldRef : fieldRefs )
|
||||
{
|
||||
group->add( fieldRef->field() );
|
||||
group->add( fieldRef->selectObjectButton(), { .newRow = false } );
|
||||
}
|
||||
for ( auto fieldRef : fieldsForView )
|
||||
{
|
||||
fieldRef->uiOrdering( uiConfigName, *group );
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimPinnedFieldCollection::deleteMarkedObjects()
|
||||
{
|
||||
for ( auto fieldRef : m_fieldReferences )
|
||||
{
|
||||
if ( fieldRef->toBeDeleted() )
|
||||
{
|
||||
m_toBeDeleted.insert( fieldRef );
|
||||
}
|
||||
}
|
||||
|
||||
for ( auto fieldRef : m_toBeDeleted )
|
||||
{
|
||||
m_fieldReferences.removeChild( fieldRef );
|
||||
delete fieldRef;
|
||||
}
|
||||
m_toBeDeleted.clear();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ public:
|
||||
private:
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
|
||||
void deleteMarkedObjects();
|
||||
|
||||
private:
|
||||
caf::PdmChildArrayField<RimFieldQuickAccess*> m_fieldReferences;
|
||||
|
||||
std::set<RimFieldQuickAccess*> m_toBeDeleted;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user