Yannick Shpilka , cleaned up
[kgraphinterface.git] / src / gihandler.cpp
blob26591a96bd37b7e776ab0ec4d75c39094b166b80
1 /***************************************************************************
2 * Copyright (C) 2007 by Schpilka Yannick *
3 * schpilka@localhost *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 * *
20 * In addition, as a special exception, the copyright holders give *
21 * permission to link the code of this program with any edition of *
22 * the Qt library by Trolltech AS, Norway (or with modified versions *
23 * of Qt that use the same license as Qt), and distribute linked *
24 * combinations including the two. You must obey the GNU General *
25 * Public License in all respects for all of the code used other than *
26 * Qt. If you modify this file, you may extend this exception to *
27 * your version of the file, but you are not obligated to do so. If *
28 * you do not wish to do so, delete this exception statement from *
29 * your version. *
30 ***************************************************************************/
31 #include "gihandler.h"
32 #include "graph.h"
33 #include "node.h"
34 #include <qmessagebox.h>
36 #include <qpushbutton.h>
37 #include <qtextedit.h>
38 #include <qimage.h>
39 #include <qpixmap.h>
41 GIHandler::GIHandler(Graph *g){
42 graph = g;
43 nbr = 0;
47 GIHandler::~GIHandler(){
51 bool GIHandler::startElement(const QString &,
52 const QString &,
53 const QString &qName,
54 const QXmlAttributes &att){
57 if (!giTag && qName != "gi"){
58 erreur = QObject::tr("This file is not supported, gi required");
59 return false;
62 if (qName == "gi"){
63 QString v = att.value("version");
64 if (!v.isEmpty() && v != "1.0"){
65 erreur = QObject::tr("This file is not a GI version 1.0 file");
66 return false;
68 giTag = true;
71 else if(qName =="graph"){
72 QString v = att.value("id");
73 if (v.isEmpty())
74 v = "untitled";
76 graph->setName(v);
79 else if(qName =="node"){
80 current_node = att.value("id");
81 c_node = new Node(graph,current_node);
82 int x = att.value("x").toInt();
83 int y = att.value("y").toInt();
84 graph->add(c_node,QPoint(x,y));
87 else if(qName =="edge"){
88 QString n1 = att.value("source");
89 QString n2 = att.value("dest");
90 QString type = att.value("type");
91 int dir = att.value("direction").toInt();
92 graph->link(n1,n2);
95 /**
96 else if (NodeContent::typeByName( qName ) > 0) {
97 int t = NodeContent::typeByName( qName );
98 NodeContent *c = new NodeContent(c_node,t,nbr++);
99 if (c->isNull()){
100 erreur = QObject::tr("Cannot load " + qName + "content");
101 return false;
103 QString url = att.value("url");
104 if (!url.isEmpty()){
105 c->open( url );
106 c_node->push(c);
110 buffer = "";
111 return true;
114 bool GIHandler::endElement (const QString &,
115 const QString &,
116 const QString &qName){
117 if (qName == "gi")
118 graph->repaint();
119 else if(qName =="node"){
120 current_node = "";
121 c_node = 0;
123 return true;
126 bool GIHandler::characters (const QString &txt){
127 buffer += txt;
128 return true;
131 bool GIHandler::fatalError (const QXmlParseException &exception){
132 QMessageBox::critical (graph,
133 QObject::tr("Graph Interface Parser"),
134 QObject::tr("Parse error at line %1, column %2:\n""%3")
135 .arg(exception.lineNumber())
136 .arg(exception.columnNumber())
137 .arg(exception.message()));
138 return false;
141 QString GIHandler::errorString() const{
142 return erreur;