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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_TABLEBUFFER_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_TABLEBUFFER_HXX
23 #include <com/sun/star/table/CellRangeAddress.hpp>
24 #include "autofilterbuffer.hxx"
25 #include "tablecolumnsbuffer.hxx"
26 #include "workbookhelper.hxx"
33 ::com::sun::star::table::CellRangeAddress
34 maRange
; /// Original (unchecked) range of the table.
35 OUString maProgName
; /// Programmatical name.
36 OUString maDisplayName
; /// Display name.
37 sal_Int32 mnId
; /// Unique table identifier.
38 sal_Int32 mnType
; /// Table type (worksheet, query, etc.).
39 sal_Int32 mnHeaderRows
; /// Number of header rows.
40 sal_Int32 mnTotalsRows
; /// Number of totals rows.
42 explicit TableModel();
45 class Table
: public WorkbookHelper
48 explicit Table( const WorkbookHelper
& rHelper
);
50 /** Imports a table definition from the passed attributes. */
51 void importTable( const AttributeList
& rAttribs
, sal_Int16 nSheet
);
52 /** Imports a table definition from a TABLE record. */
53 void importTable( SequenceInputStream
& rStrm
, sal_Int16 nSheet
);
54 /** Creates a new auto filter and stores it internally. */
55 inline AutoFilter
& createAutoFilter() { return maAutoFilters
.createAutoFilter(); }
56 /** Creates a new tableColumns handler and stores it internally. */
57 inline TableColumns
& createTableColumns() { return maTableColumns
.createTableColumns(); }
59 /** Creates a database range from this tables. */
60 void finalizeImport();
61 void applyAutoFilters();
62 void applyTableColumns();
64 /** Returns the unique table identifier. */
65 inline sal_Int32
getTableId() const { return maModel
.mnId
; }
66 /** Returns the token index used in API token arrays (com.sun.star.sheet.FormulaToken). */
67 inline sal_Int32
getTokenIndex() const { return mnTokenIndex
; }
68 /** Returns the original display name of the table. */
69 inline const OUString
& getDisplayName() const { return maModel
.maDisplayName
; }
71 /** Returns the original (unchecked) total range of the table. */
72 inline const ::com::sun::star::table::CellRangeAddress
& getOriginalRange() const { return maModel
.maRange
; }
73 /** Returns the cell range of this table. */
74 inline const ::com::sun::star::table::CellRangeAddress
& getRange() const { return maDestRange
; }
75 /** Returns the number of columns of this table. */
76 inline sal_Int32
getWidth() const { return maDestRange
.EndColumn
- maDestRange
.StartColumn
+ 1; }
77 /** Returns the number of rows of this table. */
78 inline sal_Int32
getHeight() const { return maDestRange
.EndRow
- maDestRange
.StartRow
+ 1; }
79 /** Returns the number of header rows in the table range. */
80 inline sal_Int32
getHeaderRows() const { return maModel
.mnHeaderRows
; }
81 /** Returns the number of totals rows in the table range. */
82 inline sal_Int32
getTotalsRows() const { return maModel
.mnTotalsRows
; }
86 AutoFilterBuffer maAutoFilters
; /// Filter settings for this table.
87 TableColumnsBuffer maTableColumns
; /// Column names of this table.
88 OUString maDBRangeName
; /// Name of the databae range in the Calc document.
89 ::com::sun::star::table::CellRangeAddress
90 maDestRange
; /// Validated range of the table in the worksheet.
91 sal_Int32 mnTokenIndex
; /// Token index used in API token array.
94 typedef std::shared_ptr
< Table
> TableRef
;
96 class TableBuffer
: public WorkbookHelper
99 explicit TableBuffer( const WorkbookHelper
& rHelper
);
101 /** Creates a new empty table. */
102 Table
& createTable();
104 /** Creates database ranges from all imported tables. */
105 void finalizeImport();
106 /** Applies autofilters from created database range ( requires finalizeImport to have run before being called */
107 void applyAutoFilters();
108 /** Applies columns names from created database range ( requires finalizeImport to have run before being called */
109 void applyTableColumns();
110 /** Returns a table by its identifier. */
111 TableRef
getTable( sal_Int32 nTableId
) const;
112 /** Returns a table by its display name. */
113 TableRef
getTable( const OUString
& rDispName
) const;
116 /** Inserts the passed table into the maps according to its identifier and name. */
117 void insertTableToMaps( const TableRef
& rxTable
);
120 typedef RefVector
< Table
> TableVector
;
121 typedef RefMap
< sal_Int32
, Table
> TableIdMap
;
122 typedef RefMap
< OUString
, Table
> TableNameMap
;
124 TableVector maTables
;
125 TableIdMap maIdTables
;
126 TableNameMap maNameTables
;
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */