STOFFChart.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
00002 
00003 /* libstaroffice
00004 * Version: MPL 2.0 / LGPLv2+
00005 *
00006 * The contents of this file are subject to the Mozilla Public License Version
00007 * 2.0 (the "License"); you may not use this file except in compliance with
00008 * the License or as specified alternatively below. You may obtain a copy of
00009 * the License at http://www.mozilla.org/MPL/
00010 *
00011 * Software distributed under the License is distributed on an "AS IS" basis,
00012 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013 * for the specific language governing rights and limitations under the
00014 * License.
00015 *
00016 * Major Contributor(s):
00017 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
00018 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
00019 * Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
00020 * Copyright (C) 2006, 2007 Andrew Ziem
00021 * Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
00022 *
00023 *
00024 * All Rights Reserved.
00025 *
00026 * For minor contributions see the git repository.
00027 *
00028 * Alternatively, the contents of this file may be used under the terms of
00029 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00030 * in which case the provisions of the LGPLv2+ are applicable
00031 * instead of those above.
00032 */
00033 
00034 /*
00035  * Structure to store and construct a chart
00036  *
00037  */
00038 
00039 #ifndef STOFF_CHART
00040 #  define STOFF_CHART
00041 
00042 #include <iostream>
00043 #include <vector>
00044 #include <map>
00045 
00046 #include "libstaroffice_internal.hxx"
00047 
00048 #include "STOFFEntry.hxx"
00049 #include "STOFFFont.hxx"
00050 
00051 namespace STOFFChartInternal
00052 {
00053 class SubDocument;
00054 }
00056 class STOFFChart
00057 {
00058   friend class STOFFChartInternal::SubDocument;
00059 public:
00061   struct Axis {
00063     enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty };
00065     Axis();
00067     ~Axis();
00069     void addContentTo(librevenge::RVNGString const &sheetName, int coord, librevenge::RVNGPropertyList &propList) const;
00071     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00073     friend std::ostream &operator<<(std::ostream &o, Axis const &axis);
00075     Type m_type;
00077     bool m_showGrid;
00079     bool m_showLabel;
00081     STOFFBox2i m_labelRange;
00082 #if 0
00083 
00084     STOFFGraphicStyle m_style;
00085 #endif
00086   };
00088   struct Legend {
00090     Legend() : m_show(false), m_autoPosition(true), m_relativePosition(libstoff::RightBit), m_position(0,0), m_font()
00091     {
00092     }
00094     void addContentTo(librevenge::RVNGPropertyList &propList) const;
00096     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00098     friend std::ostream &operator<<(std::ostream &o, Legend const &legend);
00100     bool m_show;
00102     bool m_autoPosition;
00104     int m_relativePosition;
00106     STOFFVec2f m_position;
00108     STOFFFont m_font;
00109 #if 0
00110 
00111     STOFFGraphicStyle m_style;
00112 #endif
00113   };
00115   struct Series {
00117     enum Type { S_Area, S_Bar, S_Column, S_Line, S_Pie, S_Scatter, S_Stock };
00119     Series();
00121     virtual ~Series();
00123     void addContentTo(librevenge::RVNGString const &sheetName, librevenge::RVNGPropertyList &propList) const;
00125     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00127     static librevenge::RVNGString getSeriesTypeName(Type type);
00129     friend std::ostream &operator<<(std::ostream &o, Series const &series);
00131     Type m_type;
00133     STOFFBox2i m_range;
00134 #if 0
00135 
00136     STOFFGraphicStyle m_style;
00137 #endif
00138   };
00140   struct TextZone {
00142     enum Type { T_Title, T_SubTitle, T_AxisX, T_AxisY, T_AxisZ };
00144     enum ContentType { C_Cell, C_Text };
00145 
00147     TextZone();
00149     ~TextZone();
00151     void addContentTo(librevenge::RVNGString const &sheetName, librevenge::RVNGPropertyList &propList) const;
00153     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00155     friend std::ostream &operator<<(std::ostream &o, TextZone const &zone);
00157     Type m_type;
00159     ContentType m_contentType;
00161     STOFFVec2f m_position;
00163     STOFFVec2i m_cell;
00165     STOFFEntry m_textEntry;
00167     STOFFFont m_font;
00168 #if 0
00169 
00170     STOFFGraphicStyle m_style;
00171 #endif
00172   };
00173 
00175   STOFFChart(librevenge::RVNGString const &sheetName, STOFFVec2f const &dim=STOFFVec2f());
00177   virtual ~STOFFChart();
00179   void sendChart(STOFFSpreadsheetListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface);
00181   virtual void sendContent(TextZone const &zone, STOFFListenerPtr &listener)=0;
00182 
00184   void setDataType(Series::Type type, bool dataStacked)
00185   {
00186     m_type=type;
00187     m_dataStacked=dataStacked;
00188   }
00189 
00191   STOFFVec2f const &getDimension() const
00192   {
00193     return m_dim;
00194   }
00196   void setDimension(STOFFVec2f const &dim)
00197   {
00198     m_dim=dim;
00199   }
00201   void add(int coord, Axis const &axis);
00203   Axis const &getAxis(int coord) const;
00204 
00206   void set(Legend const &legend)
00207   {
00208     m_legend=legend;
00209   }
00211   Legend const &getLegend() const
00212   {
00213     return m_legend;
00214   }
00215 
00217   void add(Series const &series);
00219   std::vector<Series> const &getSeries() const
00220   {
00221     return m_seriesList;
00222   }
00223 
00225   void add(TextZone const &textZone);
00227   bool getTextZone(TextZone::Type type, TextZone &textZone);
00228 
00229 protected:
00231   void sendTextZoneContent(TextZone::Type type, STOFFListenerPtr &listener);
00232 
00233 protected:
00235   librevenge::RVNGString m_sheetName;
00237   STOFFVec2f m_dim;
00239   Series::Type m_type;
00241   bool m_dataStacked;
00243   Axis m_axis[4];
00245   Legend m_legend;
00247   std::vector<Series> m_seriesList;
00249   std::map<TextZone::Type, TextZone> m_textZoneMap;
00250 private:
00251   STOFFChart(STOFFChart const &orig);
00252   STOFFChart &operator=(STOFFChart const &orig);
00253 };
00254 
00255 #endif
00256 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: