mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 10:50:23 +08:00
refactor: refactored Complex Connection Editor
This commit is contained in:
parent
febe019318
commit
5013cf7947
@ -20,6 +20,33 @@ set(QV2RAY_UI_FORMS
|
|||||||
${CMAKE_SOURCE_DIR}/src/ui/windows/w_ScreenShot_Core.ui
|
${CMAKE_SOURCE_DIR}/src/ui/windows/w_ScreenShot_Core.ui
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(QV2RAY_UI_NODEEDITOR_SOURCES
|
||||||
|
# NodeEditor Models
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/NodeBase.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/InboundNodeModel.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/InboundNodeModel.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/OutboundNodeModel.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/OutboundNodeModel.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/RuleNodeModel.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/models/RuleNodeModel.cpp
|
||||||
|
# NodeEditor Widgets
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/RuleWidget.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/RuleWidget.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/RuleWidget.ui
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/InboundWidget.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/InboundWidget.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/InboundWidget.ui
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundWidget.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundWidget.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundWidget.ui
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundChainWidget.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundChainWidget.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundChainWidget.ui
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundBalancerWidget.cpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundBalancerWidget.hpp
|
||||||
|
${CMAKE_SOURCE_DIR}/src/ui/node/widgets/OutboundBalancerWidget.ui
|
||||||
|
)
|
||||||
|
|
||||||
set(QV2RAY_UI_SOURCES
|
set(QV2RAY_UI_SOURCES
|
||||||
# Qv2ray Application
|
# Qv2ray Application
|
||||||
${CMAKE_SOURCE_DIR}/src/Qv2rayApplication.cpp
|
${CMAKE_SOURCE_DIR}/src/Qv2rayApplication.cpp
|
||||||
@ -36,30 +63,6 @@ set(QV2RAY_UI_SOURCES
|
|||||||
# Message bus
|
# Message bus
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/messaging/QvMessageBus.hpp
|
${CMAKE_SOURCE_DIR}/src/ui/messaging/QvMessageBus.hpp
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/messaging/QvMessageBus.cpp
|
${CMAKE_SOURCE_DIR}/src/ui/messaging/QvMessageBus.cpp
|
||||||
# NodeEditor Models
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/NodeModelsBase.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/InboundNodeModel.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/InboundNodeModel.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/OutboundNodeModel.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/OutboundNodeModel.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/RuleNodeModel.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/models/RuleNodeModel.cpp
|
|
||||||
# NodeEditor Widgets
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/RuleWidget.ui
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/InboundWidget.ui
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundWidget.ui
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundChainWidget.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundChainWidget.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundChainWidget.ui
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.cpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.hpp
|
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/widgets/node/OutboundBalancerWidget.ui
|
|
||||||
# Style Manager
|
# Style Manager
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.cpp
|
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.cpp
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.hpp
|
${CMAKE_SOURCE_DIR}/src/ui/styles/StyleManager.hpp
|
||||||
@ -104,4 +107,5 @@ set(QV2RAY_UI_SOURCES
|
|||||||
${CMAKE_SOURCE_DIR}/src/ui/windows/w_ScreenShot_Core.cpp
|
${CMAKE_SOURCE_DIR}/src/ui/windows/w_ScreenShot_Core.cpp
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/windows/w_GroupManager.hpp
|
${CMAKE_SOURCE_DIR}/src/ui/windows/w_GroupManager.hpp
|
||||||
${CMAKE_SOURCE_DIR}/src/ui/windows/w_GroupManager.cpp
|
${CMAKE_SOURCE_DIR}/src/ui/windows/w_GroupManager.cpp
|
||||||
|
${QV2RAY_UI_NODEEDITOR_SOURCES}
|
||||||
)
|
)
|
||||||
|
@ -1 +1 @@
|
|||||||
5797
|
5798
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
#include "core/connection/Generation.hpp"
|
#include "core/connection/Generation.hpp"
|
||||||
#include "core/handler/ConfigHandler.hpp"
|
#include "core/handler/ConfigHandler.hpp"
|
||||||
#include "ui/common/UIBase.hpp"
|
#include "ui/common/UIBase.hpp"
|
||||||
#include "ui/models/InboundNodeModel.hpp"
|
#include "ui/node/models/InboundNodeModel.hpp"
|
||||||
#include "ui/models/OutboundNodeModel.hpp"
|
#include "ui/node/models/OutboundNodeModel.hpp"
|
||||||
#include "ui/models/RuleNodeModel.hpp"
|
#include "ui/node/models/RuleNodeModel.hpp"
|
||||||
#include "ui/windows/w_ImportConfig.hpp"
|
#include "ui/windows/w_ImportConfig.hpp"
|
||||||
#include "w_InboundEditor.hpp"
|
#include "w_InboundEditor.hpp"
|
||||||
#include "w_JsonEditor.hpp"
|
#include "w_JsonEditor.hpp"
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include "core/CoreUtils.hpp"
|
#include "core/CoreUtils.hpp"
|
||||||
#include "ui/common/UIBase.hpp"
|
#include "ui/common/UIBase.hpp"
|
||||||
#include "ui/models/InboundNodeModel.hpp"
|
#include "ui/node/models/InboundNodeModel.hpp"
|
||||||
#include "ui/models/OutboundNodeModel.hpp"
|
#include "ui/node/models/OutboundNodeModel.hpp"
|
||||||
#include "ui/models/RuleNodeModel.hpp"
|
#include "ui/node/models/RuleNodeModel.hpp"
|
||||||
#include "w_RoutesEditor.hpp"
|
#include "w_RoutesEditor.hpp"
|
||||||
|
|
||||||
#include <nodes/internal/FlowScene.hpp>
|
#include <nodes/internal/FlowScene.hpp>
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
#include "InboundNodeModel.hpp"
|
|
||||||
|
|
||||||
QvInboundNodeModel::QvInboundNodeModel(std::shared_ptr<InboundNodeData> data) : NodeDataModel()
|
|
||||||
{
|
|
||||||
_in = data;
|
|
||||||
widget = new InboundWidget();
|
|
||||||
widget->setWindowFlags(Qt::FramelessWindowHint);
|
|
||||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
|
||||||
connect(widget, &InboundWidget::OnSizeUpdated, this, &QvInboundNodeModel::embeddedWidgetSizeUpdated);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::unique_ptr<NodeDataModel> QvInboundNodeModel::clone() const
|
|
||||||
{
|
|
||||||
return std::make_unique<QvInboundNodeModel>(_in);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeData> QvInboundNodeModel::outData(PortIndex)
|
|
||||||
{
|
|
||||||
return _in;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> QvInboundNodeModel::dataType(PortType portType, PortIndex portIndex) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(portType)
|
|
||||||
Q_UNUSED(portIndex)
|
|
||||||
return NODE_TYPE_INBOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString QvInboundNodeModel::name() const
|
|
||||||
{
|
|
||||||
return "InboundNode";
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int QvInboundNodeModel::nPorts(PortType portType) const
|
|
||||||
{
|
|
||||||
return portType == PortType::Out ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void QvInboundNodeModel::setData(std::shared_ptr<INBOUND> data)
|
|
||||||
{
|
|
||||||
_in = std::make_shared<InboundNodeData>(data);
|
|
||||||
widget->adjustSize();
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "NodeModelsBase.hpp"
|
|
||||||
#include "ui/widgets/node/InboundWidget.hpp"
|
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
|
|
||||||
class QvInboundNodeModel : public NodeDataModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QvInboundNodeModel(std::shared_ptr<InboundNodeData> data);
|
|
||||||
~QvInboundNodeModel(){};
|
|
||||||
|
|
||||||
QString caption() const override
|
|
||||||
{
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool captionVisible() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nPorts(PortType portType) const override;
|
|
||||||
QString name() const override;
|
|
||||||
std::shared_ptr<NodeDataType> dataType(PortType portType, PortIndex portIndex) const override;
|
|
||||||
std::shared_ptr<NodeData> outData(PortIndex) override;
|
|
||||||
void setInData(std::shared_ptr<NodeData>, int) override{};
|
|
||||||
void setData(std::shared_ptr<INBOUND> data);
|
|
||||||
|
|
||||||
QWidget *embeddedWidget() override
|
|
||||||
{
|
|
||||||
return widget;
|
|
||||||
}
|
|
||||||
std::unique_ptr<NodeDataModel> clone() const override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
|
||||||
QString modelValidationError = tr("Missing or incorrect inputs");
|
|
||||||
//
|
|
||||||
std::shared_ptr<InboundNodeData> _in;
|
|
||||||
InboundWidget *widget;
|
|
||||||
};
|
|
@ -1,88 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "base/Qv2rayBase.hpp"
|
|
||||||
#include "common/QvHelpers.hpp"
|
|
||||||
|
|
||||||
#include <QLabel>
|
|
||||||
#include <memory>
|
|
||||||
#include <nodes/internal/NodeDataModel.hpp>
|
|
||||||
#include <nodes/internal/PortType.hpp>
|
|
||||||
|
|
||||||
using QtNodes::NodeData;
|
|
||||||
using QtNodes::NodeDataModel;
|
|
||||||
using QtNodes::NodeDataType;
|
|
||||||
using QtNodes::NodeValidationState;
|
|
||||||
using QtNodes::PortIndex;
|
|
||||||
using QtNodes::PortType;
|
|
||||||
|
|
||||||
using QtNodes::NodeData;
|
|
||||||
using QtNodes::NodeDataType;
|
|
||||||
|
|
||||||
constexpr auto GRAPH_NODE_LABEL_FONTSIZE_INCREMENT = 3;
|
|
||||||
|
|
||||||
namespace Qv2ray::ui::nodemodels
|
|
||||||
{
|
|
||||||
const std::shared_ptr<NodeDataType> NODE_TYPE_OUTBOUND = std::make_shared<NodeDataType>("outbound", QObject::tr("Outbound"));
|
|
||||||
const std::shared_ptr<NodeDataType> NODE_TYPE_INBOUND = std::make_shared<NodeDataType>("inbound", QObject::tr("Inbound"));
|
|
||||||
const std::shared_ptr<NodeDataType> NODE_TYPE_RULE = std::make_shared<NodeDataType>("rule", QObject::tr("Rule"));
|
|
||||||
|
|
||||||
class InboundNodeData : public NodeData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit InboundNodeData(std::shared_ptr<INBOUND> data) : inboundData(data){};
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> type() const override
|
|
||||||
{
|
|
||||||
return NODE_TYPE_RULE;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<INBOUND> GetInbound()
|
|
||||||
{
|
|
||||||
return inboundData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<INBOUND> inboundData;
|
|
||||||
};
|
|
||||||
|
|
||||||
class OutboundNodeData : public NodeData
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit OutboundNodeData(std::shared_ptr<complex::OutboundObjectMeta> data) : outboundData(data){};
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> type() const override
|
|
||||||
{
|
|
||||||
return NODE_TYPE_OUTBOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<complex::OutboundObjectMeta> GetOutbound()
|
|
||||||
{
|
|
||||||
return outboundData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<complex::OutboundObjectMeta> outboundData;
|
|
||||||
};
|
|
||||||
|
|
||||||
class RuleNodeData : public NodeData
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit RuleNodeData(std::shared_ptr<RuleObject> rule) : _rule(rule){};
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> type() const override
|
|
||||||
{
|
|
||||||
return NODE_TYPE_INBOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<RuleObject> GetRule()
|
|
||||||
{
|
|
||||||
return _rule;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::shared_ptr<RuleObject> _rule;
|
|
||||||
};
|
|
||||||
} // namespace Qv2ray::ui::nodemodels
|
|
||||||
|
|
||||||
using namespace Qv2ray::ui::nodemodels;
|
|
@ -1,9 +0,0 @@
|
|||||||
#include "ui/models/OutboundNodeModel.hpp"
|
|
||||||
|
|
||||||
QvOutboundNodeModel::QvOutboundNodeModel(std::shared_ptr<OutboundNodeData> data) : NodeDataModel()
|
|
||||||
{
|
|
||||||
_out = data;
|
|
||||||
widget = new InboundWidget();
|
|
||||||
widget->setWindowFlags(Qt::FramelessWindowHint);
|
|
||||||
widget->setAttribute(Qt::WA_TranslucentBackground);
|
|
||||||
}
|
|
@ -1,74 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "ui/models/NodeModelsBase.hpp"
|
|
||||||
#include "ui/widgets/node/InboundWidget.hpp"
|
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
|
|
||||||
class QvOutboundNodeModel : public NodeDataModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
explicit QvOutboundNodeModel(std::shared_ptr<OutboundNodeData> data);
|
|
||||||
~QvOutboundNodeModel(){};
|
|
||||||
void setInData(std::shared_ptr<NodeData>, int) override{};
|
|
||||||
void setInData(std::vector<std::shared_ptr<NodeData>>, int) override{};
|
|
||||||
|
|
||||||
QString caption() const override
|
|
||||||
{
|
|
||||||
return "Nothing";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool captionVisible() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nPorts(PortType portType) const override
|
|
||||||
{
|
|
||||||
return portType == PortType::In ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString name() const override
|
|
||||||
{
|
|
||||||
return "OutboundNode";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> dataType(PortType portType, PortIndex portIndex) const override
|
|
||||||
{
|
|
||||||
Q_UNUSED(portType)
|
|
||||||
Q_UNUSED(portIndex)
|
|
||||||
return NODE_TYPE_OUTBOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeData> outData(PortIndex) override
|
|
||||||
{
|
|
||||||
return _out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setData(std::shared_ptr<complex::OutboundObjectMeta> data)
|
|
||||||
{
|
|
||||||
_out = std::make_shared<OutboundNodeData>(data);
|
|
||||||
widget->adjustSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *embeddedWidget() override
|
|
||||||
{
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionPolicy portInConnectionPolicy(PortIndex) const override
|
|
||||||
{
|
|
||||||
return ConnectionPolicy::Many;
|
|
||||||
}
|
|
||||||
std::unique_ptr<NodeDataModel> clone() const override
|
|
||||||
{
|
|
||||||
return std::make_unique<QvOutboundNodeModel>(_out);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
|
||||||
QString modelValidationError = tr("Missing or incorrect inputs");
|
|
||||||
//
|
|
||||||
std::shared_ptr<OutboundNodeData> _out;
|
|
||||||
InboundWidget *widget;
|
|
||||||
};
|
|
@ -1,10 +0,0 @@
|
|||||||
#include "ui/models/RuleNodeModel.hpp"
|
|
||||||
|
|
||||||
QvRuleNodeModel::QvRuleNodeModel(std::shared_ptr<RuleNodeData> data) : NodeDataModel()
|
|
||||||
{
|
|
||||||
_ruleTag = data;
|
|
||||||
ruleWidget = new QvNodeRuleWidget();
|
|
||||||
connect(ruleWidget, &QvNodeRuleWidget::OnSizeUpdated, this, &QvRuleNodeModel::embeddedWidgetSizeUpdated);
|
|
||||||
ruleWidget->setWindowFlags(Qt::FramelessWindowHint);
|
|
||||||
ruleWidget->setAttribute(Qt::WA_TranslucentBackground);
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "ui/models/NodeModelsBase.hpp"
|
|
||||||
#include "ui/widgets/node/RuleWidget.hpp"
|
|
||||||
|
|
||||||
#include <QtCore/qglobal.h>
|
|
||||||
|
|
||||||
class QvRuleNodeModel : public NodeDataModel
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
QvRuleNodeModel(std::shared_ptr<RuleNodeData> data);
|
|
||||||
~QvRuleNodeModel(){};
|
|
||||||
|
|
||||||
QString caption() const override
|
|
||||||
{
|
|
||||||
return "Nothing";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool resizable() const override
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool captionVisible() const override
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nPorts(PortType portType) const override
|
|
||||||
{
|
|
||||||
if (portType == PortType::In || portType == PortType::Out)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString name() const override
|
|
||||||
{
|
|
||||||
return "RuleNode";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeDataType> dataType(PortType portType, PortIndex) const override
|
|
||||||
{
|
|
||||||
switch (portType)
|
|
||||||
{
|
|
||||||
case PortType::In: return NODE_TYPE_INBOUND;
|
|
||||||
case PortType::Out: return NODE_TYPE_OUTBOUND;
|
|
||||||
default: return {};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<NodeData> outData(PortIndex) override
|
|
||||||
{
|
|
||||||
return _ruleTag;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setInData(std::shared_ptr<NodeData>, int) override{};
|
|
||||||
void setInData(std::vector<std::shared_ptr<NodeData>>, int) override{};
|
|
||||||
void setData(std::shared_ptr<RuleObject> data)
|
|
||||||
{
|
|
||||||
_ruleTag = std::make_shared<RuleNodeData>(data);
|
|
||||||
ruleWidget->adjustSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
QWidget *embeddedWidget() override
|
|
||||||
{
|
|
||||||
return ruleWidget;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionPolicy portInConnectionPolicy(PortIndex) const override
|
|
||||||
{
|
|
||||||
return ConnectionPolicy::Many;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConnectionPolicy portOutConnectionPolicy(PortIndex) const override
|
|
||||||
{
|
|
||||||
return ConnectionPolicy::One;
|
|
||||||
}
|
|
||||||
std::unique_ptr<NodeDataModel> clone() const override
|
|
||||||
{
|
|
||||||
return std::make_unique<QvRuleNodeModel>(_ruleTag);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
NodeValidationState modelValidationState = NodeValidationState::Warning;
|
|
||||||
QString modelValidationError = tr("Missing or incorrect inputs");
|
|
||||||
//
|
|
||||||
std::shared_ptr<RuleNodeData> _ruleTag;
|
|
||||||
QvNodeRuleWidget *ruleWidget;
|
|
||||||
};
|
|
115
src/ui/node/NodeBase.hpp
Normal file
115
src/ui/node/NodeBase.hpp
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "base/Qv2rayBase.hpp"
|
||||||
|
#include "common/QvHelpers.hpp"
|
||||||
|
|
||||||
|
#include <QLabel>
|
||||||
|
#include <memory>
|
||||||
|
#include <nodes/internal/Connection.hpp>
|
||||||
|
#include <nodes/internal/NodeDataModel.hpp>
|
||||||
|
#include <nodes/internal/PortType.hpp>
|
||||||
|
|
||||||
|
using QtNodes::NodeData;
|
||||||
|
using QtNodes::NodeDataModel;
|
||||||
|
using QtNodes::NodeDataType;
|
||||||
|
using QtNodes::NodeValidationState;
|
||||||
|
using QtNodes::PortIndex;
|
||||||
|
using QtNodes::PortType;
|
||||||
|
|
||||||
|
using QtNodes::NodeData;
|
||||||
|
using QtNodes::NodeDataType;
|
||||||
|
|
||||||
|
constexpr auto GRAPH_NODE_LABEL_FONTSIZE_INCREMENT = 3;
|
||||||
|
|
||||||
|
namespace Qv2ray::ui::nodemodels
|
||||||
|
{
|
||||||
|
const auto NODE_TYPE_OUTBOUND = std::make_shared<NodeDataType>("outbound", QObject::tr("Outbound"));
|
||||||
|
const auto NODE_TYPE_INBOUND = std::make_shared<NodeDataType>("inbound", QObject::tr("Inbound"));
|
||||||
|
const auto NODE_TYPE_RULE = std::make_shared<NodeDataType>("rule", QObject::tr("Rule"));
|
||||||
|
|
||||||
|
class QvNodeWidget : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit QvNodeWidget(QWidget *parent) : QWidget(parent){};
|
||||||
|
template<typename T>
|
||||||
|
void setValue(std::shared_ptr<T>){};
|
||||||
|
virtual void OnSizeUpdated() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DECL_NODE_DATA_TYPE(name, TYPE, INNER_TYPE) \
|
||||||
|
class name : public NodeData \
|
||||||
|
{ \
|
||||||
|
public: \
|
||||||
|
explicit name(std::shared_ptr<INNER_TYPE> data) : data(data){}; \
|
||||||
|
std::shared_ptr<NodeDataType> type() const override \
|
||||||
|
{ \
|
||||||
|
return TYPE; \
|
||||||
|
} \
|
||||||
|
std::shared_ptr<INNER_TYPE> GetInbound() \
|
||||||
|
{ \
|
||||||
|
return data; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
private: \
|
||||||
|
std::shared_ptr<INNER_TYPE> data; \
|
||||||
|
}
|
||||||
|
|
||||||
|
DECL_NODE_DATA_TYPE(InboundNodeData, NODE_TYPE_INBOUND, INBOUND);
|
||||||
|
DECL_NODE_DATA_TYPE(OutboundNodeData, NODE_TYPE_OUTBOUND, complex::OutboundObjectMeta);
|
||||||
|
DECL_NODE_DATA_TYPE(RuleNodeData, NODE_TYPE_RULE, RuleObject);
|
||||||
|
|
||||||
|
//
|
||||||
|
//***********************************************************************************************************************************
|
||||||
|
//
|
||||||
|
|
||||||
|
#define DECL_NODE_DATA_MODEL(NAME, CONTENT_TYPE) \
|
||||||
|
class NAME : public NodeDataModel \
|
||||||
|
{ \
|
||||||
|
Q_OBJECT \
|
||||||
|
public: \
|
||||||
|
explicit NAME(std::shared_ptr<CONTENT_TYPE> data); \
|
||||||
|
~NAME(){}; \
|
||||||
|
\
|
||||||
|
QString caption() const override \
|
||||||
|
{ \
|
||||||
|
return {}; \
|
||||||
|
} \
|
||||||
|
bool captionVisible() const override \
|
||||||
|
{ \
|
||||||
|
return false; \
|
||||||
|
} \
|
||||||
|
QString name() const override \
|
||||||
|
{ \
|
||||||
|
return #NAME; \
|
||||||
|
} \
|
||||||
|
unsigned int nPorts(PortType portType) const override; \
|
||||||
|
std::shared_ptr<NodeDataType> dataType(PortType portType, PortIndex portIndex) const override; \
|
||||||
|
std::shared_ptr<NodeData> outData(PortIndex) override; \
|
||||||
|
void setInData(std::shared_ptr<NodeData>, int) override; \
|
||||||
|
void setData(std::shared_ptr<CONTENT_TYPE> data); \
|
||||||
|
QWidget *embeddedWidget() override \
|
||||||
|
{ \
|
||||||
|
return widget; \
|
||||||
|
} \
|
||||||
|
std::unique_ptr<NodeDataModel> clone() const override \
|
||||||
|
{ \
|
||||||
|
return {}; \
|
||||||
|
}; \
|
||||||
|
void inputConnectionCreated(const QtNodes::Connection &) override; \
|
||||||
|
void inputConnectionDeleted(const QtNodes::Connection &) override; \
|
||||||
|
void outputConnectionCreated(const QtNodes::Connection &) override; \
|
||||||
|
void outputConnectionDeleted(const QtNodes::Connection &) override; \
|
||||||
|
\
|
||||||
|
private: \
|
||||||
|
std::shared_ptr<CONTENT_TYPE> dataptr; \
|
||||||
|
QvNodeWidget *widget; \
|
||||||
|
}
|
||||||
|
|
||||||
|
DECL_NODE_DATA_MODEL(InboundNodeDataModel, INBOUND);
|
||||||
|
DECL_NODE_DATA_MODEL(OutboundNodeDataModel, complex::OutboundObjectMeta);
|
||||||
|
DECL_NODE_DATA_MODEL(RuleNodeDataModel, RuleObject);
|
||||||
|
|
||||||
|
} // namespace Qv2ray::ui::nodemodels
|
||||||
|
|
||||||
|
using namespace Qv2ray::ui::nodemodels;
|
53
src/ui/node/models/InboundNodeModel.cpp
Normal file
53
src/ui/node/models/InboundNodeModel.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "InboundNodeModel.hpp"
|
||||||
|
|
||||||
|
#include "ui/node/widgets/InboundWidget.hpp"
|
||||||
|
|
||||||
|
InboundNodeDataModel::InboundNodeDataModel(std::shared_ptr<INBOUND> data) : NodeDataModel()
|
||||||
|
{
|
||||||
|
widget = new InboundWidget();
|
||||||
|
connect(widget, &QvNodeWidget::OnSizeUpdated, this, &InboundNodeDataModel::embeddedWidgetSizeUpdated);
|
||||||
|
widget->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeDataType> InboundNodeDataModel::dataType(PortType portType, PortIndex portIndex) const
|
||||||
|
{
|
||||||
|
return NODE_TYPE_INBOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::setInData(std::shared_ptr<NodeData>, int)
|
||||||
|
{
|
||||||
|
// dataptr = data;
|
||||||
|
// widget->adjustSize();
|
||||||
|
}
|
||||||
|
unsigned int InboundNodeDataModel::nPorts(PortType portType) const
|
||||||
|
{
|
||||||
|
return portType == PortType::Out ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeData> InboundNodeDataModel::outData(PortIndex)
|
||||||
|
{
|
||||||
|
return std::make_shared<InboundNodeData>(dataptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::setData(std::shared_ptr<INBOUND> data)
|
||||||
|
{
|
||||||
|
dataptr = data;
|
||||||
|
widget->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::inputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::inputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::outputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void InboundNodeDataModel::outputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
2
src/ui/node/models/InboundNodeModel.hpp
Normal file
2
src/ui/node/models/InboundNodeModel.hpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ui/node/NodeBase.hpp"
|
63
src/ui/node/models/OutboundNodeModel.cpp
Normal file
63
src/ui/node/models/OutboundNodeModel.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
#include "ui/node/models/OutboundNodeModel.hpp"
|
||||||
|
|
||||||
|
#include "ui/node/widgets/OutboundBalancerWidget.hpp"
|
||||||
|
#include "ui/node/widgets/OutboundChainWidget.hpp"
|
||||||
|
#include "ui/node/widgets/OutboundWidget.hpp"
|
||||||
|
|
||||||
|
OutboundNodeDataModel::OutboundNodeDataModel(std::shared_ptr<complex::OutboundObjectMeta> data) : NodeDataModel()
|
||||||
|
{
|
||||||
|
switch (data->metaType)
|
||||||
|
{
|
||||||
|
case complex::METAOUTBOUND_CHAINED:
|
||||||
|
{
|
||||||
|
}
|
||||||
|
case complex::METAOUTBOUND_BALANCER:
|
||||||
|
case complex::METAOUTBOUND_ORIGINAL: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// widget = new InboundWidget();
|
||||||
|
// widget->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
// widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeDataType> OutboundNodeDataModel::dataType(PortType portType, PortIndex portIndex) const
|
||||||
|
{
|
||||||
|
return NODE_TYPE_OUTBOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::setInData(std::shared_ptr<NodeData>, int)
|
||||||
|
{
|
||||||
|
// dataptr = data;
|
||||||
|
// widget->adjustSize();
|
||||||
|
}
|
||||||
|
unsigned int OutboundNodeDataModel::nPorts(PortType portType) const
|
||||||
|
{
|
||||||
|
return portType == PortType::Out ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeData> OutboundNodeDataModel::outData(PortIndex)
|
||||||
|
{
|
||||||
|
return std::make_shared<OutboundNodeData>(dataptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::setData(std::shared_ptr<complex::OutboundObjectMeta> data)
|
||||||
|
{
|
||||||
|
dataptr = data;
|
||||||
|
widget->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::inputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::inputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::outputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void OutboundNodeDataModel::outputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
2
src/ui/node/models/OutboundNodeModel.hpp
Normal file
2
src/ui/node/models/OutboundNodeModel.hpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ui/node/NodeBase.hpp"
|
58
src/ui/node/models/RuleNodeModel.cpp
Normal file
58
src/ui/node/models/RuleNodeModel.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
#include "ui/node/models/RuleNodeModel.hpp"
|
||||||
|
|
||||||
|
#include "ui/node/widgets/RuleWidget.hpp"
|
||||||
|
|
||||||
|
RuleNodeDataModel::RuleNodeDataModel(std::shared_ptr<RuleObject> data) : NodeDataModel()
|
||||||
|
{
|
||||||
|
widget = new QvNodeRuleWidget();
|
||||||
|
connect(widget, &QvNodeWidget::OnSizeUpdated, this, &RuleNodeDataModel::embeddedWidgetSizeUpdated);
|
||||||
|
widget->setWindowFlags(Qt::FramelessWindowHint);
|
||||||
|
widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||||
|
}
|
||||||
|
unsigned int RuleNodeDataModel::nPorts(PortType) const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeData> RuleNodeDataModel::outData(PortIndex)
|
||||||
|
{
|
||||||
|
return std::make_shared<RuleNodeData>(dataptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<NodeDataType> RuleNodeDataModel::dataType(PortType portType, PortIndex portIndex) const
|
||||||
|
{
|
||||||
|
switch (portType)
|
||||||
|
{
|
||||||
|
case PortType::In: return NODE_TYPE_INBOUND;
|
||||||
|
case PortType::Out: return NODE_TYPE_OUTBOUND;
|
||||||
|
default: return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::setInData(std::shared_ptr<NodeData>, int)
|
||||||
|
{
|
||||||
|
// dataptr = data;
|
||||||
|
// widget->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::setData(std::shared_ptr<RuleObject> data)
|
||||||
|
{
|
||||||
|
dataptr = data;
|
||||||
|
widget->adjustSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::inputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::inputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::outputConnectionCreated(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RuleNodeDataModel::outputConnectionDeleted(const QtNodes::Connection &c)
|
||||||
|
{
|
||||||
|
}
|
2
src/ui/node/models/RuleNodeModel.hpp
Normal file
2
src/ui/node/models/RuleNodeModel.hpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ui/node/NodeBase.hpp"
|
@ -1,6 +1,6 @@
|
|||||||
#include "InboundWidget.hpp"
|
#include "InboundWidget.hpp"
|
||||||
|
|
||||||
InboundWidget::InboundWidget(QWidget *parent) : QWidget(parent)
|
InboundWidget::InboundWidget(QWidget *parent) : QvNodeWidget(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
}
|
}
|
@ -1,19 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/node/NodeBase.hpp"
|
||||||
#include "ui_InboundWidget.h"
|
#include "ui_InboundWidget.h"
|
||||||
|
|
||||||
class InboundWidget
|
class InboundWidget
|
||||||
: public QWidget
|
: public QvNodeWidget
|
||||||
, private Ui::InboundWidget
|
, private Ui::InboundWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit InboundWidget(QWidget *parent = nullptr);
|
explicit InboundWidget(QWidget *parent = nullptr);
|
||||||
|
void setValue(std::shared_ptr<INBOUND> data);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void OnSizeUpdated();
|
void OnSizeUpdated() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void changeEvent(QEvent *e);
|
void changeEvent(QEvent *e) override;
|
||||||
};
|
};
|
@ -21,7 +21,7 @@ void OutboundBalancerWidget::changeEvent(QEvent *e)
|
|||||||
|
|
||||||
void OutboundBalancerWidget::on_balancerAddBtn_clicked()
|
void OutboundBalancerWidget::on_balancerAddBtn_clicked()
|
||||||
{
|
{
|
||||||
auto balancerTx = balancerSelectionCombo->currentText();
|
const auto balancerTx = balancerSelectionCombo->currentText().trimmed();
|
||||||
|
|
||||||
if (!balancerTx.isEmpty())
|
if (!balancerTx.isEmpty())
|
||||||
{
|
{
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ui/node/models/RuleNodeModel.hpp"
|
||||||
#include "ui_OutboundChainWidget.h"
|
#include "ui_OutboundChainWidget.h"
|
||||||
|
|
||||||
class OutboundChainWidget
|
class OutboundChainWidget
|
@ -10,7 +10,7 @@
|
|||||||
return;
|
return;
|
||||||
#define rule (*(this->ruleptr))
|
#define rule (*(this->ruleptr))
|
||||||
|
|
||||||
QvNodeRuleWidget::QvNodeRuleWidget(QWidget *parent) : QWidget(parent)
|
QvNodeRuleWidget::QvNodeRuleWidget(QWidget *parent) : QvNodeWidget(parent)
|
||||||
{
|
{
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
}
|
}
|
||||||
@ -25,7 +25,7 @@ void QvNodeRuleWidget::changeEvent(QEvent *e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QvNodeRuleWidget::ShowCurrentRuleDetail(std::shared_ptr<RuleObject> _ruleptr)
|
void QvNodeRuleWidget::setValue(std::shared_ptr<RuleObject> _ruleptr)
|
||||||
{
|
{
|
||||||
LOADINGCHECK
|
LOADINGCHECK
|
||||||
|
|
@ -1,20 +1,21 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "base/Qv2rayBase.hpp"
|
#include "base/Qv2rayBase.hpp"
|
||||||
|
#include "ui/node/NodeBase.hpp"
|
||||||
#include "ui_RuleWidget.h"
|
#include "ui_RuleWidget.h"
|
||||||
|
|
||||||
class QvNodeRuleWidget
|
class QvNodeRuleWidget
|
||||||
: public QWidget
|
: public QvNodeWidget
|
||||||
, private Ui::RuleWidget
|
, private Ui::RuleWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit QvNodeRuleWidget(QWidget *parent = nullptr);
|
explicit QvNodeRuleWidget(QWidget *parent = nullptr);
|
||||||
void ShowCurrentRuleDetail(std::shared_ptr<RuleObject> rule);
|
void setValue(std::shared_ptr<RuleObject>);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void OnSizeUpdated();
|
void OnSizeUpdated() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_toolButton_clicked();
|
void on_toolButton_clicked();
|
Loading…
Reference in New Issue
Block a user