@@ -832,6 +832,7 @@ ModuleTagsHandle NetworkEditor::dumpModuleTags(ModuleFilter filter) const
832832 tags->tags [mod->getModuleWidget ()->getModuleId ()] = mod->data (TagDataKey).toInt ();
833833 }
834834 }
835+ tags->labels = tagLabelOverrides_;
835836 tags->showTagGroupsOnLoad = showTagGroupsOnFileLoad ();
836837 return tags;
837838}
@@ -906,6 +907,7 @@ void NetworkEditor::updateModuleTags(const ModuleTags& moduleTags)
906907 }
907908 }
908909 setShowTagGroupsOnFileLoad (moduleTags.showTagGroupsOnLoad );
910+ tagLabelOverrides_ = moduleTags.labels ;
909911 if (showTagGroupsOnFileLoad ())
910912 {
911913 tagGroupsActive_ = true ;
@@ -1002,6 +1004,7 @@ void NetworkEditor::removeModuleWidget(const ModuleId& id)
10021004
10031005void NetworkEditor::clear ()
10041006{
1007+ tagLabelOverrides_.clear ();
10051008 ModuleWidget::NetworkClearingScope clearing;
10061009 // auto portSwitch = createDynamicPortDisabler();
10071010 scene_->clear ();
@@ -1423,6 +1426,8 @@ namespace
14231426 int tagNumber_;
14241427 NetworkEditor* ned_;
14251428 };
1429+
1430+ const int TagTextKey = 123 ;
14261431}
14271432
14281433void NetworkEditor::saveTagGroupRectInFile ()
@@ -1439,13 +1444,15 @@ void NetworkEditor::renameTagGroupInFile()
14391444
14401445 bool ok;
14411446 auto text = QInputDialog::getText (this , tr (" Rename tag group" ),
1442- tr (" Enter new tag group name for this network file:" ), QLineEdit::Normal, tagName_ (tagNum), &ok);
1447+ tr (" Enter new tag group name for this network file:" ), QLineEdit::Normal, checkForOverriddenTagName (tagNum), &ok);
14431448 if (ok && !text.isEmpty ())
14441449 {
1445- qDebug () << " rename tag group" << tagNum << " to" << text;
1450+ bool changed = tagLabelOverrides_[tagNum] != text.toStdString ();
1451+ tagLabelOverrides_[tagNum] = text.toStdString ();
1452+ if (changed)
1453+ renameTagGroup (tagNum, text);
14461454 }
14471455
1448-
14491456 Q_EMIT modified ();
14501457}
14511458
@@ -1499,15 +1506,25 @@ void NetworkEditor::drawTagGroups()
14991506 scene_->addItem (fill);
15001507
15011508 static const QFont labelFont (" Courier" , 20 , QFont::Bold);
1502- auto label = scene_->addSimpleText (tagName_ (tagNum), labelFont);
1509+
1510+ auto label = scene_->addSimpleText (checkForOverriddenTagName (tagNum), labelFont);
15031511 label->setBrush (pen.color ());
1512+ label->setData (TagTextKey, tagNum);
15041513 static const QFontMetrics fm (labelFont);
15051514 auto textWidthInPixels = fm.width (label->text ());
15061515 label->setPos ((rect->rect ().topLeft () + rect->rect ().topRight ()) / 2 + QPointF (-textWidthInPixels / 2 , -30 ));
15071516 }
15081517 }
15091518}
15101519
1520+ QString NetworkEditor::checkForOverriddenTagName (int tag) const
1521+ {
1522+ auto nameOverrideIter = tagLabelOverrides_.find (tag);
1523+ if (nameOverrideIter != tagLabelOverrides_.end () && !nameOverrideIter->second .empty ())
1524+ return QString::fromStdString (nameOverrideIter->second );
1525+ return tagName_ (tag);
1526+ }
1527+
15111528void NetworkEditor::removeTagGroups ()
15121529{
15131530 Q_FOREACH (QGraphicsItem* item, scene_->items ())
@@ -1519,6 +1536,21 @@ void NetworkEditor::removeTagGroups()
15191536 }
15201537}
15211538
1539+ void NetworkEditor::renameTagGroup (int tag, const QString& name)
1540+ {
1541+ Q_FOREACH (QGraphicsItem* item, scene_->items ())
1542+ {
1543+ if (auto rectLabel = dynamic_cast <QGraphicsSimpleTextItem*>(item))
1544+ {
1545+ if (rectLabel->data (TagTextKey).toInt () == tag)
1546+ {
1547+ rectLabel->setText (name);
1548+ return ;
1549+ }
1550+ }
1551+ }
1552+ }
1553+
15221554void NetworkEditor::redrawTagGroups ()
15231555{
15241556 removeTagGroups ();
0 commit comments