implemented final connections to allow creating new nodes in the nodeview
This commit is contained in:
+16
-1
@@ -37,7 +37,10 @@ Menu *NodeFactory::CreateMenu()
|
||||
{
|
||||
Menu* menu = new Menu();
|
||||
|
||||
foreach (Node* n, library_) {
|
||||
for (int i=0;i<library_.size();i++) {
|
||||
Node* n = library_.at(i);
|
||||
|
||||
// Make sure nodes are up-to-date with the current translation
|
||||
n->Retranslate();
|
||||
|
||||
QStringList path = n->Category().split('/');
|
||||
@@ -72,12 +75,24 @@ Menu *NodeFactory::CreateMenu()
|
||||
|
||||
// Add entry to menu
|
||||
QAction* a = destination->InsertAlphabetically(n->Name());
|
||||
a->setData(i);
|
||||
a->setToolTip(n->Description());
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
||||
Node* NodeFactory::CreateFromMenuAction(QAction *action)
|
||||
{
|
||||
int library_index = action->data().toInt();
|
||||
|
||||
if (library_index >= 0 && library_index < library_.size()) {
|
||||
return library_.at(library_index)->copy();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Node *NodeFactory::CreateInternal(const NodeFactory::InternalID &id)
|
||||
{
|
||||
switch (id) {
|
||||
|
||||
@@ -35,6 +35,8 @@ public:
|
||||
|
||||
static Menu* CreateMenu();
|
||||
|
||||
static Node *CreateFromMenuAction(QAction* action);
|
||||
|
||||
private:
|
||||
static Node* CreateInternal(const InternalID& id);
|
||||
|
||||
|
||||
@@ -199,6 +199,25 @@ void NodeView::SceneSelectionChangedSlot()
|
||||
|
||||
void NodeView::ShowContextMenu(const QPoint &pos)
|
||||
{
|
||||
Menu* m = NodeFactory::CreateMenu();
|
||||
m->exec(pos);
|
||||
if (!graph_) {
|
||||
return;
|
||||
}
|
||||
|
||||
Menu* m = new Menu();
|
||||
|
||||
Menu* add_menu = NodeFactory::CreateMenu();
|
||||
add_menu->setTitle(tr("Add"));
|
||||
connect(add_menu, SIGNAL(triggered(QAction*)), this, SLOT(CreateNodeSlot(QAction*)));
|
||||
m->addMenu(add_menu);
|
||||
|
||||
m->exec(mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void NodeView::CreateNodeSlot(QAction *action)
|
||||
{
|
||||
Node* new_node = NodeFactory::CreateFromMenuAction(action);
|
||||
|
||||
if (new_node) {
|
||||
graph_->AddNode(new_node);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,6 +137,11 @@ private slots:
|
||||
*/
|
||||
void ShowContextMenu(const QPoint &pos);
|
||||
|
||||
/**
|
||||
* @brief Receiver for when the user requests a new node from the add menu
|
||||
*/
|
||||
void CreateNodeSlot(QAction* action);
|
||||
|
||||
};
|
||||
|
||||
#endif // NODEVIEW_H
|
||||
|
||||
Reference in New Issue
Block a user