You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nmWTAI-Platform/Include/iBase/iBase/ZxGraphviz.h

117 lines
3.0 KiB
C++

#pragma once
#include <QString>
#include <QHash>
#include <QMap>
#include <iBase_global.h>
#include <IxGraphViz.h>
class QTextStream;
class IxDynObj;
// 导出Graphviz图形的工具,内部使用
// http://www.graphviz.org
class I_BASE_EXPORT ZxGraphViz
{
public:
class Obj
{
public:
QString tooltip;
QString label;
QString color;
QString labelColor;
protected:
Obj();
virtual ~Obj();
int order;
virtual void _export(QTextStream & stream) = 0;
static bool compare(Obj* a, Obj* b);
friend class ZxGraphViz;
};
class Node : public Obj
{
public:
// box polygon ellipse circle
// point egg triangle plaintext
// diamond trapezium ellipse house
// pentagon hexagon septagon octagon
// doublecircle doubleoctagon tripleoctagon invtriangle
// invtrapezium invhouse Mdiamond Msquare
// Mcircle rect rectangle none
// note tab folder box3d
// component
QString shape;
const QString& getId() const;
private:
QString id;
int ancestor;
int descendant;
Node();
~Node();
void _export(QTextStream & stream);
friend class ZxGraphViz;
};
class Edge : public Obj
{
public:
// "normal" "inv"
// "dot" "invdot"
// "odot" "invodot"
// "none" "tee"
// "empty" "invempty"
// "diamond" "odiamond"
// "ediamond" "crow"
// "box" "obox"
// "open" "halfopen"
// "vee"
QString arrowHead; // diamond ediamond vee
QString arrowTail; //
private:
Node* head;
Node* tail;
Edge();
~Edge();
void _export(QTextStream & stream);
friend class ZxGraphViz;
};
ZxGraphViz();
~ZxGraphViz();
//void save(const QString& sPath, bool bConvert = true, bool bShowConvertedInShell = true);
QString exportTempPicture();
void exportTempToResPicture();
bool isAdded(IxGraphViz* p);
Node* getNode(IxGraphViz* p);
Node* addNode(IxGraphViz* p, int ancestor, int descendant);
Node* addWildNode(const QString& id);
Edge* addEdge(Node* head, Node* tail);
// 理论上NULL只有一个, 会导致大量箭头汇集到这个NULL上. 所以我们的NULL是分开的, 和对象绑定.
Node* getNull(void* obj, quint64 id = 0);
struct HT
{
Node* h;
Node* t;
bool operator==(const HT & r) const
{ return h == r.h && t == r.t; }
bool operator<(const HT & r) const
{ return h == r.h ? t < r.t : h < r.h; }
};
IxGraphViz* wrap(QObject* p);
private:
void finish();
bool finished;
Node* _node(const QString& id, bool &add);
QHash<QString, Node*> nodes;
QMap<HT, Edge*> edges;
QHash<QObject *, IxGraphViz *> qobjects;
};