@@ -710,6 +710,37 @@ void NetworkEditor::mouseReleaseEvent(QMouseEvent *event)
710710 QGraphicsView::mouseReleaseEvent (event);
711711}
712712
713+ void NetworkEditor::mouseDoubleClickEvent (QMouseEvent* event)
714+ {
715+ #if 0
716+ if (!search_)
717+ {
718+ search_ = scene_->addWidget(new NetworkSearchWidget(this));
719+ search_->setOpacity(0.9);
720+ }
721+ search_->setPos(mapToScene(event->pos()));
722+ search_->setVisible(true);
723+ #endif
724+ QGraphicsView::mouseDoubleClickEvent (event);
725+ }
726+
727+ void NetworkEditor::hideSearchBox ()
728+ {
729+ if (search_)
730+ search_->setVisible (false );
731+ }
732+
733+ NetworkSearchWidget::NetworkSearchWidget (NetworkEditor* ned)
734+ {
735+ setupUi (this );
736+ connect (closeButton_, SIGNAL (clicked ()), ned, SLOT (hideSearchBox ()));
737+ }
738+
739+ NetworkSearchWidgetProxy::NetworkSearchWidgetProxy (NetworkSearchWidget* nsw)
740+ {
741+ setWidget (nsw);
742+ }
743+
713744ConnectionLine* NetworkEditor::getSingleConnectionSelected ()
714745{
715746 ConnectionLine* connectionSelected = nullptr ;
@@ -832,6 +863,7 @@ ModuleTagsHandle NetworkEditor::dumpModuleTags(ModuleFilter filter) const
832863 tags->tags [mod->getModuleWidget ()->getModuleId ()] = mod->data (TagDataKey).toInt ();
833864 }
834865 }
866+ tags->labels = tagLabelOverrides_;
835867 tags->showTagGroupsOnLoad = showTagGroupsOnFileLoad ();
836868 return tags;
837869}
@@ -906,6 +938,7 @@ void NetworkEditor::updateModuleTags(const ModuleTags& moduleTags)
906938 }
907939 }
908940 setShowTagGroupsOnFileLoad (moduleTags.showTagGroupsOnLoad );
941+ tagLabelOverrides_ = moduleTags.labels ;
909942 if (showTagGroupsOnFileLoad ())
910943 {
911944 tagGroupsActive_ = true ;
@@ -1002,6 +1035,7 @@ void NetworkEditor::removeModuleWidget(const ModuleId& id)
10021035
10031036void NetworkEditor::clear ()
10041037{
1038+ tagLabelOverrides_.clear ();
10051039 ModuleWidget::NetworkClearingScope clearing;
10061040 // auto portSwitch = createDynamicPortDisabler();
10071041 scene_->clear ();
@@ -1391,7 +1425,9 @@ namespace
13911425 class TagGroupBox : public QGraphicsRectItem
13921426 {
13931427 public:
1394- explicit TagGroupBox (const QRectF& rect, NetworkEditor* ned) : QGraphicsRectItem(rect), ned_(ned)
1428+ explicit TagGroupBox (int tagNum, const QRectF& rect, NetworkEditor* ned) : QGraphicsRectItem(rect),
1429+ tagNumber_(tagNum),
1430+ ned_(ned)
13951431 {
13961432 setAcceptHoverEvents (true );
13971433 }
@@ -1409,15 +1445,20 @@ namespace
14091445 virtual void mouseDoubleClickEvent (QGraphicsSceneMouseEvent* event) override
14101446 {
14111447 QMenu menu;
1412- auto action = menu.addAction (" Display in saved network" , ned_, SLOT (saveTagGroupRectInFile ()));
1413- action->setCheckable (true );
1414- action->setChecked (ned_->showTagGroupsOnFileLoad ());
1448+ auto autoDisplay = menu.addAction (" Display in saved network" , ned_, SLOT (saveTagGroupRectInFile ()));
1449+ autoDisplay->setCheckable (true );
1450+ autoDisplay->setChecked (ned_->showTagGroupsOnFileLoad ());
1451+ auto rename = menu.addAction (" Rename in saved network..." , ned_, SLOT (renameTagGroupInFile ()));
1452+ rename->setProperty (" tag" , tagNumber_);
14151453 menu.exec (event->screenPos ());
14161454 QGraphicsRectItem::mouseDoubleClickEvent (event);
14171455 }
14181456 private:
1457+ int tagNumber_;
14191458 NetworkEditor* ned_;
14201459 };
1460+
1461+ const int TagTextKey = 123 ;
14211462}
14221463
14231464void NetworkEditor::saveTagGroupRectInFile ()
@@ -1427,6 +1468,25 @@ void NetworkEditor::saveTagGroupRectInFile()
14271468 Q_EMIT modified ();
14281469}
14291470
1471+ void NetworkEditor::renameTagGroupInFile ()
1472+ {
1473+ auto action = qobject_cast<QAction*>(sender ());
1474+ auto tagNum = action->property (" tag" ).toInt ();
1475+
1476+ bool ok;
1477+ auto text = QInputDialog::getText (this , tr (" Rename tag group" ),
1478+ tr (" Enter new tag group name for this network file:" ), QLineEdit::Normal, checkForOverriddenTagName (tagNum), &ok);
1479+ if (ok && !text.isEmpty ())
1480+ {
1481+ bool changed = tagLabelOverrides_[tagNum] != text.toStdString ();
1482+ tagLabelOverrides_[tagNum] = text.toStdString ();
1483+ if (changed)
1484+ renameTagGroup (tagNum, text);
1485+ }
1486+
1487+ Q_EMIT modified ();
1488+ }
1489+
14301490void NetworkEditor::drawTagGroups ()
14311491{
14321492 if (tagGroupsActive_)
@@ -1458,11 +1518,12 @@ void NetworkEditor::drawTagGroups()
14581518 for (auto rectIter = tagItemRects.constBegin (); rectIter != tagItemRects.constEnd (); ++rectIter)
14591519 {
14601520 auto rectBounds = rectIter.value ().adjusted (-10 , -10 , 10 , 10 );
1461- QPen pen (tagColor_ (rectIter.key ()));
1521+ auto tagNum = rectIter.key ();
1522+ QPen pen (tagColor_ (tagNum));
14621523 pen.setWidth (3 );
14631524 pen.setCapStyle (Qt::RoundCap);
14641525 pen.setJoinStyle (Qt::RoundJoin);
1465- auto rect = new TagGroupBox (rectBounds, this );
1526+ auto rect = new TagGroupBox (tagNum, rectBounds, this );
14661527 rect->setPen (pen);
14671528 scene_->addItem (rect);
14681529 rect->setFlags (QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsSelectable);
@@ -1476,15 +1537,25 @@ void NetworkEditor::drawTagGroups()
14761537 scene_->addItem (fill);
14771538
14781539 static const QFont labelFont (" Courier" , 20 , QFont::Bold);
1479- auto label = scene_->addSimpleText (tagName_ (rectIter.key ()), labelFont);
1540+
1541+ auto label = scene_->addSimpleText (checkForOverriddenTagName (tagNum), labelFont);
14801542 label->setBrush (pen.color ());
1543+ label->setData (TagTextKey, tagNum);
14811544 static const QFontMetrics fm (labelFont);
14821545 auto textWidthInPixels = fm.width (label->text ());
14831546 label->setPos ((rect->rect ().topLeft () + rect->rect ().topRight ()) / 2 + QPointF (-textWidthInPixels / 2 , -30 ));
14841547 }
14851548 }
14861549}
14871550
1551+ QString NetworkEditor::checkForOverriddenTagName (int tag) const
1552+ {
1553+ auto nameOverrideIter = tagLabelOverrides_.find (tag);
1554+ if (nameOverrideIter != tagLabelOverrides_.end () && !nameOverrideIter->second .empty ())
1555+ return QString::fromStdString (nameOverrideIter->second );
1556+ return tagName_ (tag);
1557+ }
1558+
14881559void NetworkEditor::removeTagGroups ()
14891560{
14901561 Q_FOREACH (QGraphicsItem* item, scene_->items ())
@@ -1496,6 +1567,21 @@ void NetworkEditor::removeTagGroups()
14961567 }
14971568}
14981569
1570+ void NetworkEditor::renameTagGroup (int tag, const QString& name)
1571+ {
1572+ Q_FOREACH (QGraphicsItem* item, scene_->items ())
1573+ {
1574+ if (auto rectLabel = dynamic_cast <QGraphicsSimpleTextItem*>(item))
1575+ {
1576+ if (rectLabel->data (TagTextKey).toInt () == tag)
1577+ {
1578+ rectLabel->setText (name);
1579+ return ;
1580+ }
1581+ }
1582+ }
1583+ }
1584+
14991585void NetworkEditor::redrawTagGroups ()
15001586{
15011587 removeTagGroups ();
@@ -1510,6 +1596,7 @@ void NetworkEditor::highlightTaggedItem(int tagValue)
15101596
15111597void NetworkEditor::highlightTaggedItem (QGraphicsItem* item, int tagValue)
15121598{
1599+ qDebug () << " highlightTaggedItem" << tagValue;
15131600 if (tagValue == NoTag)
15141601 {
15151602 item->setGraphicsEffect (blurEffect ());
0 commit comments