Skip to content
Snippets Groups Projects
Commit 98d07545 authored by David Li's avatar David Li Committed by Pospelov, Gennady
Browse files

making user names (Instrument, Multilayer) unique

parent ee1ee15a
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,16 @@ QString ParameterizedItem::displayName() const
int index = mp_parent->getCopyNumberOfChild(this);
if (index >= 0 && modelType() != Constants::PropertyType &&
modelType() != Constants::GroupItemType) {
return m_display_name + QString::number(index);
QString new_name = m_display_name + QString::number(index);
for (auto other : parent()->childItems()) {
if (other != this) {
if (isRegisteredProperty(P_NAME) && other->itemName() == new_name) {
++ index;
new_name = m_display_name + QString::number(index);
}
}
}
return new_name;
}
}
return m_display_name;
......@@ -278,9 +287,9 @@ PropertyAttribute &ParameterizedItem::registerProperty(const QString &name, cons
"ParameterizedItem::registerProperty() -> Error. Already existing property " + name);
ParameterizedItem *property = ItemFactory::createItem(Constants::PropertyType);
property->setValue(variant);
property->setDisplayName(name);
insertChildItem(-1, property);
property->setValue(variant);
m_property_attribute[name] = attribute;
return m_property_attribute[name];
}
......
......@@ -47,7 +47,7 @@ public:
//! set data in the given column, return true when successful, notify model if present
//! we only support one role
bool setData(int column, const QVariant &data);
virtual bool setData(int column, const QVariant &data);
//! return variant stored in data column
QVariant value() const;
......
......@@ -20,3 +20,20 @@ PropertyItem::PropertyItem()
{
}
bool PropertyItem::setData(int column, const QVariant &data)
{
if (displayName() == ParameterizedItem::P_NAME) {
if (data.toString().isEmpty())
return false;
if (ParameterizedItem *item = parent()) {
if (ParameterizedItem *item_parent = item->parent()) {
// forbid setting duplicate name
if (item_parent->getChildByName(data.toString())) {
return false;
}
}
}
}
return ParameterizedItem::setData(column, data);
}
......@@ -23,6 +23,8 @@ class BA_CORE_API_ PropertyItem : public ParameterizedItem
Q_OBJECT
public:
PropertyItem();
bool setData(int column, const QVariant &data);
};
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment