summaryrefslogtreecommitdiff
path: root/src/data/tikzassembler.cpp
blob: 456464a654dd4b704cfd0c88eb65ec15e17dbd43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "tikzassembler.h"

#include "tikzparserdefs.h"
#include "tikzparser.parser.hpp"
#include "tikzlexer.h"

int yyparse(void *scanner);

TikzAssembler::TikzAssembler(Graph *graph, QObject *parent) :
    QObject(parent), _graph(graph), _project(0)
{
    yylex_init(&scanner);
    yyset_extra(this, scanner);
}

TikzAssembler::TikzAssembler(Project *project, QObject *parent) :
    QObject(parent), _graph(0), _project(project)
{
    yylex_init(&scanner);
    yyset_extra(this, scanner);
}

void TikzAssembler::addNodeToMap(Node *n) { _nodeMap.insert(n->name(), n); }
Node *TikzAssembler::nodeWithName(QString name) { return _nodeMap[name]; }

bool TikzAssembler::parse(const QString &tikz)
{
    yy_scan_string(tikz.toLatin1().data(), scanner);
    int result = yyparse(scanner);

    if (result == 0) return true;
    else return false;
}

Graph *TikzAssembler::graph() const
{
    return _graph;
}

Project *TikzAssembler::project() const
{
    return _project;
}

bool TikzAssembler::isGraph() const
{
    return _graph != 0;
}

bool TikzAssembler::isProject() const
{
    return _project != 0;
}