@@ -882,7 +882,10 @@ void NetworkEditor::updateModuleTags(const ModuleTags& moduleTags)
882882 }
883883 setShowTagGroupsOnFileLoad (moduleTags.showTagGroupsOnLoad );
884884 if (showTagGroupsOnFileLoad ())
885+ {
886+ tagGroupsActive_ = true ;
885887 drawTagGroups ();
888+ }
886889}
887890
888891void NetworkEditor::updateConnectionNotes (const ConnectionNotes& notes)
@@ -1342,10 +1345,12 @@ void NetworkEditor::tagLayer(bool active, int tag)
13421345 }
13431346 if (ShowGroups == tag)
13441347 {
1348+ tagGroupsActive_ = true ;
13451349 redrawTagGroups ();
13461350 }
13471351 if (HideGroups == tag)
13481352 {
1353+ tagGroupsActive_ = false ;
13491354 removeTagGroups ();
13501355 }
13511356}
@@ -1388,60 +1393,64 @@ void NetworkEditor::saveTagGroupRectInFile()
13881393{
13891394 auto action = qobject_cast<QAction*>(sender ());
13901395 setShowTagGroupsOnFileLoad (action->isChecked ());
1396+ Q_EMIT modified ();
13911397}
13921398
13931399void NetworkEditor::drawTagGroups ()
13941400{
1395- QMap<int ,QRectF> tagItemRects;
1396-
1397- Q_FOREACH (QGraphicsItem* item, scene_->items ())
1401+ if (tagGroupsActive_)
13981402 {
1399- if (dynamic_cast <ModuleProxyWidget*>(item))
1400- {
1401- const auto itemTag = item->data (TagDataKey).toInt ();
1403+ QMap<int , QRectF> tagItemRects;
14021404
1403- if (itemTag != NoTag)
1405+ Q_FOREACH (QGraphicsItem* item, scene_->items ())
1406+ {
1407+ if (dynamic_cast <ModuleProxyWidget*>(item))
14041408 {
1405- auto r = item->boundingRect ();
1406- r.translate (item->pos ());
1407- if (!tagItemRects.contains (itemTag))
1408- {
1409- tagItemRects.insert (itemTag, r);
1410- }
1411- else
1409+ const auto itemTag = item->data (TagDataKey).toInt ();
1410+
1411+ if (itemTag != NoTag)
14121412 {
1413- tagItemRects[itemTag] = tagItemRects[itemTag].united (r);
1413+ auto r = item->boundingRect ();
1414+ r.translate (item->pos ());
1415+ if (!tagItemRects.contains (itemTag))
1416+ {
1417+ tagItemRects.insert (itemTag, r);
1418+ }
1419+ else
1420+ {
1421+ tagItemRects[itemTag] = tagItemRects[itemTag].united (r);
1422+ }
14141423 }
14151424 }
14161425 }
1417- }
14181426
1419- for (auto rectIter = tagItemRects.constBegin (); rectIter != tagItemRects.constEnd (); ++rectIter)
1420- {
1421- auto rectBounds = rectIter.value ().adjusted (-10 , -10 , 10 , 10 );
1422- QPen pen (tagColor_ (rectIter.key ()));
1423- pen.setWidth (3 );
1424- pen.setCapStyle (Qt::RoundCap);
1425- pen.setJoinStyle (Qt::RoundJoin);
1426- auto rect = new TagGroupBox (rectBounds, this );
1427- rect->setPen (pen);
1428- scene_->addItem (rect);
1429- rect->setFlags (QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsSelectable);
1430- rect->setZValue (-100000 );
1431-
1432- auto fill = new QGraphicsRectItem (rectBounds);
1433- auto c = pen.color ();
1434- c.setAlphaF (0.15 );
1435- fill->setBrush (c);
1436- fill->setZValue (-100000 );
1437- scene_->addItem (fill);
1438-
1439- static const QFont labelFont (" Courier" , 20 , QFont::Bold);
1440- auto label = scene_->addSimpleText (tagName_ (rectIter.key ()), labelFont);
1441- label->setBrush (pen.color ());
1442- static const QFontMetrics fm (labelFont);
1443- auto textWidthInPixels = fm.width (label->text ());
1444- label->setPos ((rect->rect ().topLeft () + rect->rect ().topRight ()) / 2 + QPointF (-textWidthInPixels/2 , -30 ));
1427+ for (auto rectIter = tagItemRects.constBegin (); rectIter != tagItemRects.constEnd (); ++rectIter)
1428+ {
1429+ auto rectBounds = rectIter.value ().adjusted (-10 , -10 , 10 , 10 );
1430+ QPen pen (tagColor_ (rectIter.key ()));
1431+ pen.setWidth (3 );
1432+ pen.setCapStyle (Qt::RoundCap);
1433+ pen.setJoinStyle (Qt::RoundJoin);
1434+ auto rect = new TagGroupBox (rectBounds, this );
1435+ rect->setPen (pen);
1436+ scene_->addItem (rect);
1437+ rect->setFlags (QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsSelectable);
1438+ rect->setZValue (-100000 );
1439+
1440+ auto fill = new QGraphicsRectItem (rectBounds);
1441+ auto c = pen.color ();
1442+ c.setAlphaF (0.15 );
1443+ fill->setBrush (c);
1444+ fill->setZValue (-100000 );
1445+ scene_->addItem (fill);
1446+
1447+ static const QFont labelFont (" Courier" , 20 , QFont::Bold);
1448+ auto label = scene_->addSimpleText (tagName_ (rectIter.key ()), labelFont);
1449+ label->setBrush (pen.color ());
1450+ static const QFontMetrics fm (labelFont);
1451+ auto textWidthInPixels = fm.width (label->text ());
1452+ label->setPos ((rect->rect ().topLeft () + rect->rect ().topRight ()) / 2 + QPointF (-textWidthInPixels / 2 , -30 ));
1453+ }
14451454 }
14461455}
14471456
0 commit comments