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:
parent
2ea84bdb63
commit
66cec70718
@ -66,43 +66,9 @@ CmdUiCommandSystemImpl::CmdUiCommandSystemImpl()
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void CmdUiCommandSystemImpl::fieldChangedCommand(PdmFieldHandle* editorField, const QVariant& newUiValue)
|
void CmdUiCommandSystemImpl::fieldChangedCommand( const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue)
|
||||||
{
|
{
|
||||||
std::vector<PdmFieldHandle*> fieldsToUpdate;
|
if ( fieldsToUpdate.empty() ) return;
|
||||||
fieldsToUpdate.push_back(editorField);
|
|
||||||
|
|
||||||
// For current selection, find all fields with same keyword
|
|
||||||
{
|
|
||||||
std::vector<PdmUiItem*> items;
|
|
||||||
SelectionManager::instance()->selectedItems(items, SelectionManager::CURRENT);
|
|
||||||
|
|
||||||
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
|
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<CmdExecuteCommand*> commands;
|
std::vector<CmdExecuteCommand*> commands;
|
||||||
|
|
||||||
@ -136,7 +102,7 @@ void CmdUiCommandSystemImpl::fieldChangedCommand(PdmFieldHandle* editorField, co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj(editorField->ownerObject());
|
caf::PdmUiObjectHandle* uiOwnerObjectHandle = uiObj(fieldsToUpdate[0]->ownerObject());
|
||||||
if (uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoForFieldChanged())
|
if (uiOwnerObjectHandle && !uiOwnerObjectHandle->useUndoRedoForFieldChanged())
|
||||||
{
|
{
|
||||||
// Temporarily disable undo framework as requested by the PdmUiObjectHandle
|
// Temporarily disable undo framework as requested by the PdmUiObjectHandle
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "cafInternalPdmUiCommandSystemInterface.h"
|
#include "cafInternalPdmUiCommandSystemInterface.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
@ -50,7 +50,7 @@ class CmdUiCommandSystemImpl : public PdmUiCommandSystemInterface
|
|||||||
public:
|
public:
|
||||||
CmdUiCommandSystemImpl();
|
CmdUiCommandSystemImpl();
|
||||||
|
|
||||||
virtual void fieldChangedCommand(PdmFieldHandle* field, const QVariant& newUiValue);
|
virtual void fieldChangedCommand(const std::vector<PdmFieldHandle*>& fieldsToUpdate, const QVariant& newUiValue);
|
||||||
virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu);
|
virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu);
|
||||||
|
|
||||||
bool isUndoEnabled();
|
bool isUndoEnabled();
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class QVariant;
|
class QVariant;
|
||||||
class QMenu;
|
class QMenu;
|
||||||
class QString;
|
class QString;
|
||||||
@ -50,7 +52,7 @@ class PdmUiFieldHandle;
|
|||||||
class PdmUiCommandSystemInterface
|
class PdmUiCommandSystemInterface
|
||||||
{
|
{
|
||||||
public:
|
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;
|
virtual void populateMenuWithDefaultCommands(const QString& uiConfigName, QMenu* menu) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "cafPdmObjectHandle.h"
|
#include "cafPdmObjectHandle.h"
|
||||||
#include "cafPdmUiFieldHandle.h"
|
#include "cafPdmUiFieldHandle.h"
|
||||||
#include "cafPdmUiObjectHandle.h"
|
#include "cafPdmUiObjectHandle.h"
|
||||||
|
#include "cafSelectionManager.h"
|
||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
@ -83,13 +84,56 @@ void PdmUiCommandSystemProxy::setUiValueToField(PdmUiFieldHandle* uiFieldHandle,
|
|||||||
{
|
{
|
||||||
if (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)
|
if (m_commandInterface)
|
||||||
{
|
{
|
||||||
m_commandInterface->fieldChangedCommand(uiFieldHandle->fieldHandle(), newUiValue);
|
m_commandInterface->fieldChangedCommand(fieldsToUpdate, newUiValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uiFieldHandle->setValueFromUiEditor(newUiValue);
|
for (auto fieldHandle : fieldsToUpdate)
|
||||||
|
{
|
||||||
|
fieldHandle->uiCapability()->setValueFromUiEditor(newUiValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user