AppFwk : Assert if two fields or groups with same name is present in PdmuiOrdering for cafPdmUiDefaultObjectEditor

This commit is contained in:
Magne Sjaastad 2016-06-29 12:48:05 +02:00
parent 94efe9b14c
commit 9db44a349a
2 changed files with 52 additions and 1 deletions

View File

@ -127,6 +127,12 @@ void PdmUiDefaultObjectEditor::configureAndUpdateUi(const QString& uiConfigName)
m_newGroupBoxes.clear();
const std::vector<PdmUiItem*>& uiItems = config.uiItems();
{
std::set<QString> fieldKeywordNames;
std::set<QString> groupNames;
recursiveVerifyUniqueNames(uiItems, uiConfigName, &fieldKeywordNames, &groupNames);
}
recursiveSetupFieldsAndGroups(uiItems, m_mainWidget, m_layout, uiConfigName);
@ -352,5 +358,49 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiDefaultObjectEditor::recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames)
{
for (size_t i = 0; i < uiItems.size(); ++i)
{
if (uiItems[i]->isUiGroup())
{
PdmUiGroup* group = static_cast<PdmUiGroup*>(uiItems[i]);
const std::vector<PdmUiItem*>& groupChildren = group->uiItems();
QString groupBoxKey = uiItems[i]->uiName();
if (groupNames->find(groupBoxKey) != groupNames->end())
{
// It is not supported to have two groups with identical names
assert(false);
}
else
{
groupNames->insert(groupBoxKey);
}
recursiveVerifyUniqueNames(groupChildren, uiConfigName, fieldKeywordNames, groupNames);
}
else
{
PdmUiFieldHandle* field = dynamic_cast<PdmUiFieldHandle*>(uiItems[i]);
QString fieldKeyword = field->fieldHandle()->keyword();
if (fieldKeywordNames->find(fieldKeyword) != fieldKeywordNames->end())
{
// It is not supported to have two fields with identical names
assert(false);
}
else
{
fieldKeywordNames->insert(fieldKeyword);
}
}
}
}
} // end namespace caf

View File

@ -65,7 +65,8 @@ protected:
virtual void configureAndUpdateUi(const QString& uiConfigName);
private:
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName );
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
std::map<QString, PdmUiFieldEditorHandle*> m_fieldViews;
std::map<QString, QPointer<QGroupBox> > m_groupBoxes;