Skip to content

Commit ee4f528

Browse files
committed
Rename tag group menu item
1 parent 8101d34 commit ee4f528

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/Interface/Application/NetworkEditor.cc

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,9 @@ namespace
13911391
class TagGroupBox : public QGraphicsRectItem
13921392
{
13931393
public:
1394-
explicit TagGroupBox(const QRectF& rect, NetworkEditor* ned) : QGraphicsRectItem(rect), ned_(ned)
1394+
explicit TagGroupBox(int tagNum, const QRectF& rect, NetworkEditor* ned) : QGraphicsRectItem(rect),
1395+
tagNumber_(tagNum),
1396+
ned_(ned)
13951397
{
13961398
setAcceptHoverEvents(true);
13971399
}
@@ -1409,13 +1411,16 @@ namespace
14091411
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent* event) override
14101412
{
14111413
QMenu menu;
1412-
auto action = menu.addAction("Display in saved network", ned_, SLOT(saveTagGroupRectInFile()));
1413-
action->setCheckable(true);
1414-
action->setChecked(ned_->showTagGroupsOnFileLoad());
1414+
auto autoDisplay = menu.addAction("Display in saved network", ned_, SLOT(saveTagGroupRectInFile()));
1415+
autoDisplay->setCheckable(true);
1416+
autoDisplay->setChecked(ned_->showTagGroupsOnFileLoad());
1417+
auto rename = menu.addAction("Rename in saved network...", ned_, SLOT(renameTagGroupInFile()));
1418+
rename->setProperty("tag", tagNumber_);
14151419
menu.exec(event->screenPos());
14161420
QGraphicsRectItem::mouseDoubleClickEvent(event);
14171421
}
14181422
private:
1423+
int tagNumber_;
14191424
NetworkEditor* ned_;
14201425
};
14211426
}
@@ -1427,6 +1432,23 @@ void NetworkEditor::saveTagGroupRectInFile()
14271432
Q_EMIT modified();
14281433
}
14291434

1435+
void NetworkEditor::renameTagGroupInFile()
1436+
{
1437+
auto action = qobject_cast<QAction*>(sender());
1438+
auto tagNum = action->property("tag").toInt();
1439+
1440+
bool ok;
1441+
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);
1443+
if (ok && !text.isEmpty())
1444+
{
1445+
qDebug() << "rename tag group" << tagNum << "to" << text;
1446+
}
1447+
1448+
1449+
Q_EMIT modified();
1450+
}
1451+
14301452
void NetworkEditor::drawTagGroups()
14311453
{
14321454
if (tagGroupsActive_)
@@ -1458,11 +1480,12 @@ void NetworkEditor::drawTagGroups()
14581480
for (auto rectIter = tagItemRects.constBegin(); rectIter != tagItemRects.constEnd(); ++rectIter)
14591481
{
14601482
auto rectBounds = rectIter.value().adjusted(-10, -10, 10, 10);
1461-
QPen pen(tagColor_(rectIter.key()));
1483+
auto tagNum = rectIter.key();
1484+
QPen pen(tagColor_(tagNum));
14621485
pen.setWidth(3);
14631486
pen.setCapStyle(Qt::RoundCap);
14641487
pen.setJoinStyle(Qt::RoundJoin);
1465-
auto rect = new TagGroupBox(rectBounds, this);
1488+
auto rect = new TagGroupBox(tagNum, rectBounds, this);
14661489
rect->setPen(pen);
14671490
scene_->addItem(rect);
14681491
rect->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsSelectable);
@@ -1476,7 +1499,7 @@ void NetworkEditor::drawTagGroups()
14761499
scene_->addItem(fill);
14771500

14781501
static const QFont labelFont("Courier", 20, QFont::Bold);
1479-
auto label = scene_->addSimpleText(tagName_(rectIter.key()), labelFont);
1502+
auto label = scene_->addSimpleText(tagName_(tagNum), labelFont);
14801503
label->setBrush(pen.color());
14811504
static const QFontMetrics fm(labelFont);
14821505
auto textWidthInPixels = fm.width(label->text());
@@ -1510,6 +1533,7 @@ void NetworkEditor::highlightTaggedItem(int tagValue)
15101533

15111534
void NetworkEditor::highlightTaggedItem(QGraphicsItem* item, int tagValue)
15121535
{
1536+
qDebug() << "highlightTaggedItem" << tagValue;
15131537
if (tagValue == NoTag)
15141538
{
15151539
item->setGraphicsEffect(blurEffect());

src/Interface/Application/NetworkEditor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ namespace Gui {
256256
void adjustModuleWidth(int delta);
257257
void adjustModuleHeight(int delta);
258258
void saveTagGroupRectInFile();
259+
void renameTagGroupInFile();
259260

260261
Q_SIGNALS:
261262
void addConnection(const SCIRun::Dataflow::Networks::ConnectionDescription&);

src/Interface/Application/TagManagerWindow.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ QColor TagManagerWindow::tagColor(int tag) const
134134

135135
QString TagManagerWindow::tagName(int tag) const
136136
{
137-
if (0 <= tag && tag < NumberOfTags)
138-
return tagNames_[tag];
139-
return "[No tag]";
137+
auto name = (0 <= tag && tag < NumberOfTags) ? tagNames_[tag] : "[No tag]";
138+
qDebug() << "tagName" << tag << name;
139+
return name;
140140
}
141141

142142
void TagManagerWindow::showHelp(QWidget* parent)
@@ -149,8 +149,8 @@ void TagManagerWindow::showHelp(QWidget* parent)
149149
"according to the chosen colors). Or press 0 - 9 keys to see each tag group individually; other modules will be slightly blurred out. While in "
150150
"the single - tag view, you can click a module to toggle it as tagged. There is also a button in the toolbar to view all tagged modules."
151151
"\n\nOnce tags are being used, tag groups can be toggled using Alt-G (show) and Alt-Shift-G (hide). Boxes of the tag color, labelled with the tag's text, will be displayed overlaying the network. "
152-
"To display tag groups on network load, double-click on a tag group box and select the option in the menu. "
153-
"\n\nComing soon: tag names saved in the network file to override application-level names."
152+
"To display tag groups on network load, double-click on a tag group box and select the display option in the menu. "
153+
"\n\nTag names saved in the network file can override application-level names--double-click a displayed tag group box and select the rename option."
154154
);
155155
}
156156

0 commit comments

Comments
 (0)