QGVCore.h
Go to the documentation of this file.
1 /***************************************************************
2 QGVCore
3 Copyright (c) 2014, Bergont Nicolas, All rights reserved.
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 3.0 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library.
17 ***************************************************************/
18 
19 #ifndef QGVCORE_H
20 #define QGVCORE_H
21 
22 #include <QPointF>
23 #include <QPolygonF>
24 #include <QPainterPath>
25 #include <QColor>
26 
27 //GraphViz headers
28 #include <gvc.h>
29 #include <cgraph.h>
30 
31 const qreal DotDefaultDPI = 72.0;
32 
37 class QGVCore
38 {
39 public:
40  static qreal graphHeight(Agraph_t *graph);
41  static bool gvToQtPos(QString att, qreal dpi, qreal gheight, QPointF& pos);
42  static QString qtToGvPos (QPointF pos, qreal gheight);
43  static QPointF toPoint(pointf p, qreal gheight);
44  static QPointF toPoint(point p, qreal gheight);
45  static QPointF centerToOrigin(const QPointF &p, qreal width, qreal height);
46  static QPolygonF toPolygon(const polygon_t* poly, qreal width, qreal height);
47 
48  static QPainterPath toPath(const char *type, const polygon_t *poly, qreal width, qreal height);
49  static QPainterPath toPath(const splines* spl, qreal gheight);
50 
51  static Qt::BrushStyle toBrushStyle(const QString &style);
52  static Qt::PenStyle toPenStyle(const QString &style);
53  static int toPenWidth(const QString &width);
54  static QColor toColor(const QString &color);
55 
56  typedef struct {
57  const char *data;
58  int len;
59  int cur;
60  } rdr_t;
61 
62  static int memiofread(void *chan, char *buf, int bufsize)
63  {
64  const char *ptr;
65  char *optr;
66  char c;
67  int l;
68  rdr_t *s;
69 
70  if (bufsize == 0) return 0;
71  s = (rdr_t *) chan;
72  if (s->cur >= s->len)
73  return 0;
74  l = 0;
75  ptr = s->data + s->cur;
76  optr = buf;
77  do {
78  *optr++ = c = *ptr++;
79  l++;
80  } while (c && (c != '\n') && (l < bufsize));
81  s->cur += l;
82  return l;
83  }
84 
85  static Agraph_t *agmemread2(const char *cp)
86  {
87  Agraph_t* g;
88  rdr_t rdr;
89  Agdisc_t disc;
90  Agiodisc_t memIoDisc;
91 
92  memIoDisc.afread = memiofread;
93  memIoDisc.putstr = AgIoDisc.putstr;
94  memIoDisc.flush = AgIoDisc.flush;
95  rdr.data = cp;
96  rdr.len = strlen(cp);
97  rdr.cur = 0;
98 
99  disc.mem = &AgMemDisc;
100  disc.id = &AgIdDisc;
101  disc.io = &memIoDisc;
102  g = agread (&rdr, &disc);
103  return g;
104  }
105 };
106 
107 #endif // QGVCORE_H
static QPointF centerToOrigin(const QPointF &p, qreal width, qreal height)
Definition: QGVCore.cpp:59
int cur
Definition: QGVCore.h:59
static qreal graphHeight(Agraph_t *graph)
Definition: QGVCore.cpp:21
static QPointF toPoint(pointf p, qreal gheight)
Definition: QGVCore.cpp:47
const qreal DotDefaultDPI
Definition: QGVCore.h:31
static bool gvToQtPos(QString att, qreal dpi, qreal gheight, QPointF &pos)
Definition: QGVCore.cpp:27
const char * data
Definition: QGVCore.h:57
static QPolygonF toPolygon(const polygon_t *poly, qreal width, qreal height)
Definition: QGVCore.cpp:65
static int memiofread(void *chan, char *buf, int bufsize)
Definition: QGVCore.h:62
static Qt::PenStyle toPenStyle(const QString &style)
Definition: QGVCore.cpp:140
GraphViz to GraphicsScene conversions.
Definition: QGVCore.h:37
static QPainterPath toPath(const char *type, const polygon_t *poly, qreal width, qreal height)
Definition: QGVCore.cpp:79
int len
Definition: QGVCore.h:58
static Qt::BrushStyle toBrushStyle(const QString &style)
Definition: QGVCore.cpp:131
static QString qtToGvPos(QPointF pos, qreal gheight)
Definition: QGVCore.cpp:39
static QColor toColor(const QString &color)
Definition: QGVCore.cpp:159
Definition: QGVCore.h:56
static Agraph_t * agmemread2(const char *cp)
Definition: QGVCore.h:85
static int toPenWidth(const QString &width)
Definition: QGVCore.cpp:151