DiagramDesigner/common/include/global.h

156 lines
4.1 KiB
C++

#ifndef GLOBAL_H
#define GLOBAL_H
#include <QGraphicsItem>
#include <QtCore/QMetaObject>
#include <QtSwap>
#include <QHash>
const double g_dGriaphicsScene_Width = 800;
const double g_dGriaphicsScene_Height = 600;
//Q_NAMESPACE
enum GraphicsItemType
{
GIT_base = QGraphicsItem::UserType + 1,
GIT_line = QGraphicsItem::UserType + 2,
GIT_rect = QGraphicsItem::UserType + 3,
GIT_roundRect = QGraphicsItem::UserType + 4,
GIT_ellipse = QGraphicsItem::UserType + 5,
GIT_polygon = QGraphicsItem::UserType + 6,
//======================================
GIT_bus = QGraphicsItem::UserType + 50,
GIT_itemRect = QGraphicsItem::UserType + 51,
GIT_itemTri = QGraphicsItem::UserType + 52,
GIT_link= QGraphicsItem::UserType + 53
};
enum DiagramMode //组态图模式
{
DM_edit = 0,
DM_run
};
//Q_ENUM_NS(GraphicsItemType)
/**
* Constants used for fetching QVariant data from GraphModel.
*/
enum class NodeRole {
Type = 0, ///< Type of the current node, usually a string.
Position = 1, ///< `QPointF` positon of the node on the scene.
Size = 2, ///< `QSize` for resizable nodes.
CaptionVisible = 3, ///< `bool` for caption visibility.
Caption = 4, ///< `QString` for node caption.
Style = 5, ///< Custom NodeStyle as QJsonDocument
InternalData = 6, ///< Node-stecific user data as QJsonObject
InPortCount = 7, ///< `unsigned int`
OutPortCount = 9, ///< `unsigned int`
Widget = 10, ///< Optional `QWidget*` or `nullptr`
};
//Q_ENUM_NS(NodeRole)
/**
* Specific flags regulating node features and appeaarence.
*/
enum NodeFlag {
NoFlags = 0x0, ///< Default NodeFlag
Resizable = 0x1, ///< Lets the node be resizable
Locked = 0x2
};
Q_DECLARE_FLAGS(NodeFlags, NodeFlag)
//Q_FLAG_NS(NodeFlags)
Q_DECLARE_OPERATORS_FOR_FLAGS(NodeFlags)
/**
* Constants for fetching port-related information from the GraphModel.
*/
enum class PortRole {
Data = 0, ///< `std::shared_ptr<NodeData>`.
DataType = 1, ///< `QString` describing the port data type.
ConnectionPolicyRole = 2, ///< `enum` ConnectionPolicyRole
CaptionVisible = 3, ///< `bool` for caption visibility.
Caption = 4, ///< `QString` for port caption.
};
//Q_ENUM_NS(PortRole)
/**
* Defines how many connections are possible to attach to ports. The
* values are fetched using PortRole::ConnectionPolicy.
*/
enum class ConnectionPolicy {
One, ///< Just one connection for each port.
Many, ///< Any number of connections possible for the port.
};
//Q_ENUM_NS(ConnectionPolicy)
/**
* Used for distinguishing input and output node ports.
*/
enum class PortType {
In = 0, ///< Input node port (from the left).
Out = 1, ///< Output node port (from the right).
None = 2
};
//Q_ENUM_NS(PortType)
enum PortState
{
P_const = 0, //固定端口
p_movable, //移动端口
};
using PortCount = int;
/// ports are consecutively numbered starting from zero.
using PortIndex = int;
const PortIndex InvalidPortIndex = -1;
/// Unique Id associated with each node in the GraphModel.
using NodeId = int;
const NodeId InvalidNodeId = -1;
/**
* A unique connection identificator that stores
* out `NodeId`, out `PortIndex`, in `NodeId`, in `PortIndex`
*/
struct ConnectionId
{
int conId;
NodeId outNodeId;
PortIndex outPortIndex;
NodeId inNodeId;
PortIndex inPortIndex;
};
inline uint qHash(const ConnectionId &data, uint seed){
return data.conId;
}
inline bool operator<(ConnectionId const &a, ConnectionId const &b)
{
return a.conId<b.conId;
}
inline bool operator==(ConnectionId const &a, ConnectionId const &b)
{
return a.outNodeId == b.outNodeId && a.outPortIndex == b.outPortIndex
&& a.inNodeId == b.inNodeId && a.inPortIndex == b.inPortIndex;
}
inline bool operator!=(ConnectionId const &a, ConnectionId const &b)
{
return !(a == b);
}
inline void invertConnection(ConnectionId &id)
{
qSwap(id.outNodeId, id.inNodeId);
qSwap(id.outPortIndex, id.inPortIndex);
}
#endif