OdsFileHandler.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : OdsFileHandler.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2009 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : An XML handler for parsing Open Document Format Spreadsheets (.ods)
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef OdsFileHandler_H
00030 #define OdsFileHandler_H
00031 
00032 #include <QXmlDefaultHandler>
00033 #include <vector>
00034 
00035 class ApplicationWindow;
00036 class Table;
00037 
00038 class OdsFileHandler : public QXmlDefaultHandler
00039 {
00040 public:
00041     OdsFileHandler(ApplicationWindow *app, const QString& odsFileName);
00042 
00043     bool startElement(const QString &namespaceURI, const QString &localName,
00044                        const QString &qName, const QXmlAttributes &attributes);
00045     bool endElement(const QString &namespaceURI, const QString &localName,
00046                      const QString &qName);
00047     bool characters(const QString &str);
00048     bool fatalError(const QXmlParseException &){return false;};
00049     QString errorString() const;
00050 
00051     Table *sheet(int index);
00052     int sheetsCount(){return d_tables.size();};
00053 
00054 private:
00055     ApplicationWindow * d_app;
00056     QString d_ods_file_name;
00057     QString currentText;
00058     QString errorStr;
00059     //Index of the last non-empty cell in a sheet
00060     int d_last_column;
00061     //Total number of rows in a sheet
00062     int d_rows;
00063     //Current column in a row
00064     int d_col;
00065 
00066     enum CellType {EmptyCell = 0, Float, String, Date, Time, Boolean, Currency, Percent};
00067 
00068     struct cell_data{
00069         int row;
00070         int col;
00071         double  d;
00072         QString str;
00073         CellType type;
00074     };
00075 
00076     std::vector <cell_data> cells;
00077 
00078     QStringList d_sheet_names;
00079     QList<Table *> d_tables;
00080 };
00081 
00082 #endif