1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef CHART2_DATABROWSERMODEL_HXX
24 #define CHART2_DATABROWSERMODEL_HXX
25 
26 #include <com/sun/star/chart2/XChartDocument.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 
29 #include <memory>
30 #include <vector>
31 
32 namespace com { namespace sun { namespace star { namespace chart2 {
33     class XDataSeries;
34     class XChartType;
35     namespace data {
36         class XLabeledDataSequence;
37     }
38 }}}}
39 
40 namespace chart
41 {
42 
43 class DialogModel;
44 
45 class DataBrowserModel
46 {
47 public:
48 	explicit DataBrowserModel(
49         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > & xChartDoc,
50         const ::com::sun::star::uno::Reference<
51             ::com::sun::star::uno::XComponentContext > & xContext );
52 	virtual ~DataBrowserModel();
53 
54     /** Inserts a new data series after the data series to which the data column
55         with index nAfterColumnIndex belongs.
56      */
57     void insertDataSeries( sal_Int32 nAfterColumnIndex );
58 
59     /** Inserts a new text column for complex categories.
60      */
61     void insertComplexCategoryLevel( sal_Int32 nAfterColumnIndex );
62 
63     /** Removes a data series to which the data column with index nAtColumnIndex
64         belongs.
65      */
66     void removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex );
67 
68     /** Swaps the series to which the data column with index nFirstIndex belongs
69         with the next series (which starts at an index >= nFirstIndex + 1)
70      */
71     void swapDataSeries( sal_Int32 nFirstIndex );
72     void swapDataPointForAllSeries( sal_Int32 nFirstIndex );
73 
74     void insertDataPointForAllSeries( sal_Int32 nAfterIndex );
75     void removeDataPointForAllSeries( sal_Int32 nAtIndex );
76 
77     enum eCellType
78     {
79         NUMBER,
80         TEXT,
81         TEXTORDATE
82     };
83 
84     eCellType getCellType( sal_Int32 nAtColumn, sal_Int32 nAtRow ) const;
85     /// If getCellType( nAtColumn, nAtRow ) returns TEXT, the result will be Nan
86     double getCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow );
87     ::rtl::OUString getCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow );
88     ::com::sun::star::uno::Any getCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow );
89     sal_uInt32 getNumberFormatKey( sal_Int32 nAtColumn, sal_Int32 nAtRow );
90 
91     /// returns </sal_True> if the number could successfully be set at the given position
92     bool setCellNumber( sal_Int32 nAtColumn, sal_Int32 nAtRow, double fValue );
93     /// returns </sal_True> if the text could successfully be set at the given position
94     bool setCellText( sal_Int32 nAtColumn, sal_Int32 nAtRow, const ::rtl::OUString & rText );
95     bool setCellAny( sal_Int32 nAtColumn, sal_Int32 nAtRow, const ::com::sun::star::uno::Any & aValue );
96 
97     sal_Int32 getColumnCount() const;
98     sal_Int32 getMaxRowCount() const;
99 
100     // returns the UI string of the corresponding role
101     ::rtl::OUString getRoleOfColumn( sal_Int32 nColumnIndex ) const;
102     bool isCategoriesColumn( sal_Int32 nColumnIndex ) const;
103 
104     struct tDataHeader
105     {
106         ::com::sun::star::uno::Reference<
107             ::com::sun::star::chart2::XDataSeries >     m_xDataSeries;
108         ::com::sun::star::uno::Reference<
109             ::com::sun::star::chart2::XChartType >      m_xChartType;
110         bool                                            m_bSwapXAndYAxis;
111         sal_Int32                                       m_nStartColumn;
112         sal_Int32                                       m_nEndColumn;
113 
114         // default CTOR
tDataHeaderchart::DataBrowserModel::tDataHeader115         tDataHeader() :
116                 m_bSwapXAndYAxis( false ),
117                 m_nStartColumn( -1 ),
118                 m_nEndColumn( -1 )
119         {}
120         // "full" CTOR
tDataHeaderchart::DataBrowserModel::tDataHeader121         tDataHeader(
122             ::com::sun::star::uno::Reference<
123                 ::com::sun::star::chart2::XDataSeries > xDataSeries,
124             ::com::sun::star::uno::Reference<
125                 ::com::sun::star::chart2::XChartType >  xChartType,
126             bool                                        bSwapXAndYAxis,
127             sal_Int32                                   nStartColumn,
128             sal_Int32                                   nEndColumn ) :
129                 m_xDataSeries( xDataSeries ),
130                 m_xChartType( xChartType ),
131                 m_bSwapXAndYAxis( bSwapXAndYAxis ),
132                 m_nStartColumn( nStartColumn ),
133                 m_nEndColumn( nEndColumn )
134         {}
135     };
136 
137     typedef ::std::vector< tDataHeader > tDataHeaderVector;
138 
139     const tDataHeaderVector& getDataHeaders() const;
140 
141     tDataHeader getHeaderForSeries(
142         const ::com::sun::star::uno::Reference<
143             ::com::sun::star::chart2::XDataSeries > &xSeries ) const;
144 
145     ::com::sun::star::uno::Reference<
146             ::com::sun::star::chart2::XDataSeries >
147         getDataSeriesByColumn( sal_Int32 nColumn ) const;
148 
149 private:
150     void updateFromModel();
151 
152     void addErrorBarRanges(
153         const ::com::sun::star::uno::Reference<
154             ::com::sun::star::chart2::XDataSeries > & xDataSeries,
155         sal_Int32 nNumberFormatKey,
156         sal_Int32 & rInOutSequenceIndex,
157         sal_Int32 & rInOutHeaderEnd );
158 
159     sal_Int32 getCategoryColumnCount();
160 
161     ::com::sun::star::uno::Reference<
162             ::com::sun::star::chart2::XChartDocument > m_xChartDocument;
163     ::com::sun::star::uno::Reference<
164             ::com::sun::star::uno::XComponentContext > m_xContext;
165     ::std::auto_ptr< DialogModel > m_apDialogModel;
166 
167     struct tDataColumn;
168     struct implColumnLess;
169 
170     typedef ::std::vector< tDataColumn > tDataColumnVector;
171 
172     tDataColumnVector m_aColumns;
173     tDataHeaderVector m_aHeaders;
174 };
175 
176 } //  namespace chart
177 
178 // CHART2_DATABROWSERMODEL_HXX
179 #endif
180