1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef CHART2_DATABROWSERMODEL_HXX
28 #define CHART2_DATABROWSERMODEL_HXX
29 
30 #include <com/sun/star/chart2/XChartDocument.hpp>
31 #include <com/sun/star/uno/XComponentContext.hpp>
32 
33 #include <memory>
34 #include <vector>
35 
36 namespace com { namespace sun { namespace star { namespace chart2 {
37     class XDataSeries;
38     class XChartType;
39     namespace data {
40         class XLabeledDataSequence;
41     }
42 }}}}
43 
44 namespace chart
45 {
46 
47 class DialogModel;
48 
49 class DataBrowserModel
50 {
51 public:
52 	explicit DataBrowserModel(
53         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > & xChartDoc,
54         const ::com::sun::star::uno::Reference<
55             ::com::sun::star::uno::XComponentContext > & xContext );
56 	virtual ~DataBrowserModel();
57 
58     /** Inserts a new data series after the data series to which the data column
59         with index nAfterColumnIndex belongs.
60      */
61     void insertDataSeries( sal_Int32 nAfterColumnIndex );
62 
63     /** Inserts a new text column for complex categories.
64      */
65     void insertComplexCategoryLevel( sal_Int32 nAfterColumnIndex );
66 
67     /** Removes a data series to which the data column with index nAtColumnIndex
68         belongs.
69      */
70     void removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex );
71 
72     /** Swaps the series to which the data column with index nFirstIndex belongs
73         with the next series (which starts at an index >= nFirstIndex + 1)
74      */
75     void swapDataSeries( sal_Int32 nFirstIndex );
76     void swapDataPointForAllSeries( sal_Int32 nFirstIndex );
77 
78     void insertDataPointForAllSeries( sal_Int32 nAfterIndex );
79     void removeDataPointForAllSeries( sal_Int32 nAtIndex );
80 
81     enum eCellType
82     {
83         NUMBER,
84         TEXT,
85         TEXTORDATE
86     };
87 
88     eCellType getCellType( sal_Int32 nAtColumn, sal_Int32 nAtRow ) const;
89     /// If getCellType( nAtColumn, nAtRow ) returns TEXT, the result will be Nan
90     double getCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow );
91     ::rtl::OUString getCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow );
92     ::com::sun::star::uno::Any getCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow );
93     sal_uInt32 getNumberFormatKey( sal_Int32 nAtColumn, sal_Int32 nAtRow );
94 
95     /// returns </sal_True> if the number could successfully be set at the given position
96     bool setCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow, double fValue );
97     /// returns </sal_True> if the text could successfully be set at the given position
98     bool setCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow, const ::rtl::OUString & rText );
99     bool setCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow, const ::com::sun::star::uno::Any & aValue );
100 
101     sal_Int32 getColumnCount() const;
102     sal_Int32 getMaxRowCount() const;
103 
104     // returns the UI string of the corresponding role
105     ::rtl::OUString getRoleOfColumn( sal_Int32 nColumnIndex ) const;
106     bool isCategoriesColumn( sal_Int32 nColumnIndex ) const;
107 
108     struct tDataHeader
109     {
110         ::com::sun::star::uno::Reference<
111             ::com::sun::star::chart2::XDataSeries >     m_xDataSeries;
112         ::com::sun::star::uno::Reference<
113             ::com::sun::star::chart2::XChartType >      m_xChartType;
114         bool                                            m_bSwapXAndYAxis;
115         sal_Int32                                       m_nStartColumn;
116         sal_Int32                                       m_nEndColumn;
117 
118         // default CTOR
119         tDataHeader() :
120                 m_bSwapXAndYAxis( false ),
121                 m_nStartColumn( -1 ),
122                 m_nEndColumn( -1 )
123         {}
124         // "full" CTOR
125         tDataHeader(
126             ::com::sun::star::uno::Reference<
127                 ::com::sun::star::chart2::XDataSeries > xDataSeries,
128             ::com::sun::star::uno::Reference<
129                 ::com::sun::star::chart2::XChartType >  xChartType,
130             bool                                        bSwapXAndYAxis,
131             sal_Int32                                   nStartColumn,
132             sal_Int32                                   nEndColumn ) :
133                 m_xDataSeries( xDataSeries ),
134                 m_xChartType( xChartType ),
135                 m_bSwapXAndYAxis( bSwapXAndYAxis ),
136                 m_nStartColumn( nStartColumn ),
137                 m_nEndColumn( nEndColumn )
138         {}
139     };
140 
141     typedef ::std::vector< tDataHeader > tDataHeaderVector;
142 
143     const tDataHeaderVector& getDataHeaders() const;
144 
145     tDataHeader getHeaderForSeries(
146         const ::com::sun::star::uno::Reference<
147             ::com::sun::star::chart2::XDataSeries > &xSeries ) const;
148 
149     ::com::sun::star::uno::Reference<
150             ::com::sun::star::chart2::XDataSeries >
151         getDataSeriesByColumn( sal_Int32 nColumn ) const;
152 
153 private:
154     void updateFromModel();
155 
156     void addErrorBarRanges(
157         const ::com::sun::star::uno::Reference<
158             ::com::sun::star::chart2::XDataSeries > & xDataSeries,
159         sal_Int32 nNumberFormatKey,
160         sal_Int32 & rInOutSequenceIndex,
161         sal_Int32 & rInOutHeaderEnd );
162 
163     sal_Int32 getCategoryColumnCount();
164 
165     ::com::sun::star::uno::Reference<
166             ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
167     ::com::sun::star::uno::Reference<
168             ::com::sun::star::uno::XComponentContext > m_xContext;
169     ::std::auto_ptr< DialogModel > m_apDialogModel;
170 
171     struct tDataColumn;
172     struct implColumnLess;
173 
174     typedef ::std::vector< tDataColumn > tDataColumnVector;
175 
176     tDataColumnVector m_aColumns;
177     tDataHeaderVector m_aHeaders;
178 };
179 
180 } //  namespace chart
181 
182 // CHART2_DATABROWSERMODEL_HXX
183 #endif
184