MWAWChart.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 /* libmwaw
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 MWAW_CHART
00040 #  define MWAW_CHART
00041 
00042 #include <iostream>
00043 #include <vector>
00044 #include <map>
00045 
00046 #include "libmwaw_internal.hxx"
00047 
00048 #include "MWAWEntry.hxx"
00049 #include "MWAWFont.hxx"
00050 #include "MWAWGraphicStyle.hxx"
00051 
00052 namespace MWAWChartInternal
00053 {
00054 class SubDocument;
00055 }
00057 class MWAWChart
00058 {
00059   friend class MWAWChartInternal::SubDocument;
00060 public:
00062   struct Axis {
00064     enum Type { A_None, A_Numeric, A_Logarithmic, A_Sequence, A_Sequence_Skip_Empty };
00066     Axis();
00068     ~Axis();
00070     void addContentTo(std::string const &sheetName, int coord, librevenge::RVNGPropertyList &propList) const;
00072     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00074     friend std::ostream &operator<<(std::ostream &o, Axis const &axis);
00076     Type m_type;
00078     bool m_showGrid;
00080     bool m_showLabel;
00082     MWAWBox2i m_labelRange;
00084     MWAWGraphicStyle m_style;
00085   };
00087   struct Legend {
00089     Legend() : m_show(false), m_autoPosition(true), m_relativePosition(libmwaw::RightBit), m_position(0,0), m_font(), m_style()
00090     {
00091     }
00093     void addContentTo(librevenge::RVNGPropertyList &propList) const;
00095     void addStyleTo(librevenge::RVNGPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter) const;
00097     friend std::ostream &operator<<(std::ostream &o, Legend const &legend);
00099     bool m_show;
00101     bool m_autoPosition;
00103     int m_relativePosition;
00105     MWAWVec2f m_position;
00107     MWAWFont m_font;
00109     MWAWGraphicStyle m_style;
00110   };
00112   struct Series {
00114     enum Type { S_Area, S_Bar, S_Column, S_Line, S_Pie, S_Scatter, S_Stock };
00116     Series();
00118     virtual ~Series();
00120     void addContentTo(std::string const &sheetName, librevenge::RVNGPropertyList &propList) const;
00122     void addStyleTo(librevenge::RVNGPropertyList &propList) const;
00124     static std::string getSeriesTypeName(Type type);
00126     friend std::ostream &operator<<(std::ostream &o, Series const &series);
00128     Type m_type;
00130     MWAWBox2i m_range;
00132     MWAWGraphicStyle m_style;
00133   };
00135   struct TextZone {
00137     enum Type { T_Title, T_SubTitle, T_AxisX, T_AxisY, T_AxisZ };
00139     enum ContentType { C_Cell, C_Text };
00140 
00142     TextZone();
00144     ~TextZone();
00146     void addContentTo(std::string const &sheetName, librevenge::RVNGPropertyList &propList) const;
00148     void addStyleTo(librevenge::RVNGPropertyList &propList, shared_ptr<MWAWFontConverter> fontConverter) const;
00150     friend std::ostream &operator<<(std::ostream &o, TextZone const &zone);
00152     Type m_type;
00154     ContentType m_contentType;
00156     MWAWVec2f m_position;
00158     MWAWVec2i m_cell;
00160     MWAWEntry m_textEntry;
00162     MWAWFont m_font;
00164     MWAWGraphicStyle m_style;
00165   };
00166 
00168   MWAWChart(std::string const &sheetName, MWAWFontConverterPtr fontConverter, MWAWVec2f const &dim=MWAWVec2f());
00170   virtual ~MWAWChart();
00172   void sendChart(MWAWSpreadsheetListenerPtr &listener, librevenge::RVNGSpreadsheetInterface *interface);
00174   virtual void sendContent(TextZone const &zone, MWAWListenerPtr &listener)=0;
00175 
00177   void setDataType(Series::Type type, bool dataStacked)
00178   {
00179     m_type=type;
00180     m_dataStacked=dataStacked;
00181   }
00182 
00184   MWAWVec2f const &getDimension() const
00185   {
00186     return m_dim;
00187   }
00189   void setDimension(MWAWVec2f const &dim)
00190   {
00191     m_dim=dim;
00192   }
00194   void add(int coord, Axis const &axis);
00196   Axis const &getAxis(int coord) const;
00197 
00199   void set(Legend const &legend)
00200   {
00201     m_legend=legend;
00202   }
00204   Legend const &getLegend() const
00205   {
00206     return m_legend;
00207   }
00208 
00210   void add(Series const &series);
00212   std::vector<Series> const &getSeries() const
00213   {
00214     return m_seriesList;
00215   }
00216 
00218   void add(TextZone const &textZone);
00220   bool getTextZone(TextZone::Type type, TextZone &textZone);
00221 
00222 protected:
00224   void sendTextZoneContent(TextZone::Type type, MWAWListenerPtr &listener);
00225 
00226 protected:
00228   std::string m_sheetName;
00230   MWAWVec2f m_dim;
00232   Series::Type m_type;
00234   bool m_dataStacked;
00236   Axis m_axis[3];
00238   Legend m_legend;
00240   std::vector<Series> m_seriesList;
00242   std::map<TextZone::Type, TextZone> m_textZoneMap;
00244   MWAWFontConverterPtr m_fontConverter;
00245 private:
00246   MWAWChart(MWAWChart const &orig);
00247   MWAWChart &operator=(MWAWChart const &orig);
00248 };
00249 
00250 #endif
00251 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: