Graph Library - ns3098/Graph_Visualiser GitHub Wiki

You can use my graph library in your projects. Just add GraphBuilder/Logic/AbstractGraph directory to your project and then #include "AbstractGraph/abstractgraph.h".

Contents

  1. Classes
  2. Structures
  3. GraphModel
  4. AbstractGraph
  5. Graph I/O to QDataStream

Classes

Graph library have 2 main classes:

  • AbstractGraph -- for editing and displaying graph
  • GraphModel -- for saving graph
    • VectorListGS -- Vector list
    • RibListGS -- Merge list
    • MatrixGS -- Adjacency matrix

AbstractGraph located in abstractgraph.h file.

GraphModel located in graph_save_struct.h file.

Structures

Graph library have 3 main structures, located in graph_struct_decl.h and abstractgraph_header.h:

  • TvertexInfo -- contains information about vertex parameters
  • TribInfo -- contains information about merge parameters
  • ABrib -- for merge

TvertexInfo have next parameters:

struct TvertexInfo{
    // Functions ...

    int x, y, radius;
    int number, degree;
    QColor color;
    QString text;
    bool hidden;
};

TribInfo have next parameters:

struct TribInfo{
    // Functions ...

    int from, to, weight;
    QColor color;
    QString text;
    bool hidden;
};

ABrib have next parameters:

struct ABrib{
    // Functions ...

    int from, to;
};

GraphModel

This class use for saving graph. It contains all vertexes and merges.

You can save AbstractGraph to GraphModel and load GraphModel to AbstractGraph using this code:

AbstractGraph *ag;
GraphModel gm;

gm = ag->getGraphModel();    // save
ag->setGraphModel(gm);       // load

You can convert GraphModel to:

    // Vector list
struct VLGraphRib{int to, weight;};
typedef QVector < QVector <VLGraphRib> > VectorListGS;

    // Rib list
struct RLGraphItem{int from, to, weight;};
typedef QVector <RLGraphItem> RibListGS;

    // Adjacency matrix
typedef QVector< QVector<int> > MatrixGS;

Using this functions:

VectorListGS    toVectorList();
RibListGS       toRibList();
MatrixGS        toMatrix();

AbstractGraph

This object class use to edit and display graph.

To edit graph use this functions:

bool addVertex      (int px, int py, const TvertexInfo &vi = TvertexInfo());
bool updateVertex   (int v,          const TvertexInfo &vi);
bool moveVertex     (int v,  int px, int py);
bool removeVertex   (int v);

bool addRib         (const ABrib r, const TribInfo &ri = TribInfo());
bool updateRib      (const ABrib r, const TribInfo &ri);
bool removeRib      (const ABrib r);

void setOriented(bool io);
void clear();

To get information about elements use this functions:

bool isOriented  () const;
int  vertexCount () const;
int  ribCount    () const;
TvertexInfo getVertexInfo   (int v)             const;
TribInfo    getRibInfo      (const ABrib &r)    const;

Also, you can edit vertexes and ribs using AG_CHANGE_VER_PARAM(AG, ver, param, val) and AG_CHANGE_RIB_PARAM(AG, rib, param, val) macro. For example

AbstractGraph *gr;
AG_CHANGE_VER_PARAM((*gr), 2, color, "#00FF00")

Some useful functions:

QRect       vertexToRound   (int v)                                     const;
QLine       ribToLine       (const ABrib &r)                            const;
int         findVertex      (int px, int py, int r = 0, int exept = -1) const;
ABrib       findRib         (int px, int py, int r = 0)                 const;
bool        isRibExist      (const ABrib &r)                            const;

When graph changes, AbstractGraph emit this signals:

                // Vertex changes
void atVertexAdd    (int=0);    void vertexAdded    (int=0);
void atVertexUpdate (int=0);    void vertexUpdated  (int=0);
void atVertexMove   (int=0);    void vertexMoved    (int=0);
void atVertexRemove (int=0);    void vertexRemoved  (int=0);

                // Rib changes
void atRibAdd    (ABrib=ABrib());   void ribAdded   (ABrib=ABrib());
void atRibUpdate (ABrib=ABrib());   void ribUpdated (ABrib=ABrib());
void atRibRemove (ABrib=ABrib());   void ribRemoved (ABrib=ABrib());

                // Other changes
void atOrientChanged ();    void orientChanged  ();
void atClear         ();    void cleared        ();
void aboutToChange   ();    void changed        ();

First column emits before change and second column emits after change.

Graph I/O to QDataStream

Include #include "AbstractGraph/graphio.h" and use this code:

QDataStream io;
AbstractGraph *ag;
GraphModel gm;
io >> gm; // load
io << gm; // save
⚠️ **GitHub.com Fallback** ⚠️