summaryrefslogtreecommitdiffstats
path: root/filters/kspread/csv/xmltree.cc
blob: f5c56373a89c46db90ba0e693a028fc47ba18908 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/* This file is part of the KDE project
   Copyright (C) 1999 David Faure <faure@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <xmltree.h>

#include <tqdatetime.h>
#include <kdebug.h>


XMLTree::XMLTree(TQDomDocument &qdoc) : root(qdoc)
{
  root=TQDomDocument("spreadsheet");
  root.appendChild( root.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
  doc = root.createElement( "spreadsheet" );

  doc.setAttribute("editor", "KSpread CSV Filter");
  doc.setAttribute("mime", "application/x-kspread");
  root.appendChild(doc);

  TQDomElement paper = root.createElement("paper");
  paper.setAttribute("format", "A4");
  paper.setAttribute("orientation", "Portrait");
  TQDomElement borders = root.createElement( "borders" );
  borders.setAttribute( "left", 20 );
  borders.setAttribute( "top", 20 );
  borders.setAttribute( "right", 20 );
  borders.setAttribute( "bottom", 20 );
  paper.appendChild( borders );
  doc.appendChild(paper);

  map = root.createElement("map");
  doc.appendChild(map);

  sheet = root.createElement("table");

  sheet.setAttribute("name", "foobar");
  map.appendChild(sheet);

  row = 1;
  column = 1;
}

XMLTree::~XMLTree()
{
    //if(root)      // We're using fancy references, now! (Werner)
    //delete root;
}

// Not needed anymore (Werner)
//const TQString XMLTree::part()
//{
//  TQString s;
//  TQTextStream t(s, IO_WriteOnly);

//  TQTime tmr;
//  tmr.start();
//  kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;

//  root.save(t);  // Why does this take sooooo long (approx. 8s on my Athlon 500 with a
                 // quite small file :( )

// David: gdb says that TQString::replace calls itself recursively an enormous amount of time
// This is called by TQStringBuffer::writeBlock (), called by TQTextStream::writeBlock ()
// called by TQTextStream::operator<< () in TQDOM_AttrPrivate::save ().
//
// And this looks related to the UTF 8 encoding ...

//  kdDebug(30501) << (const char*)TQString::number((int)tmr.elapsed()) << endl;
//  kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;

//  t << '\0';

//  return s;
//}

bool XMLTree::cell( const TQString & contents )
{
  TQDomElement e = root.createElement("cell");
  //e.appendChild(getFormat(xf));
  //e.appendChild(getFont(xf));

  e.setAttribute("row", row);
  e.setAttribute("column", column++);

  TQDomElement format=root.createElement("format");
  format.setAttribute("float", "3");
  format.setAttribute("alignY", "2");
  format.setAttribute("floatcolor", "2");
  format.setAttribute("faktor", "1");
  format.setAttribute("precision", "-1");
  format.setAttribute("align", "4");

  TQDomElement pen=root.createElement("pen");
  pen.setAttribute("width", "1");
  pen.setAttribute("style", "0");
  pen.setAttribute("color", "#000000");

  TQDomElement lborder=root.createElement("left-border");
  lborder.appendChild(pen);
  format.appendChild(lborder);

  pen=root.createElement("pen");
  pen.setAttribute("width", "1");
  pen.setAttribute("style", "0");
  pen.setAttribute("color", "#000000");

  TQDomElement tborder=root.createElement("top-border");
  tborder.appendChild(pen);
  format.appendChild(tborder);

  pen=root.createElement("pen");
  pen.setAttribute("width", "1");
  pen.setAttribute("style", "0");
  pen.setAttribute("color", "#000000");

  TQDomElement fdia=root.createElement("fall-diagonal");
  fdia.appendChild(pen);
  format.appendChild(fdia);

  pen=root.createElement("pen");
  pen.setAttribute("width", "1");
  pen.setAttribute("style", "0");
  pen.setAttribute("color", "#000000");

  TQDomElement udia=root.createElement("up-diagonal");
  udia.appendChild(pen);
  format.appendChild(udia);

  e.appendChild(format);

  TQDomElement text=root.createElement("text");
  text.appendChild(root.createTextNode(contents));
  e.appendChild(text);

  sheet.appendChild(e);

  return true;
}