xmltree.cpp
1/* This file is part of the KDE project
2 Copyright (C) 1999 David Faure <faure@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <xmltree.h>
21
22#include <tqdatetime.h>
23#include <kdebug.h>
24
25
26XMLTree::XMLTree(TQDomDocument &qdoc) : root(qdoc)
27{
28 root=TQDomDocument("spreadsheet");
29 root.appendChild( root.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
30 doc = root.createElement( "spreadsheet" );
31
32 doc.setAttribute("editor", "KSpread CSV Filter");
33 doc.setAttribute("mime", "application/x-kspread");
34 root.appendChild(doc);
35
36 TQDomElement paper = root.createElement("paper");
37 paper.setAttribute("format", "A4");
38 paper.setAttribute("orientation", "Portrait");
39 TQDomElement borders = root.createElement( "borders" );
40 borders.setAttribute( "left", 20 );
41 borders.setAttribute( "top", 20 );
42 borders.setAttribute( "right", 20 );
43 borders.setAttribute( "bottom", 20 );
44 paper.appendChild( borders );
45 doc.appendChild(paper);
46
47 map = root.createElement("map");
48 doc.appendChild(map);
49
50 sheet = root.createElement("table");
51
52 sheet.setAttribute("name", "foobar");
53 map.appendChild(sheet);
54
55 row = 1;
56 column = 1;
57}
58
59XMLTree::~XMLTree()
60{
61 //if(root) // We're using fancy references, now! (Werner)
62 //delete root;
63}
64
65// Not needed anymore (Werner)
66//const TQString XMLTree::part()
67//{
68// TQString s;
69// TQTextStream t(s, IO_WriteOnly);
70
71// TQTime tmr;
72// tmr.start();
73// kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
74
75// root.save(t); // Why does this take sooooo long (approx. 8s on my Athlon 500 with a
76 // quite small file :( )
77
78// David: gdb says that TQString::replace calls itself recursively an enormous amount of time
79// This is called by TQStringBuffer::writeBlock (), called by TQTextStream::writeBlock ()
80// called by TQTextStream::operator<< () in TQDOM_AttrPrivate::save ().
81//
82// And this looks related to the UTF 8 encoding ...
83
84// kdDebug(30501) << (const char*)TQString::number((int)tmr.elapsed()) << endl;
85// kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
86
87// t << '\0';
88
89// return s;
90//}
91
92bool XMLTree::cell( const TQString & contents )
93{
94 TQDomElement e = root.createElement("cell");
95 //e.appendChild(getFormat(xf));
96 //e.appendChild(getFont(xf));
97
98 e.setAttribute("row", row);
99 e.setAttribute("column", column++);
100
101 TQDomElement format=root.createElement("format");
102 format.setAttribute("float", "3");
103 format.setAttribute("alignY", "2");
104 format.setAttribute("floatcolor", "2");
105 format.setAttribute("faktor", "1");
106 format.setAttribute("precision", "-1");
107 format.setAttribute("align", "4");
108
109 TQDomElement pen=root.createElement("pen");
110 pen.setAttribute("width", "1");
111 pen.setAttribute("style", "0");
112 pen.setAttribute("color", "#000000");
113
114 TQDomElement lborder=root.createElement("left-border");
115 lborder.appendChild(pen);
116 format.appendChild(lborder);
117
118 pen=root.createElement("pen");
119 pen.setAttribute("width", "1");
120 pen.setAttribute("style", "0");
121 pen.setAttribute("color", "#000000");
122
123 TQDomElement tborder=root.createElement("top-border");
124 tborder.appendChild(pen);
125 format.appendChild(tborder);
126
127 pen=root.createElement("pen");
128 pen.setAttribute("width", "1");
129 pen.setAttribute("style", "0");
130 pen.setAttribute("color", "#000000");
131
132 TQDomElement fdia=root.createElement("fall-diagonal");
133 fdia.appendChild(pen);
134 format.appendChild(fdia);
135
136 pen=root.createElement("pen");
137 pen.setAttribute("width", "1");
138 pen.setAttribute("style", "0");
139 pen.setAttribute("color", "#000000");
140
141 TQDomElement udia=root.createElement("up-diagonal");
142 udia.appendChild(pen);
143 format.appendChild(udia);
144
145 e.appendChild(format);
146
147 TQDomElement text=root.createElement("text");
148 text.appendChild(root.createTextNode(contents));
149 e.appendChild(text);
150
151 sheet.appendChild(e);
152
153 return true;
154}