caf: notifyFieldChange now uses the QVariant content data when checking for equality

This commit is contained in:
Jacob Støren 2019-08-23 13:18:18 +02:00 committed by Gaute Lindkvist
parent 11e73a76fc
commit 2784f5ce11
4 changed files with 23 additions and 2 deletions

View File

@ -22,6 +22,8 @@ public:
QVariant toUiBasedQVariant() const override;
private:
bool isQVariantDataEqual(const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant) const override;
mutable QList<PdmOptionItemInfo> m_optionEntryCache;
private:

View File

@ -247,6 +247,15 @@ QVariant caf::PdmFieldUiCap<FieldType>::toUiBasedQVariant() const
return PdmUiFieldSpecialization<typename FieldType::FieldDataType>::convert(m_field->value());
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template < typename FieldType>
bool caf::PdmFieldUiCap<FieldType>::isQVariantDataEqual(const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant) const
{
return PdmUiFieldSpecialization<typename FieldType::FieldDataType>::isDataElementEqual(oldUiBasedQVariant, newUiBasedQVariant);
}
} // End of namespace caf

View File

@ -52,9 +52,8 @@ QList<caf::PdmOptionItemInfo> PdmUiFieldHandle::valueOptions(bool* useOptionsOnl
//--------------------------------------------------------------------------------------------------
void PdmUiFieldHandle::notifyFieldChanged(const QVariant& oldFieldValue, const QVariant& newFieldValue)
{
// Todo : Should use a virtual version of isElementEqual. The variant != operation will not work on user types
if (oldFieldValue != newFieldValue)
if (!this->isQVariantDataEqual( oldFieldValue, newFieldValue))
{
PdmFieldHandle* fieldHandle = this->fieldHandle();
CAF_ASSERT(fieldHandle && fieldHandle->ownerObject());
@ -126,6 +125,15 @@ void PdmUiFieldHandle::setAutoAddingOptionFromValue(bool isAddingValue)
//--------------------------------------------------------------------------------------------------
void PdmUiFieldHandle::setValueFromUiEditor(const QVariant& uiValue) {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmUiFieldHandle::isQVariantDataEqual(const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant) const
{
CAF_ASSERT(false);
return false;
}
//--------------------------------------------------------------------------------------------------
/// Implementation of uiCapability() defined in cafPdmFieldHandle.h
//--------------------------------------------------------------------------------------------------

View File

@ -31,6 +31,8 @@ private:
friend class PdmUiCommandSystemProxy;
friend class CmdFieldChangeExec;
virtual void setValueFromUiEditor(const QVariant& uiValue);
// This is needed to handle custom types in QVariants since operator == between QVariant does not work when they use custom types.
virtual bool isQVariantDataEqual(const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant) const;
private:
PdmFieldHandle* m_owner;