Eneboo - Documentación para desarrolladores
tools/aqods/odf-gen/row.h
Ir a la documentación de este archivo.
00001 /*
00002 odf-gen: Simple API to generate OpenDocument documents.
00003     Copyright (C) 2009  Pablo Jorge, FuDePAN
00004 
00005     This file is part of the odf-gen project.
00006 
00007     odf-gen is free software: you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation, either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     odf-gen is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with odf-gen.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #ifndef ROW_H
00022 #define ROW_H
00023 
00024 #include <iostream>
00025 
00026 #include "odstype.h"
00027 
00028 #include "element.h"
00029 #include "sheet.h"
00030 
00031 #include "celladdress.h"
00032 #include "style.h"
00033 #include "span.h"
00034 #include "color.h"
00035 
00036 class Row : public Element
00037 {
00038 public:
00039   Row(Sheet &sheet)
00040     : Element(sheet),
00041       _sheet(sheet),
00042       _column(0),
00043       _row(0) {
00044     _sheet.add_row();
00045     _row = _sheet.get_rows();
00046     _ostream << "<row>";
00047   }
00048 
00049   virtual void close_() {
00050     if (!!_style)
00051       add_cell("");
00052 
00053     _ostream << "</row>";
00054   }
00055 
00056   ~Row() {
00057     close();
00058   }
00059 
00060   template < class T >
00061   void begin_cell(const Style &style,
00062                   unsigned int column_span,
00063                   unsigned int row_span) {
00064     _ostream << "<cell";
00065 
00066     if (!!style)
00067       _ostream << " style=\"" << style << "\"";
00068     if (_bgcolor.isValid())
00069       _ostream << " bgcolor=\"" << _bgcolor << "\"";
00070     if (_fgcolor.isValid())
00071       _ostream << " fgcolor=\"" << _fgcolor << "\"";
00072     if (column_span > 0)
00073       _ostream << " column-span=\"" << column_span << "\"";
00074     if (row_span > 0)
00075       _ostream << " row-span=\"" << row_span << "\"";
00076 
00077     _ostream << " type=\"" << ODSType< T >::convert() << "\">";
00078   }
00079 
00080   void end_cell() {
00081     _ostream << "</cell>";
00082   }
00083 
00084   template < class T >
00085   void add_value(const T &value) {
00086     _ostream << value;
00087   }
00088 
00089   template < class T >
00090   CellAddress add_cell(const T &value,
00091                        unsigned int column_span,
00092                        unsigned int row_span) {
00093     // add the cell using the preset style
00094     begin_cell< T >(_style, column_span, row_span);
00095     add_value(value);
00096     end_cell();
00097 
00098     // reset style
00099     _style = Style::NONE;
00100 
00101     // increment current column count
00102     ++_column;
00103 
00104     // capture current cell address
00105     CellAddress address(_sheet.get_name(),
00106                         _column,
00107                         _row);
00108 
00109     // adjust (if necessary) the columns count
00110     _column += column_span ? column_span - 1 : 0;
00111 
00112     // if current column count > maximum column count
00113     // for all the rows in this sheet, update sheet's
00114     // column count
00115     if (_column > _sheet.get_columns())
00116       _sheet.add_column();
00117 
00118     // return a valid CellAddress
00119     return address;
00120   }
00121 
00122   template < class T >
00123   CellAddress add_cell(const T &value) {
00124     return add_cell(value, 0, 0);
00125   }
00126 
00127   void add_style(const Style &style) {
00128     _style |= style;
00129   }
00130 
00131   Row &add_bgcolor(const Color &color) {
00132     _bgcolor = color;
00133     return *this;
00134   }
00135 
00136   Row &add_fgcolor(const Color &color) {
00137     _fgcolor = color;
00138     return *this;
00139   }
00140 
00141   template < class T >
00142   Row &operator << (const T &value) {
00143     add_cell(value);
00144     return *this;
00145   }
00146 
00147   Row &operator << (const Style &style) {
00148     add_style(style);
00149     return *this;
00150   }
00151 
00152   template < class T >
00153   Row &operator << (const ColumnSpan< T >& spanned_value) {
00154     add_cell(spanned_value.value(),
00155              spanned_value.count(),
00156              0);
00157     return *this;
00158   }
00159 
00160   template < class T >
00161   Row &operator << (const RowSpan< T >& spanned_value) {
00162     add_cell(spanned_value.value(),
00163              0,
00164              spanned_value.count());
00165     return *this;
00166   }
00167 
00168   Row &operator << (const CoveredCell & /*covered*/) {
00169     _ostream << "<cell covered=\"true\"/>";
00170     return *this;
00171   }
00172 
00173   Row &add_coveredcell() {
00174     _ostream << "<cell covered=\"true\"/>";
00175     return *this;
00176   }
00177 
00178 private:
00179   Sheet &_sheet;
00180 
00181   Style _style;
00182   Color _bgcolor;
00183   Color _fgcolor;
00184   unsigned int _column,
00185            _row;
00186 };
00187 
00188 #endif // ROW_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'