feat: signle displayFlag

This commit is contained in:
parker
2025-07-05 17:14:47 +01:00
parent f6d78d6d8b
commit 18f85d6e76
6 changed files with 66 additions and 4 deletions

View File

@@ -35,6 +35,7 @@ Network::Network(QWidget* parent)
scene_ = new NetworkGraphicsScene();
view_ = new NetworkGraphicsView(this, this, scene_);
nm_ = enzo::nt::NetworkManager::getInstance();
mainLayout_->addWidget(view_);
@@ -106,6 +107,14 @@ void Network::leftMousePressed(QMouseEvent *event)
// display flag
else if(QGraphicsItem* clickedDisplayFlag = itemOfType<DisplayFlagButton>(clickedItems))
{
NodeGraphic* clickedNode = static_cast<NodeGraphic*>(itemOfType<NodeGraphic>(clickedItems));
enzo::nt::OpId opId = clickedNode->getOpId();
if(auto prevDisplayOpId = nm_->getDisplayOp(); prevDisplayOpId)
{
NodeGraphic* prevDisplayNode = nodeStore_.at(*prevDisplayOpId);
prevDisplayNode->setDisplayFlag(false);
}
nm_->setDisplayOp(opId);
static_cast<DisplayFlagButton*>(clickedDisplayFlag)->setEnabled(true);
}
else if(QGraphicsItem* clickedNode = itemOfType<NodeGraphic>(clickedItems))
@@ -276,12 +285,9 @@ void Network::keyPressEvent(QKeyEvent *event)
}
case(Qt::Key_Tab):
{
nt::NetworkManager* nm = nt::NetworkManager::getInstance();
if(nt::OpId id = nm->addOperator())
if(auto newNode = createNode())
{
NodeGraphic* newNode = new NodeGraphic(id);
newNode->setPos(viewPos);
scene_->addItem(newNode);
}
break;
@@ -289,6 +295,23 @@ void Network::keyPressEvent(QKeyEvent *event)
}
}
NodeGraphic* Network::createNode()
{
if(nt::OpId id = nm_->addOperator())
{
NodeGraphic* newNode = new NodeGraphic(id);
scene_->addItem(newNode);
nodeStore_.emplace(id, newNode);
return newNode;
}
else
{
return nullptr;
}
}
void Network::highlightEdge(QGraphicsItem* edge, bool state)
{
if(!edge || !isType<NodeEdgeGraphic>(edge)) return;

View File

@@ -3,13 +3,17 @@
#include <memory>
#include <qgraphicsitem.h>
#include <typeinfo>
#include "Engine/Network/NetworkManager.h"
#include "Engine/Types.h"
#include "gui/network/NetworkGraphicsView.h"
#include "gui/network/NodeEdgeGraphic.h"
#include "gui/network/NetworkGraphicsScene.h"
#include "gui/network/NodeGraphic.h"
#include "gui/network/SocketGraphic.h"
#include "gui/network/FloatingEdgeGraphic.h"
#include <iostream>
#include <QPointer>
#include <unordered_map>
class Network
: public QWidget
@@ -31,6 +35,10 @@ private:
NetworkGraphicsScene* scene_;
NetworkGraphicsView* view_;
enzo::nt::NetworkManager* nm_;
std::unordered_map<enzo::nt::OpId, NodeGraphic*> nodeStore_;
FloatingEdgeGraphic* floatingEdge_=nullptr;
SocketGraphic* startSocket_=nullptr;
@@ -46,6 +54,8 @@ private:
void destroyFloatingEdge();
void deleteEdge(QGraphicsItem* edge);
NodeGraphic* createNode();
void highlightEdge(QGraphicsItem* edge, bool state);
void leftMousePressed(QMouseEvent* event);

View File

@@ -7,6 +7,7 @@
#include <string>
#include "Engine/Network/NetworkManager.h"
#include "Engine/Operator/GeometryOperator.h"
#include "Engine/Types.h"
#include "gui/network/DisplayFlagButton.h"
#include "gui/network/SocketGraphic.h"
#include <QGraphicsScene>
@@ -220,6 +221,17 @@ QPointF NodeGraphic::getSocketScenePosition(int socketIndex, enzo::nt::SocketIOT
return this->pos()+getSocketPosition(socketIndex, socketType);
}
enzo::nt::OpId NodeGraphic::getOpId() const
{
return opId_;
}
void NodeGraphic::setDisplayFlag(bool state)
{
displayFlagButton_->setEnabled(state);
}
QRectF NodeGraphic::getBodyRect()
{
return bodyRect_;

View File

@@ -17,9 +17,11 @@ public:
SocketGraphic* getInput(int indx) const;
SocketGraphic* getOutput(int indx) const;
enzo::nt::OpId getOpId() const;
QPointF getSocketPosition(int socketIndex, enzo::nt::SocketIOType socketType);
QPointF getSocketScenePosition(int socketIndex, enzo::nt::SocketIOType socketType);
QRectF getBodyRect();
void setDisplayFlag(bool state);
// void addEdge(NodeEdgeGraphic* edge);