2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmUiFieldHandle.h"
|
2017-03-08 08:19:51 +01:00
|
|
|
|
|
|
|
|
#include "cafAssert.h"
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmFieldHandle.h"
|
2017-04-19 22:25:31 +02:00
|
|
|
#include "cafPdmUiModelChangeDetector.h"
|
2015-07-29 14:19:43 +02:00
|
|
|
#include "cafPdmUiObjectHandle.h"
|
2019-05-03 15:46:56 +02:00
|
|
|
#include "cafPdmUiEditorHandle.h"
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
|
{
|
2018-08-16 21:42:52 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
PdmUiFieldHandle::PdmUiFieldHandle(PdmFieldHandle* owner, bool giveOwnership)
|
|
|
|
|
: m_isAutoAddingOptionFromValue(true)
|
|
|
|
|
{
|
|
|
|
|
m_owner = owner;
|
|
|
|
|
owner->addCapability(this, giveOwnership);
|
|
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2018-08-16 21:42:52 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
PdmUiFieldHandle::~PdmUiFieldHandle() {}
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-08-16 21:42:52 +02:00
|
|
|
///
|
2015-07-29 14:19:43 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-08-16 21:42:52 +02:00
|
|
|
caf::PdmFieldHandle* PdmUiFieldHandle::fieldHandle()
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
2018-08-16 21:42:52 +02:00
|
|
|
return m_owner;
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-08-16 21:42:52 +02:00
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QVariant PdmUiFieldHandle::uiValue() const
|
|
|
|
|
{
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2018-08-20 08:56:35 +02:00
|
|
|
QList<caf::PdmOptionItemInfo> PdmUiFieldHandle::valueOptions(bool* useOptionsOnly) const
|
2018-08-16 21:42:52 +02:00
|
|
|
{
|
|
|
|
|
return QList<PdmOptionItemInfo>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
2015-07-29 14:19:43 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiFieldHandle::notifyFieldChanged(const QVariant& oldFieldValue, const QVariant& newFieldValue)
|
|
|
|
|
{
|
2018-06-29 16:21:54 +02:00
|
|
|
|
2019-08-23 13:18:18 +02:00
|
|
|
if (!this->isQVariantDataEqual( oldFieldValue, newFieldValue))
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
|
|
|
|
PdmFieldHandle* fieldHandle = this->fieldHandle();
|
2017-03-08 08:19:51 +01:00
|
|
|
CAF_ASSERT(fieldHandle && fieldHandle->ownerObject());
|
2015-07-29 14:19:43 +02:00
|
|
|
|
2019-04-10 10:57:18 +02:00
|
|
|
PdmObjectHandle* ownerObjectHandle = fieldHandle->ownerObject();
|
|
|
|
|
|
|
|
|
|
{
|
2019-05-03 15:46:56 +02:00
|
|
|
bool noOwnerObject = true;
|
|
|
|
|
|
|
|
|
|
// Object editors
|
|
|
|
|
|
2019-04-10 10:57:18 +02:00
|
|
|
PdmUiObjectHandle* uiObjHandle = uiObj(ownerObjectHandle);
|
|
|
|
|
if (uiObjHandle)
|
|
|
|
|
{
|
|
|
|
|
uiObjHandle->fieldChangedByUi(fieldHandle, oldFieldValue, newFieldValue);
|
|
|
|
|
uiObjHandle->updateConnectedEditors();
|
|
|
|
|
|
2019-05-03 15:46:56 +02:00
|
|
|
noOwnerObject = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Field editors
|
|
|
|
|
|
|
|
|
|
for (const auto& editorForThisField : m_editors)
|
|
|
|
|
{
|
|
|
|
|
PdmUiEditorHandle* editorContainingThisField = editorForThisField->topMostContainingEditor();
|
|
|
|
|
|
|
|
|
|
bool editorContainingThisFieldIsNotUpdated = !uiObjHandle->hasEditor(editorContainingThisField);
|
|
|
|
|
|
|
|
|
|
if (noOwnerObject || editorContainingThisFieldIsNotUpdated)
|
|
|
|
|
{
|
|
|
|
|
editorContainingThisField->updateUi();
|
|
|
|
|
}
|
2019-04-10 10:57:18 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ownerObjectHandle->parentField() && ownerObjectHandle->parentField()->ownerObject())
|
2015-07-29 14:19:43 +02:00
|
|
|
{
|
2019-04-10 10:57:18 +02:00
|
|
|
PdmUiObjectHandle* uiObjHandle = uiObj(ownerObjectHandle->parentField()->ownerObject());
|
|
|
|
|
if (uiObjHandle)
|
|
|
|
|
{
|
|
|
|
|
uiObjHandle->childFieldChangedByUi(ownerObjectHandle->parentField());
|
|
|
|
|
|
|
|
|
|
// If updateConnectedEditors() is required, this has to be called in childFieldChangedByUi()
|
|
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
|
|
|
|
|
2017-04-20 10:17:05 +02:00
|
|
|
PdmUiModelChangeDetector::instance()->setModelChanged();
|
2015-07-29 14:19:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 21:42:52 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool PdmUiFieldHandle::isAutoAddingOptionFromValue() const
|
|
|
|
|
{
|
|
|
|
|
return m_isAutoAddingOptionFromValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiFieldHandle::setAutoAddingOptionFromValue(bool isAddingValue)
|
|
|
|
|
{
|
|
|
|
|
m_isAutoAddingOptionFromValue = isAddingValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiFieldHandle::setValueFromUiEditor(const QVariant& uiValue) {}
|
|
|
|
|
|
2019-08-23 13:18:18 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
bool PdmUiFieldHandle::isQVariantDataEqual(const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant) const
|
|
|
|
|
{
|
|
|
|
|
CAF_ASSERT(false);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-05 12:34:07 +02:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
/// Implementation of uiCapability() defined in cafPdmFieldHandle.h
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
PdmUiFieldHandle* PdmFieldHandle::uiCapability()
|
|
|
|
|
{
|
2015-10-23 15:21:23 +02:00
|
|
|
PdmUiFieldHandle* uiField = capability<PdmUiFieldHandle>();
|
2017-03-08 08:19:51 +01:00
|
|
|
CAF_ASSERT(uiField);
|
2015-08-05 12:34:07 +02:00
|
|
|
|
2015-10-23 15:21:23 +02:00
|
|
|
return uiField;
|
2015-08-05 12:34:07 +02:00
|
|
|
}
|
2015-07-29 14:19:43 +02:00
|
|
|
|
|
|
|
|
} // End of namespace caf
|