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