filters

xmltree.cc

00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 David Faure <faure@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <xmltree.h>
00021 
00022 #include <qdatetime.h>
00023 #include <kdebug.h>
00024 
00025 
00026 XMLTree::XMLTree(QDomDocument &qdoc) : root(qdoc)
00027 {
00028   root=QDomDocument("spreadsheet");
00029   root.appendChild( root.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" ) );
00030   doc = root.createElement( "spreadsheet" );
00031 
00032   doc.setAttribute("editor", "KSpread CSV Filter");
00033   doc.setAttribute("mime", "application/x-kspread");
00034   root.appendChild(doc);
00035 
00036   QDomElement paper = root.createElement("paper");
00037   paper.setAttribute("format", "A4");
00038   paper.setAttribute("orientation", "Portrait");
00039   QDomElement borders = root.createElement( "borders" );
00040   borders.setAttribute( "left", 20 );
00041   borders.setAttribute( "top", 20 );
00042   borders.setAttribute( "right", 20 );
00043   borders.setAttribute( "bottom", 20 );
00044   paper.appendChild( borders );
00045   doc.appendChild(paper);
00046 
00047   map = root.createElement("map");
00048   doc.appendChild(map);
00049 
00050   sheet = root.createElement("table");
00051 
00052   sheet.setAttribute("name", "foobar");
00053   map.appendChild(sheet);
00054 
00055   row = 1;
00056   column = 1;
00057 }
00058 
00059 XMLTree::~XMLTree()
00060 {
00061     //if(root)      // We're using fancy references, now! (Werner)
00062     //delete root;
00063 }
00064 
00065 // Not needed anymore (Werner)
00066 //const QString XMLTree::part()
00067 //{
00068 //  QString s;
00069 //  QTextStream t(s, IO_WriteOnly);
00070 
00071 //  QTime tmr;
00072 //  tmr.start();
00073 //  kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
00074 
00075 //  root.save(t);  // Why does this take sooooo long (approx. 8s on my Athlon 500 with a
00076                  // quite small file :( )
00077 
00078 // David: gdb says that QString::replace calls itself recursively an enormous amount of time
00079 // This is called by QStringBuffer::writeBlock (), called by QTextStream::writeBlock ()
00080 // called by QTextStream::operator<< () in QDOM_AttrPrivate::save ().
00081 //
00082 // And this looks related to the UTF 8 encoding ...
00083 
00084 //  kdDebug(30501) << (const char*)QString::number((int)tmr.elapsed()) << endl;
00085 //  kdDebug(30501) << "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
00086 
00087 //  t << '\0';
00088 
00089 //  return s;
00090 //}
00091 
00092 bool XMLTree::cell( const QString & contents )
00093 {
00094   QDomElement e = root.createElement("cell");
00095   //e.appendChild(getFormat(xf));
00096   //e.appendChild(getFont(xf));
00097 
00098   e.setAttribute("row", row);
00099   e.setAttribute("column", column++);
00100 
00101   QDomElement format=root.createElement("format");
00102   format.setAttribute("float", "3");
00103   format.setAttribute("alignY", "2");
00104   format.setAttribute("floatcolor", "2");
00105   format.setAttribute("faktor", "1");
00106   format.setAttribute("precision", "-1");
00107   format.setAttribute("align", "4");
00108 
00109   QDomElement pen=root.createElement("pen");
00110   pen.setAttribute("width", "1");
00111   pen.setAttribute("style", "0");
00112   pen.setAttribute("color", "#000000");
00113 
00114   QDomElement lborder=root.createElement("left-border");
00115   lborder.appendChild(pen);
00116   format.appendChild(lborder);
00117 
00118   pen=root.createElement("pen");
00119   pen.setAttribute("width", "1");
00120   pen.setAttribute("style", "0");
00121   pen.setAttribute("color", "#000000");
00122 
00123   QDomElement tborder=root.createElement("top-border");
00124   tborder.appendChild(pen);
00125   format.appendChild(tborder);
00126 
00127   pen=root.createElement("pen");
00128   pen.setAttribute("width", "1");
00129   pen.setAttribute("style", "0");
00130   pen.setAttribute("color", "#000000");
00131 
00132   QDomElement fdia=root.createElement("fall-diagonal");
00133   fdia.appendChild(pen);
00134   format.appendChild(fdia);
00135 
00136   pen=root.createElement("pen");
00137   pen.setAttribute("width", "1");
00138   pen.setAttribute("style", "0");
00139   pen.setAttribute("color", "#000000");
00140 
00141   QDomElement udia=root.createElement("up-diagonal");
00142   udia.appendChild(pen);
00143   format.appendChild(udia);
00144 
00145   e.appendChild(format);
00146 
00147   QDomElement text=root.createElement("text");
00148   text.appendChild(root.createTextNode(contents));
00149   e.appendChild(text);
00150 
00151   sheet.appendChild(e);
00152 
00153   return true;
00154 }
KDE Home | KDE Accessibility Home | Description of Access Keys