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_VIEW_EXPLICITCATEGORIESPROVIDER_HXX
24 #define CHART2_VIEW_EXPLICITCATEGORIESPROVIDER_HXX
25 
26 #include "ServiceMacros.hxx"
27 #include <cppuhelper/implbase1.hxx>
28 #include <cppuhelper/weakref.hxx>
29 #include <com/sun/star/chart2/XCoordinateSystem.hpp>
30 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
31 #include <com/sun/star/frame/XModel.hpp>
32 #include "charttoolsdllapi.hxx"
33 
34 #include <vector>
35 
36 namespace chart
37 {
38 
39 struct OOO_DLLPUBLIC_CHARTTOOLS ComplexCategory
40 {
41     rtl::OUString Text;
42     sal_Int32 Count;
43 
ComplexCategorychart::ComplexCategory44     ComplexCategory( const rtl::OUString& rText, sal_Int32 nCount ) : Text( rText ), Count (nCount)
45     {}
46 };
47 
48 class OOO_DLLPUBLIC_CHARTTOOLS SplitCategoriesProvider
49 {
50 public:
51     virtual ~SplitCategoriesProvider();
52 
53     virtual sal_Int32 getLevelCount() const = 0;
54     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > getStringsForLevel( sal_Int32 nIndex ) const = 0;
55 };
56 
57 struct DatePlusIndex
58 {
DatePlusIndexchart::DatePlusIndex59     DatePlusIndex()
60         : fValue(1.0)
61         , nIndex( -1 )
62     {
63     }
64 
DatePlusIndexchart::DatePlusIndex65     DatePlusIndex( const double& _fValue, sal_Int32 _nIndex )
66         : fValue(_fValue)
67         , nIndex( _nIndex )
68     {
69     }
70 
71     double fValue;
72     sal_Int32 nIndex;
73 };
74 
75 class OOO_DLLPUBLIC_CHARTTOOLS ExplicitCategoriesProvider
76 {
77 public:
78     ExplicitCategoriesProvider( const ::com::sun::star::uno::Reference<
79                         ::com::sun::star::chart2::XCoordinateSystem >& xCooSysModel
80                        , const ::com::sun::star::uno::Reference<
81                         ::com::sun::star::frame::XModel >& xChartModel
82                        );
83 	virtual ~ExplicitCategoriesProvider();
84 
85     void init();
86 
87     ::com::sun::star::uno::Reference<
88         ::com::sun::star::chart2::data::XDataSequence > getOriginalCategories();
89 
90     ::com::sun::star::uno::Sequence< ::rtl::OUString > getSimpleCategories();
91     ::std::vector< ComplexCategory > getCategoriesByLevel( sal_Int32 nLevel );
92 
93     static ::rtl::OUString getCategoryByIndex(
94           const ::com::sun::star::uno::Reference<
95             ::com::sun::star::chart2::XCoordinateSystem >& xCooSysModel
96         , const ::com::sun::star::uno::Reference<
97             ::com::sun::star::frame::XModel >& xChartModel
98         , sal_Int32 nIndex );
99 
100     static ::com::sun::star::uno::Sequence< ::rtl::OUString > getExplicitSimpleCategories(
101             const SplitCategoriesProvider& rSplitCategoriesProvider );
102 
103     static void convertCategoryAnysToText( ::com::sun::star::uno::Sequence< rtl::OUString >& rOutTexts
104         , const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rInAnys
105         , ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > xChartModel );
106 
107     bool hasComplexCategories() const;
108     sal_Int32 getCategoryLevelCount() const;
109 
110     const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
111         ::com::sun::star::chart2::data::XLabeledDataSequence> >& getSplitCategoriesList();
112 
113     bool isDateAxis();
114     const std::vector< DatePlusIndex >&  getDateCategories();
115 
116 private: //member
117     bool volatile m_bDirty;
118     ::com::sun::star::uno::WeakReference<
119         ::com::sun::star::chart2::XCoordinateSystem >   m_xCooSysModel;
120     ::com::sun::star::uno::WeakReference<
121         ::com::sun::star::frame::XModel >               m_xChartModel;
122     ::com::sun::star::uno::Reference<
123         ::com::sun::star::chart2::data::XLabeledDataSequence> m_xOriginalCategories;
124 
125     bool m_bIsExplicitCategoriesInited;
126     ::com::sun::star::uno::Sequence< ::rtl::OUString >  m_aExplicitCategories;
127     ::std::vector< ::std::vector< ComplexCategory > >   m_aComplexCats;
128     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
129         ::com::sun::star::chart2::data::XLabeledDataSequence> > m_aSplitCategoriesList;
130 
131     bool m_bIsDateAxis;
132     bool m_bIsAutoDate;
133     std::vector< DatePlusIndex >  m_aDateCategories;
134 };
135 
136 } //  namespace chart
137 
138 // CHART2_VIEW_EXPLICITCATEGORIESPROVIDER_HXX
139 #endif
140