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 QPointF toPoint(pointf p, qreal gheight);
42  static QPointF toPoint(point p, qreal gheight);
43  static QPointF centerToOrigin(const QPointF &p, qreal width, qreal height);
44  static QPolygonF toPolygon(const polygon_t* poly, qreal width,
45  qreal height);
46 
47  static QPainterPath toPath(const char *type, const polygon_t *poly,
48  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 QColor toColor(const QString &color);
54 
55  typedef struct {
56  const char *data;
57  int len;
58  int cur;
59  } rdr_t;
60 
61  static int memiofread(void *chan, char *buf, int bufsize)
62  {
63  const char *ptr;
64  char *optr;
65  char c;
66  int l;
67  rdr_t *s;
68 
69  if (bufsize == 0) return 0;
70  s = static_cast<rdr_t *>(chan);
71  if (s->cur >= s->len)
72  return 0;
73  l = 0;
74  ptr = s->data + s->cur;
75  optr = buf;
76  do {
77  *optr++ = c = *ptr++;
78  l++;
79  } while (c && (c != '\n') && (l < bufsize));
80  s->cur += l;
81  return l;
82  }
83 
84  static Agraph_t *agmemread2(const char *cp)
85  {
86  Agraph_t* g;
87  rdr_t rdr;
88  Agdisc_t disc;
89  Agiodisc_t memIoDisc;
90 
91  memIoDisc.afread = memiofread;
92  memIoDisc.putstr = AgIoDisc.putstr;
93  memIoDisc.flush = AgIoDisc.flush;
94  rdr.data = cp;
95  rdr.len = strlen(cp);
96  rdr.cur = 0;
97 
98  disc.mem = &AgMemDisc;
99  disc.id = &AgIdDisc;
100  disc.io = &memIoDisc;
101  g = agread(&rdr, &disc);
102  return g;
103  }
104 };
105 
106 #endif
int cur
Definition: QGVCore.h:58
static QPointF centerToOrigin(const QPointF &p, qreal width, qreal height)
static QPolygonF toPolygon(const polygon_t *poly, qreal width, qreal height)
static qreal graphHeight(Agraph_t *graph)
const qreal DotDefaultDPI
Definition: QGVCore.h:31
static Qt::PenStyle toPenStyle(const QString &style)
static QPainterPath toPath(const char *type, const polygon_t *poly, qreal width, qreal height)
const char * data
Definition: QGVCore.h:56
static int memiofread(void *chan, char *buf, int bufsize)
Definition: QGVCore.h:61
GraphViz to GraphicsScene conversions.
Definition: QGVCore.h:37
int len
Definition: QGVCore.h:57
static QPointF toPoint(pointf p, qreal gheight)
static QColor toColor(const QString &color)
static Qt::BrushStyle toBrushStyle(const QString &style)
Definition: QGVCore.h:55
static Agraph_t * agmemread2(const char *cp)
Definition: QGVCore.h:84