1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include "address.hxx"
23 #include "formulagroup.hxx"
26 #include "cellvalue.hxx"
27 #include "mtvelements.hxx"
28 #include "queryparam.hxx"
29 #include "attarray.hxx"
30 #include <vcl/outdev.hxx>
31 #include <vcl/vclptr.hxx>
42 class ScFlatBoolRowSegments
;
44 struct ScDBQueryParamBase
;
46 struct ScDBQueryParamInternal
;
47 struct ScDBQueryParamMatrix
;
50 struct ScInterpreterContext
;
51 enum class SvNumFormatType
: sal_Int16
;
53 class ScValueIterator
// walk through all values in an area
55 typedef sc::CellStoreType::const_position_type PositionType
;
57 const ScDocument
& mrDoc
;
58 ScInterpreterContext
& mrContext
;
59 const ScAttrArray
* pAttrArray
;
60 sal_uInt32 nNumFormat
; // for CalcAsShown
61 sal_uInt32 nNumFmtIndex
;
67 SubtotalFlags mnSubTotalFlags
;
68 SvNumFormatType nNumFmtType
;
73 const sc::CellStoreType
* mpCells
;
74 PositionType maCurPos
;
81 * See if the cell at the current position is a non-empty cell. If not,
82 * move to the next non-empty cell position.
84 bool GetThis( double& rValue
, FormulaError
& rErr
);
88 ScValueIterator(ScInterpreterContext
& rContext
,
89 const ScRange
& rRange
, SubtotalFlags nSubTotalFlags
= SubtotalFlags::NONE
,
90 bool bTextAsZero
= false );
92 void GetCurNumFmtInfo( SvNumFormatType
& nType
, sal_uInt32
& nIndex
);
94 /// Does NOT reset rValue if no value found!
95 bool GetFirst( double& rValue
, FormulaError
& rErr
);
97 /// Does NOT reset rValue if no value found!
98 bool GetNext( double& rValue
, FormulaError
& rErr
);
101 class ScDBQueryDataIterator
108 FormulaError mnError
;
115 static const sc::CellStoreType
* GetColumnCellStore(ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
);
116 static const ScAttrArray
* GetAttrArrayByCol(ScDocument
& rDoc
, SCTAB nTab
, SCCOL nCol
);
117 static bool IsQueryValid(ScDocument
& rDoc
, const ScQueryParam
& rParam
, SCTAB nTab
, SCROW nRow
, const ScRefCellValue
* pCell
);
123 virtual ~DataAccess() = 0;
124 virtual bool getCurrent(Value
& rValue
) = 0;
125 virtual bool getFirst(Value
& rValue
) = 0;
126 virtual bool getNext(Value
& rValue
) = 0;
129 class DataAccessInternal final
: public DataAccess
131 typedef std::pair
<sc::CellStoreType::const_iterator
,size_t> PositionType
;
133 DataAccessInternal(ScDBQueryParamInternal
* pParam
, ScDocument
& rDoc
, const ScInterpreterContext
& rContext
);
134 virtual ~DataAccessInternal() override
;
135 virtual bool getCurrent(Value
& rValue
) override
;
136 virtual bool getFirst(Value
& rValue
) override
;
137 virtual bool getNext(Value
& rValue
) override
;
143 const sc::CellStoreType
* mpCells
;
144 PositionType maCurPos
;
145 ScDBQueryParamInternal
* mpParam
;
147 const ScInterpreterContext
& mrContext
;
148 const ScAttrArray
* pAttrArray
;
149 sal_uInt32 nNumFormat
; // for CalcAsShown
150 sal_uInt32 nNumFmtIndex
;
155 SvNumFormatType nNumFmtType
;
159 class DataAccessMatrix final
: public DataAccess
162 DataAccessMatrix(ScDBQueryParamMatrix
* pParam
);
163 virtual ~DataAccessMatrix() override
;
164 virtual bool getCurrent(Value
& rValue
) override
;
165 virtual bool getFirst(Value
& rValue
) override
;
166 virtual bool getNext(Value
& rValue
) override
;
169 bool isValidQuery(SCROW mnRow
, const ScMatrix
& rMat
) const;
171 ScDBQueryParamMatrix
* mpParam
;
176 ::std::unique_ptr
<ScDBQueryParamBase
> mpParam
;
177 ::std::unique_ptr
<DataAccess
> mpData
;
180 ScDBQueryDataIterator(ScDocument
& rDocument
, const ScInterpreterContext
& rContext
, std::unique_ptr
<ScDBQueryParamBase
> pParam
);
181 /// Does NOT reset rValue if no value found!
182 bool GetFirst(Value
& rValue
);
183 /// Does NOT reset rValue if no value found!
184 bool GetNext(Value
& rValue
);
187 class ScFormulaGroupIterator
195 std::vector
<sc::FormulaGroupEntry
> maEntries
;
198 ScFormulaGroupIterator( ScDocument
& rDoc
);
200 sc::FormulaGroupEntry
* first();
201 sc::FormulaGroupEntry
* next();
205 * Walk through all cells in an area. For SubTotal and Aggregate depending on mnSubTotalFlags.
209 typedef std::pair
<sc::CellStoreType::const_iterator
, size_t> PositionType
;
212 ScAddress maStartPos
;
216 PositionType maCurColPos
;
217 SubtotalFlags mnSubTotalFlags
;
219 ScRefCellValue maCurCell
;
223 void setPos(size_t nPos
);
225 const ScColumn
* getColumn() const;
231 ScCellIterator( ScDocument
& rDoc
, const ScRange
& rRange
, SubtotalFlags nSubTotalFlags
= SubtotalFlags::NONE
);
233 const ScAddress
& GetPos() const { return maCurPos
; }
235 CellType
getType() const { return maCurCell
.getType();}
236 OUString
getString() const;
237 const EditTextObject
* getEditText() const { return maCurCell
.getEditText();}
238 ScFormulaCell
* getFormulaCell() { return maCurCell
.getFormula();}
239 const ScFormulaCell
* getFormulaCell() const { return maCurCell
.getFormula();}
240 ScCellValue
getCellValue() const;
241 const ScRefCellValue
& getRefCellValue() const { return maCurCell
;}
243 bool hasString() const;
244 bool isEmpty() const;
245 bool equalsWithoutFormat( const ScAddress
& rPos
) const;
251 class ScDocAttrIterator
// all attribute areas
260 std::optional
<ScAttrIterator
> moColIter
;
263 ScDocAttrIterator(ScDocument
& rDocument
, SCTAB nTable
,
264 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
266 const ScPatternAttr
* GetNext( SCCOL
& rCol
, SCROW
& rRow1
, SCROW
& rRow2
);
269 class ScAttrRectIterator
// all attribute areas, including areas stretching
270 // across more than one column
280 std::optional
<ScAttrIterator
>
284 ScAttrRectIterator(ScDocument
& rDocument
, SCTAB nTable
,
285 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
288 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow1
, SCROW
& rRow2
);
291 class ScHorizontalCellIterator
// walk through all non empty cells in an area
295 sc::CellStoreType::const_iterator maPos
;
296 sc::CellStoreType::const_iterator maEnd
;
300 std::vector
<ColParam
>::iterator maColPos
;
301 std::vector
<ColParam
> maColPositions
;
311 ScRefCellValue maCurCell
;
315 ScHorizontalCellIterator(ScDocument
& rDocument
, SCTAB nTable
,
316 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
317 ~ScHorizontalCellIterator();
319 ScRefCellValue
* GetNext( SCCOL
& rCol
, SCROW
& rRow
);
320 bool GetPos( SCCOL
& rCol
, SCROW
& rRow
);
321 /// Set a(nother) sheet and (re)init.
322 void SetTab( SCTAB nTab
);
327 bool SkipInvalidInRow();
328 SCROW
FindNextNonEmptyRow();
331 /** Row-wise value iterator. */
332 class ScHorizontalValueIterator
336 const ScAttrArray
* pAttrArray
;
337 std::unique_ptr
<ScHorizontalCellIterator
>
339 sal_uInt32 nNumFormat
; // for CalcAsShown
349 ScHorizontalValueIterator( ScDocument
& rDocument
,
350 const ScRange
& rRange
);
351 ~ScHorizontalValueIterator();
352 /// Does NOT reset rValue if no value found!
353 bool GetNext( double& rValue
, FormulaError
& rErr
);
356 class ScHorizontalAttrIterator
366 std::unique_ptr
<SCROW
[]> pNextEnd
;
367 std::unique_ptr
<SCCOL
[]> pHorizEnd
;
368 std::unique_ptr
<SCSIZE
[]> pIndices
;
369 std::unique_ptr
<const ScPatternAttr
*[]>
375 void InitForNextRow(bool bInitialization
);
378 ScHorizontalAttrIterator( ScDocument
& rDocument
, SCTAB nTable
,
379 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
380 ~ScHorizontalAttrIterator();
382 const ScPatternAttr
* GetNext( SCCOL
& rCol1
, SCCOL
& rCol2
, SCROW
& rRow
);
385 // returns non-empty cells and areas with formatting (horizontal)
387 class SC_DLLPUBLIC ScUsedAreaIterator
390 ScHorizontalCellIterator aCellIter
;
391 ScHorizontalAttrIterator aAttrIter
;
398 ScRefCellValue
* pCell
;
402 const ScPatternAttr
* pPattern
;
404 SCCOL nFoundStartCol
; // results after GetNext
407 const ScPatternAttr
* pFoundPattern
;
409 ScRefCellValue maFoundCell
;
412 ScUsedAreaIterator( ScDocument
& rDocument
, SCTAB nTable
,
413 SCCOL nCol1
, SCROW nRow1
, SCCOL nCol2
, SCROW nRow2
);
414 ~ScUsedAreaIterator();
418 SCCOL
GetStartCol() const { return nFoundStartCol
; }
419 SCCOL
GetEndCol() const { return nFoundEndCol
; }
420 SCROW
GetRow() const { return nFoundRow
; }
421 const ScPatternAttr
* GetPattern() const { return pFoundPattern
; }
422 const ScRefCellValue
& GetCell() const { return maFoundCell
;}
425 class ScRowBreakIterator
428 static constexpr SCROW NOT_FOUND
= -1;
430 explicit ScRowBreakIterator(::std::set
<SCROW
>& rBreaks
);
435 ::std::set
<SCROW
>& mrBreaks
;
436 ::std::set
<SCROW
>::const_iterator maItr
;
437 ::std::set
<SCROW
>::const_iterator maEnd
;
440 class ScDocRowHeightUpdater
446 ScFlatBoolRowSegments maRanges
;
448 TabRanges(SCTAB nTab
, SCROW nMaxRow
);
452 * Passing a NULL pointer to pTabRangesArray forces the heights of all
453 * rows in all tables to be updated.
455 explicit ScDocRowHeightUpdater(
456 ScDocument
& rDoc
, OutputDevice
* pOutDev
, double fPPTX
, double fPPTY
,
457 const ::std::vector
<TabRanges
>* pTabRangesArray
);
459 void update(const bool bOnlyUsedRows
= false);
462 void updateAll(const bool bOnlyUsedRows
);
466 VclPtr
<OutputDevice
> mpOutDev
;
469 const ::std::vector
<TabRanges
>* mpTabRangesArray
;
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */