LibreOffice Module sc (master) 1
tablecolumnsbuffer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
22#include <sal/log.hxx>
24#include <oox/token/tokens.hxx>
25
26namespace oox::xls {
27
29 WorkbookHelper( rHelper ),
30 mnId( -1 ),
31 mnDataDxfId( -1 )
32{
33}
34
36{
37 mnId = rAttribs.getInteger( XML_id, -1 );
38 maName = rAttribs.getString( XML_name, OUString() );
39 mnDataDxfId = rAttribs.getInteger( XML_dataDxfId, -1 );
40 if ( rAttribs.hasAttribute( XML_totalsRowFunction ) )
41 maColumnAttributes.maTotalsFunction = rAttribs.getStringDefaulted( XML_totalsRowFunction );
42}
43
45{
46 /* XXX not implemented */
47 (void) mnId;
48}
49
50const OUString& TableColumn::getName() const
51{
52 return maName;
53}
54
56{
57 return maColumnAttributes;
58}
59
61 WorkbookHelper( rHelper ),
62 mnCount(0)
63{
64}
65
67{
68 mnCount = rAttribs.getInteger( XML_count, 0 );
69}
70
72{
73 /* XXX not implemented */
74 (void) mnCount;
75}
76
78{
79 TableColumnVector::value_type xTableColumn = std::make_shared<TableColumn>( *this );
80 maTableColumnVector.push_back( xTableColumn );
81 return *xTableColumn;
82}
83
85{
86 SAL_WARN_IF( static_cast<size_t>(mnCount) != maTableColumnVector.size(), "sc.filter",
87 "TableColumns::finalizeImport - count attribute doesn't match number of tableColumn elements");
88 if ( pDBData )
89 {
90 /* TODO: use svl::SharedString for names */
91 ::std::vector< OUString > aNames( maTableColumnVector.size());
92 ::std::vector< TableColumnAttributes > aAttributesVector( maTableColumnVector.size() );
93 size_t i = 0;
94 for (const auto& rxTableColumn : maTableColumnVector)
95 {
96 aNames[i] = rxTableColumn->getName();
97 aAttributesVector[i] = rxTableColumn->getColumnAttributes();
98 ++i;
99 }
100 pDBData->SetTableColumnNames( std::move(aNames) );
101 pDBData->SetTableColumnAttributes( std::move(aAttributesVector) );
102 return true;
103 }
104 return false;
105}
106
108 WorkbookHelper( rHelper )
109{
110}
111
113{
114 TableColumnsVector::value_type xTableColumns = std::make_shared<TableColumns>( *this );
115 maTableColumnsVector.push_back( xTableColumns );
116 return *xTableColumns;
117}
118
120{
121 TableColumns* pTableColumns = getActiveTableColumns();
122 if ( pTableColumns )
123 pTableColumns->finalizeImport( pDBData );
124}
125
127{
128 // not more than one table columns descriptor per table
129 SAL_WARN_IF( maTableColumnsVector.size() > 1, "sc.filter",
130 "TableColumnsBuffer::getActiveTableColumns - too many table columns" );
131 // stick to the last imported table columns
132 return maTableColumnsVector.empty() ? nullptr : maTableColumnsVector.back().get();
133}
134
135} // namespace oox::xls
136
137/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void SetTableColumnAttributes(::std::vector< TableColumnAttributes > &&rAttributes)
Definition: dbdata.cxx:689
SC_DLLPUBLIC void SetTableColumnNames(::std::vector< OUString > &&rNames)
Definition: dbdata.cxx:683
OUString getStringDefaulted(sal_Int32 nAttrToken) const
bool hasAttribute(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
value_type get(sal_Int32 nIndex) const
container_type::value_type value_type
A column in a table (database range).
TableColumn(const WorkbookHelper &rHelper)
const OUString & getName() const
Gets the name of this column.
TableColumnAttributes maColumnAttributes
void importTableColumn(const AttributeList &rAttribs)
Imports table column settings from the tableColumn element.
const TableColumnAttributes & getColumnAttributes() const
Gets the attributes of this column.
TableColumns * getActiveTableColumns()
Returns the table columns object used.
TableColumnsVector maTableColumnsVector
TableColumnsBuffer(const WorkbookHelper &rHelper)
void finalizeImport(ScDBData *pDBData)
Applies the table columns to the passed database range.
TableColumns & createTableColumns()
Creates a new table columns object and stores it internally.
TableColumns(const WorkbookHelper &rHelper)
bool finalizeImport(ScDBData *pDBData)
Applies the columns to the passed database range.
void importTableColumns(const AttributeList &rAttribs)
Imports settings from the tableColumns element.
TableColumn & createTableColumn()
Creates a new table column and stores it internally.
TableColumnVector maTableColumnVector
Helper class to provide access to global workbook data.
sal_uInt16 mnId
std::size_t mnCount
#define SAL_WARN_IF(condition, area, stream)
int i
std::optional< OUString > maTotalsFunction
Definition: dbdata.hxx:48