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 
24 #ifndef _CHART2_DATASOURCEHELPER_HXX
25 #define _CHART2_DATASOURCEHELPER_HXX
26 
27 #include <com/sun/star/chart2/XChartDocument.hpp>
28 #include <com/sun/star/chart2/XDiagram.hpp>
29 #include <com/sun/star/chart2/data/XDataSource.hpp>
30 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <com/sun/star/frame/XModel.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 
35 #include "charttoolsdllapi.hxx"
36 
37 #include <vector>
38 
39 //.............................................................................
40 namespace chart
41 {
42 //.............................................................................
43 
44 //-----------------------------------------------------------------------------
45 /**
46 */
47 
48 class OOO_DLLPUBLIC_CHARTTOOLS DataSourceHelper
49 {
50 public:
51         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >
52             createDataSource( const ::com::sun::star::uno::Sequence<
53                 ::com::sun::star::uno::Reference<
54                     ::com::sun::star::chart2::data::XLabeledDataSequence > > & rSequences );
55 
56         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >
57             createCachedDataSequence();
58 
59         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >
60             createCachedDataSequence( const ::rtl::OUString & rSingleText );
61 
62         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >
63             createLabeledDataSequence(
64                 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xValues ,
65                 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xLabels );
66 
67         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >
68             createLabeledDataSequence(
69                 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xValues );
70 
71         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence >
72             createLabeledDataSequence(
73                 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext );
74 
75         static ::com::sun::star::uno::Sequence<
76                ::com::sun::star::beans::PropertyValue > createArguments(
77                    bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories );
78 
79         static ::com::sun::star::uno::Sequence<
80                ::com::sun::star::beans::PropertyValue > createArguments(
81                    const ::rtl::OUString & rRangeRepresentation,
82                    const ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping,
83                    bool bUseColumns, bool bFirstCellAsLabel, bool bHasCategories );
84 
85         SAL_DLLPRIVATE static void readArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rArguments
86             , ::rtl::OUString & rRangeRepresentation, ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
87             , bool& bUseColumns, bool& bFirstCellAsLabel, bool& bHasCategories );
88 
89         static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >
90             pressUsedDataIntoRectangularFormat( const ::com::sun::star::uno::Reference<
91                 ::com::sun::star::chart2::XChartDocument >& xChartDoc,
92                 bool bWithCategories = true );
93 
94         static void addRangeRepresentationsFromLabeledDataSequence(
95             const ::com::sun::star::uno::Reference<
96                 ::com::sun::star::chart2::data::XLabeledDataSequence >& xLabeledDataSequence
97             ,  ::std::vector< ::rtl::OUString >& rOutRangeRepresentations );
98 
99         SAL_DLLPRIVATE static ::com::sun::star::uno::Sequence< ::rtl::OUString > getUsedDataRanges(
100             const ::com::sun::star::uno::Reference<
101                 ::com::sun::star::chart2::XDiagram > & xDiagram );
102 
103         static ::com::sun::star::uno::Sequence< ::rtl::OUString > getUsedDataRanges(
104             const ::com::sun::star::uno::Reference<
105                 ::com::sun::star::frame::XModel > & xChartModel );
106 
107         static ::com::sun::star::uno::Reference<
108                 ::com::sun::star::chart2::data::XDataSource > getUsedData(
109             const ::com::sun::star::uno::Reference<
110                 ::com::sun::star::frame::XModel >& xChartModel );
111 
112         static ::com::sun::star::uno::Reference<
113                 ::com::sun::star::chart2::data::XDataSource > getUsedData(
114             const ::com::sun::star::uno::Reference<
115                 ::com::sun::star::chart2::XChartDocument >& xChartDoc );
116 
117         static bool detectRangeSegmentation(
118             const ::com::sun::star::uno::Reference<
119                 ::com::sun::star::frame::XModel >& xChartModel
120             , ::rtl::OUString& rOutRangeString
121             , ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
122             , bool& rOutUseColumns
123             , bool& rOutFirstCellAsLabel
124             , bool& rOutHasCategories );
125 
126         static void setRangeSegmentation(
127             const ::com::sun::star::uno::Reference<
128                 ::com::sun::star::frame::XModel >& xChartModel
129             , const ::com::sun::star::uno::Sequence< sal_Int32 >& rSequenceMapping
130             , bool bUseColumns
131             , bool bFirstCellAsLabel
132             , bool bUseCategories );
133 
134         /** Returns true, if all arguments necessary for getting all data by a
135             rectangular region are returned by detectArguments at the given
136             document's data provider.
137 
138             Currently, this is: CellRangeRepresentation, DataRowSource,
139             HasCategories and FirstCellAsLabel.
140          */
141         static bool allArgumentsForRectRangeDetected(
142             const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDocument );
143 
144         SAL_DLLPRIVATE static ::com::sun::star::uno::Sequence< ::rtl::OUString > getRangesFromLabeledDataSequence(
145             const ::com::sun::star::uno::Reference<
146                 ::com::sun::star::chart2::data::XLabeledDataSequence > & xLSeq );
147 
148         SAL_DLLPRIVATE static ::rtl::OUString getRangeFromValues(
149             const ::com::sun::star::uno::Reference<
150                 ::com::sun::star::chart2::data::XLabeledDataSequence > & xLSeq );
151 
152         SAL_DLLPRIVATE static ::com::sun::star::uno::Sequence< ::rtl::OUString > getRangesFromDataSource(
153             const ::com::sun::star::uno::Reference<
154                 ::com::sun::star::chart2::data::XDataSource > & xSource );
155 };
156 
157 //.............................................................................
158 } //namespace chart
159 //.............................................................................
160 #endif
161