1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dpcachetable.hxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SC_DPCACHETABLE_HXX
33 #define SC_DPCACHETABLE_HXX
35 #include "sal/types.h"
36 #include "osl/mutex.hxx"
38 #include "collect.hxx"
43 #include <boost/shared_ptr.hpp>
44 #include <com/sun/star/uno/Reference.hxx>
46 namespace com
{ namespace sun
{ namespace star
{
51 struct DataPilotFieldFilter
;
65 // ----------------------------------------------------------------------------
74 ScDPCacheCell
* mpContent
;
80 /** individual filter item used in SingleFilter and GroupFilter. */
83 sal_Int32 mnMatchStrId
;
90 /** interface class used for filtering of rows. */
94 /** returns true if the matching condition is met for a single cell
95 value, or false otherwise. */
96 virtual bool match(const ScDPCacheCell
& rCell
) const = 0;
99 /** ordinary single-item filter. */
100 class SingleFilter
: public FilterBase
103 explicit SingleFilter(ScSimpleSharedString
& rSharedString
,
104 sal_Int32 nMatchStrId
, double fValue
, bool bHasValue
);
105 virtual ~SingleFilter(){}
107 virtual bool match(const ScDPCacheCell
& rCell
) const;
109 const String
getMatchString();
110 double getMatchValue() const;
111 bool hasValue() const;
114 explicit SingleFilter();
117 ScSimpleSharedString mrSharedString
;
120 /** multi-item (group) filter. */
121 class GroupFilter
: public FilterBase
124 GroupFilter(ScSimpleSharedString
& rSharedString
);
125 virtual ~GroupFilter(){}
126 virtual bool match(const ScDPCacheCell
& rCell
) const;
128 void addMatchItem(const String
& rStr
, double fVal
, bool bHasValue
);
129 size_t getMatchItemCount() const;
134 ::std::vector
<FilterItem
> maItems
;
135 ScSimpleSharedString mrSharedString
;
138 /** single filtering criterion. */
141 sal_Int32 mnFieldIndex
;
142 ::boost::shared_ptr
<FilterBase
> mpFilter
;
147 ScDPCacheTable(ScDPCollection
* pCollection
);
150 sal_Int32
getRowSize() const;
151 sal_Int32
getColSize() const;
153 /** Fill the internal table from the cell range provided. This function
154 assumes that the first row is the column header. */
155 void fillTable(ScDocument
* pDoc
, const ScRange
& rRange
, const ScQueryParam
& rQuery
, BOOL
* pSpecial
,
156 bool bIgnoreEmptyRows
);
158 /** Fill the internal table from database connection object. This function
159 assumes that the first row is the column header. */
160 void fillTable(const ::com::sun::star::uno::Reference
< ::com::sun::star::sdbc::XRowSet
>& xRowSet
,
161 const Date
& rNullDate
);
163 /** Check whether a specified row is active or not. When a row is active,
164 it is used in calculation of the results data. A row becomes inactive
165 when it is filtered out by page field. */
166 bool isRowActive(sal_Int32 nRow
) const;
168 /** Set filter on/off flag to each row to control visibility. The caller
169 must ensure that the table is filled before calling this function. */
170 void filterByPageDimension(const ::std::vector
<Criterion
>& rCriteria
, const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
);
172 /** Get the cell instance at specified location within the data grid. Note
173 that the data grid doesn't include the header row. Don't delete the
175 const ScDPCacheCell
* getCell(SCCOL nCol
, SCROW nRow
, bool bRepeatIfEmpty
) const;
177 const String
* getFieldName(sal_Int32 nIndex
) const;
179 /** Get the unique entries for a field specified by index. The caller must
180 make sure that the table is filled before calling function, or it will
181 get an empty collection. */
182 const TypedScStrCollection
& getFieldEntries(sal_Int32 nIndex
) const;
184 /** Filter the table based on the specified criteria, and copy the
185 result to rTabData. This method is used, for example, to generate
186 a drill-down data table. */
187 void filterTable(const ::std::vector
<Criterion
>& rCriteria
,
188 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> >& rTabData
,
189 const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
);
196 ScDPCacheTable(const ScDPCacheTable
&);
199 * Check if a given row meets all specified criteria.
201 * @param nRow index of row to be tested.
202 * @param rCriteria a list of criteria
204 bool isRowQualified(sal_Int32 nRow
, const ::std::vector
<Criterion
>& rCriteria
, const ::std::hash_set
<sal_Int32
>& rRepeatIfEmptyDims
) const;
205 void getValueData(ScDocument
* pDoc
, const ScAddress
& rPos
, ScDPCacheCell
& rCell
);
208 typedef ::boost::shared_ptr
<TypedScStrCollection
> TypedScStrCollectionPtr
;
210 /** main data table. */
211 ::std::vector
< ::std::vector
< ::ScDPCacheTable::Cell
> > maTable
;
213 /** header string IDs */
214 ::std::vector
<sal_Int32
> maHeader
;
216 /** unique field entires for each field (column). */
217 ::std::vector
<TypedScStrCollectionPtr
> maFieldEntries
;
219 /** used to track visibility of rows. The first row below the header row
220 has the index of 0. */
221 ::std::vector
<bool> maRowsVisible
;
223 ScSimpleSharedString
& mrSharedString
;
224 ScDPCollection
* mpCollection
;