feat: pass node info with template

This commit is contained in:
parker
2025-07-23 14:06:57 +01:00
parent c5f2dec008
commit b2afebd883
17 changed files with 151 additions and 70 deletions

View File

@@ -19,6 +19,7 @@
#include <qgraphicsitem.h>
#include <qnamespace.h>
#include <QLine>
#include <stdexcept>
#include "Gui/Network/TabMenu.h"
using namespace enzo;
@@ -310,30 +311,35 @@ void Network::keyPressEvent(QKeyEvent *event)
tabMenu_->showOnMouse();
break;
}
case(Qt::Key_G):
{
if(auto newNode = createNode(op::OperatorTable::getOpConstructor("transform")))
{
newNode->setPos(viewPos);
}
// case(Qt::Key_G):
// {
// auto opInfo = op::OperatorTable::getOpInfo("transform");
// if(!opInfo.has_value()) {throw std::runtime_error("Couldn't find op info for: " + )}
// if(
// opInfo.has_value() &&
// auto newNode = createNode(opInfo)
// )
// {
// newNode->setPos(viewPos);
// }
break;
}
case(Qt::Key_F):
{
if(auto newNode = createNode(op::OperatorTable::getOpConstructor("house")))
{
newNode->setPos(viewPos);
}
// break;
// }
// case(Qt::Key_F):
// {
// if(auto newNode = createNode(op::OperatorTable::getOpInfo("house")))
// {
// newNode->setPos(viewPos);
// }
break;
}
// break;
// }
}
}
NodeGraphic* Network::createNode(nt::opConstructor ctorFunc)
NodeGraphic* Network::createNode(op::OpInfo opInfo)
{
if(nt::OpId id = enzo::nt::nm().addOperator(ctorFunc))
if(nt::OpId id = enzo::nt::nm().addOperator(opInfo))
{
NodeGraphic* newNode = new NodeGraphic(id);
QPointF cursorPos = view_->mapToScene(mapFromGlobal(QCursor::pos()));

View File

@@ -33,7 +33,7 @@ public:
DEFAULT,
MOVING_NODE
};
NodeGraphic* createNode(enzo::nt::opConstructor ctorFunc);
NodeGraphic* createNode(enzo::op::OpInfo opInfo);
private:
QLayout* mainLayout_;

View File

@@ -171,11 +171,23 @@ void enzo::ui::TabMenu::textChanged(const QString &text)
}
}
void enzo::ui::TabMenu::createNode(std::string nodeName)
{
// get node info
std::optional<op::OpInfo> opInfo = op::OperatorTable::getOpInfo(nodeName);
// check valid result
if(!opInfo.has_value()) {throw std::runtime_error("Couldn't find op info for: " + nodeName);}
static_cast<Network*>(parentWidget())->createNode(opInfo.value());
}
void enzo::ui::TabMenu::nodeClicked()
{
// get name of button clicked
TabMenuButton* buttonClicked = static_cast<TabMenuButton*>(sender());
static_cast<Network*>(parentWidget())->createNode(op::OperatorTable::getOpConstructor(buttonClicked->nodeName));
createNode(buttonClicked->nodeName);
doHide();
}
@@ -230,7 +242,7 @@ bool enzo::ui::TabMenu::event(QEvent *event)
if(visibleButtons_.size()==0) return true;
if(selectionIndex_>=visibleButtons_.size()) selectionIndex_=visibleButtons_.size()-1;
auto button = visibleButtons_.at(selectionIndex_);
static_cast<Network*>(parentWidget())->createNode(op::OperatorTable::getOpConstructor(button->nodeName));
createNode(button->nodeName);
doHide();
return true;
}

View File

@@ -21,11 +21,11 @@ public:
QString getDisplayText() {return displayText_;}
void setSelected(bool selected);
private:
QHBoxLayout* mainLayout_;
QLabel* textLabel_;
QSvgWidget* icon_;
QString displayText_;
};
class TabMenu
@@ -42,6 +42,7 @@ private:
DOWN
};
void createNode(std::string nodeName);
QVBoxLayout* mainLayout_;
QLineEdit* searchBar_;
QScrollArea* nodeScrollArea_;