124 lines
3.2 KiB
C++
124 lines
3.2 KiB
C++
#pragma once
|
|
#include <QRectF>
|
|
#include <QGraphicsItem>
|
|
#include <QGraphicsView>
|
|
#include <QGraphicsScene>
|
|
#include <memory>
|
|
#include "data_type.h"
|
|
#include "dag_layout.h"
|
|
|
|
|
|
namespace dags {
|
|
enum class GraphNodeType {
|
|
ActivePresentNode,
|
|
PenetrateNode,
|
|
TransitionCurve,
|
|
};
|
|
|
|
class IGraphNode {
|
|
public:
|
|
virtual GraphNodeType nodeType() const = 0;
|
|
virtual void highlight(bool mark) = 0;
|
|
virtual bool isHighlighted() const = 0;
|
|
|
|
virtual QRectF boundingRect() const = 0;
|
|
virtual QPointF pos() const = 0;
|
|
virtual void setPos(qreal x, qreal y) = 0;
|
|
};
|
|
|
|
class __GraphNodeBase : public QGraphicsItem, public IGraphNode {
|
|
private:
|
|
GraphNodeType _node_type;
|
|
bool _highlight_mark = false;
|
|
|
|
public:
|
|
__GraphNodeBase(GraphNodeType t);
|
|
|
|
// Inherited via IGraphNode
|
|
GraphNodeType nodeType() const override;
|
|
void highlight(bool mark) override;
|
|
bool isHighlighted() const override;
|
|
QPointF pos() const override;
|
|
void setPos(qreal x, qreal y) override;
|
|
};
|
|
|
|
enum class PrsnType {
|
|
StartNode,
|
|
NormalNode,
|
|
};
|
|
class ActivePresentNode : public __GraphNodeBase {
|
|
private:
|
|
PrsnType node_type = PrsnType::NormalNode;
|
|
QString node_name;
|
|
QFontMetricsF measure_base;
|
|
|
|
public:
|
|
ActivePresentNode(const QString name, PrsnType type, QFont font);
|
|
QString nodeName() const;
|
|
|
|
// ͨ¹ý QGraphicsItem ¼Ì³Ð
|
|
QRectF boundingRect() const override;
|
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
|
};
|
|
class PenetrateNode : public __GraphNodeBase {
|
|
private:
|
|
double width_store = 20;
|
|
QString from_name, to_name;
|
|
|
|
public:
|
|
PenetrateNode(double width, const QString &from, const QString &to);
|
|
|
|
void resizeWidth(double width);
|
|
QString nodeFrom() const;
|
|
QString nodeTo() const;
|
|
|
|
// ͨ¹ý QGraphicsItem ¼Ì³Ð
|
|
QRectF boundingRect() const override;
|
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
|
};
|
|
class TransitionCurve : public __GraphNodeBase {
|
|
private:
|
|
IGraphNode* start_node, * end_node;
|
|
double prev_layer_w = 0;
|
|
QRectF outline;
|
|
|
|
public:
|
|
TransitionCurve(IGraphNode* start, IGraphNode* end, double prev_layer_width);
|
|
|
|
void layoutRefresh();
|
|
QString nodeFrom() const;
|
|
QString nodeTo() const;
|
|
|
|
// ͨ¹ý QGraphicsItem ¼Ì³Ð
|
|
QRectF boundingRect() const override;
|
|
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) override;
|
|
};
|
|
|
|
class DAGActiveView : public QGraphicsView {
|
|
Q_OBJECT
|
|
private:
|
|
double layer_span = 200;
|
|
double node_span = 10;
|
|
QGraphicsScene scene_bind;
|
|
QList<IGraphNode*> highlight_nodelist;
|
|
QList<IGraphNode*> total_graph_nodes;
|
|
|
|
signals:
|
|
void nodeClicked(const QPointF &pos, const QList<QString> &node_name);
|
|
|
|
public:
|
|
DAGActiveView(QWidget* parent = nullptr);
|
|
|
|
void updateWithEdges(QList<graph_data::Arrow> arrows);
|
|
void highlightGraphLink(const QList<graph_data::Arrow> color_path);
|
|
|
|
// QGraphicsView
|
|
virtual void mousePressEvent(QMouseEvent *ev) override;
|
|
|
|
private:
|
|
QList<IGraphNode*> layer_nodes_construction(const QHash<IGraphNode*, std::shared_ptr<dags::DAGOrderHelper>>& prev_layer,
|
|
const QList<std::shared_ptr<dags::DAGOrderHelper>>& total_datas, int layer_idx = 0, double prev_layer_end = 0);
|
|
};
|
|
};
|
|
|