GCC Code Coverage Report


Directory: QGVCore/
File: QGVCore/private/QGVCore.h
Date: 2024-12-03 11:07:38
Exec Total Coverage
Lines: 0 23 0.0%
Branches: 0 10 0.0%

Line Branch Exec Source
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 <QColor>
23 #include <QPainterPath>
24 #include <QPointF>
25 #include <QPolygonF>
26
27 // GraphViz headers
28 #include <cgraph.h>
29 #include <gvc.h>
30
31 const qreal DotDefaultDPI = 72.0;
32
33 /**
34 * @brief GraphViz to GraphicsScene conversions
35 *
36 */
37 class 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.id = &AgIdDisc;
97 disc.io = &memIoDisc;
98 g = agread(&rdr, &disc);
99 return g;
100 }
101 };
102
103 #endif // QGVCORE_H
104