MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / contextMenuEvent

Method contextMenuEvent

QtNodeEditor/src/FlowView.cpp:101–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99
100
101void
102FlowView::
103contextMenuEvent(QContextMenuEvent *event)
104{
105 if (itemAt(event->pos()))
106 {
107 QGraphicsView::contextMenuEvent(event);
108 return;
109 }
110
111 QMenu modelMenu;
112
113 auto skipText = QStringLiteral("skip me");
114
115 //Add filterbox to the context menu
116 auto *txtBox = new QLineEdit(&modelMenu);
117
118 txtBox->setPlaceholderText(QStringLiteral("Filter"));
119 txtBox->setClearButtonEnabled(true);
120
121 auto *txtBoxAction = new QWidgetAction(&modelMenu);
122 txtBoxAction->setDefaultWidget(txtBox);
123
124 modelMenu.addAction(txtBoxAction);
125
126 //Add result treeview to the context menu
127 auto *treeView = new QTreeWidget(&modelMenu);
128 treeView->header()->close();
129
130 auto *treeViewAction = new QWidgetAction(&modelMenu);
131 treeViewAction->setDefaultWidget(treeView);
132
133 modelMenu.addAction(treeViewAction);
134
135 QMap<QString, QTreeWidgetItem*> topLevelItems;
136 for (auto const &cat : _scene->registry().categories())
137 {
138 auto item = new QTreeWidgetItem(treeView);
139 item->setText(0, cat);
140 item->setData(0, Qt::UserRole, skipText);
141 topLevelItems[cat] = item;
142 }
143
144 for (auto const &assoc : _scene->registry().registeredModelsCategoryAssociation())
145 {
146 auto parent = topLevelItems[assoc.second];
147 auto item = new QTreeWidgetItem(parent);
148 item->setText(0, assoc.first);
149 item->setData(0, Qt::UserRole, assoc.first);
150 }
151
152 treeView->expandAll();
153
154 connect(treeView, &QTreeWidget::itemClicked, [&](QTreeWidgetItem *item, int)
155 {
156 QString modelName = item->data(0, Qt::UserRole).toString();
157
158 if (modelName == skipText)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected