From 296dac48d33f0ab6c8130dfd712e4f7f29c0876e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 4 Nov 2016 08:03:22 +0100 Subject: [PATCH] Removed a call to uiValue() that was not preceeded with valueOptions(). Understood that this is an inherent problem with those two methods, and made a comment on that. --- .../cafPdmUiCore/cafInternalPdmUiFieldCapability.inl | 11 ++++++++++- .../cafUserInterface/cafPdmUiDefaultObjectEditor.cpp | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiFieldCapability.inl b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiFieldCapability.inl index 6bca85c6d8..145fc9f703 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiFieldCapability.inl +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafInternalPdmUiFieldCapability.inl @@ -102,6 +102,12 @@ void caf::PdmFieldUiCap::setValueFromUiEditor(const QVariant& uiValue //-------------------------------------------------------------------------------------------------- /// Extracts a QVariant representation of the data in the field to be used in the UI. /// +/// Note : You have to call valueOptions() before this method to make sure that the m_optionEntryCache is updated and valid !!! +/// We should find a way to enforce this, but JJS and MSJ could not think of a way to catch the situation +/// that would always be valid. Could invalidate cache when all editors are removed. That would help. +/// It is not considered to be healthy to always call valueOptions() from this method either -> double calls to valueOptions() +/// The solution might actually be to merge the two ino one method, making uiValues and valueOptions directly connected. +/// /// Note : For fields with a none-empty m_optionEntryCache list, the returned QVariant contains the /// _indexes_ to the selected options rather than the actual values, if they can be found. /// @@ -122,7 +128,10 @@ QVariant caf::PdmFieldUiCap::uiValue() const { if (isAutoAddingOptionFromValue() && indexesToFoundOptions.size() != static_cast(uiBasedQVariant.toList().size())) { - assert(false); // Did not find all the field values among the options available, even though we should. The "core" data type in the field is probably not supported by QVariant::toString() + assert(false); // Did not find all the field values among the options available, even though we should. + // Reasons might be: + // The "core" data type in the field is probably not supported by QVariant::toString() + // You forgot to call valueOptions() before the call to uiValue(). } else { diff --git a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp index 1ea0d72fe9..9b542389c6 100644 --- a/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp +++ b/Fwk/AppFwk/cafUserInterface/cafPdmUiDefaultObjectEditor.cpp @@ -272,7 +272,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector

uiValue().type() != QVariant::List) + if (field->toUiBasedQVariant().type() != QVariant::List) { bool useOptionsOnly = true; QList options = field->valueOptions( &useOptionsOnly);