mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
AppFwk: Support field changed on multiple objects in general.
Not only inside the command framework on CURRENT selection
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
class QVariant;
|
||||
class QMenu;
|
||||
class QString;
|
||||
@@ -50,7 +52,7 @@ class PdmUiFieldHandle;
|
||||
class PdmUiCommandSystemInterface
|
||||
{
|
||||
public:
|
||||
virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue) = 0;
|
||||
virtual void fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue) = 0;
|
||||
virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmUiFieldHandle.h"
|
||||
#include "cafPdmUiObjectHandle.h"
|
||||
#include "cafSelectionManager.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@@ -83,13 +84,56 @@ void PdmUiCommandSystemProxy::setUiValueToField(PdmUiFieldHandle* uiFieldHandle,
|
||||
{
|
||||
if (uiFieldHandle)
|
||||
{
|
||||
// Handle editing multiple objects when several objects are selected
|
||||
PdmFieldHandle* editorField = uiFieldHandle->fieldHandle();
|
||||
std::vector<PdmFieldHandle*> fieldsToUpdate;
|
||||
fieldsToUpdate.push_back(editorField);
|
||||
|
||||
// For current selection, find all fields with same keyword
|
||||
{
|
||||
std::vector<PdmUiItem*> items;
|
||||
SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT);
|
||||
SelectionManager::instance()->selectedItems(items, SelectionManager::APPLICATION_GLOBAL);
|
||||
|
||||
for (size_t i = 0; i < items.size(); i++)
|
||||
{
|
||||
PdmObjectHandle* objectHandle = dynamic_cast<PdmObjectHandle*>(items[i]);
|
||||
if (objectHandle)
|
||||
{
|
||||
// An object is selected, find field with same keyword as the current field being edited
|
||||
PdmFieldHandle* fieldHandle = objectHandle->findField(editorField->keyword());
|
||||
if (fieldHandle && fieldHandle != editorField)
|
||||
{
|
||||
fieldsToUpdate.push_back(fieldHandle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Todo Remove when dust has settled. Selection manager is not supposed to select single fields
|
||||
// A field is selected, check if keywords are identical
|
||||
PdmUiFieldHandle* uiFieldHandle = dynamic_cast<PdmUiFieldHandle*>(items[i]);
|
||||
if (uiFieldHandle)
|
||||
{
|
||||
PdmFieldHandle* field = uiFieldHandle->fieldHandle();
|
||||
if (field && field != editorField && field->keyword() == editorField->keyword())
|
||||
{
|
||||
fieldsToUpdate.push_back(field);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_commandInterface)
|
||||
{
|
||||
m_commandInterface->fieldChangedCommand(uiFieldHandle->fieldHandle(), newUiValue);
|
||||
m_commandInterface->fieldChangedCommand(fieldsToUpdate, newUiValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiFieldHandle->setValueFromUiEditor(newUiValue);
|
||||
for (auto fieldHandle : fieldsToUpdate)
|
||||
{
|
||||
fieldHandle->uiCapability()->setValueFromUiEditor(newUiValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user