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 
20 #include <tablecolumnsbuffer.hxx>
21 
22 #include <sal/log.hxx>
24 #include <oox/token/tokens.hxx>
25 #include <dbdata.hxx>
26 
27 namespace oox::xls {
28 
30  WorkbookHelper( rHelper ),
31  mnId( -1 ),
32  mnDataDxfId( -1 )
33 {
34 }
35 
37 {
38  mnId = rAttribs.getInteger( XML_id, -1 );
39  maName = rAttribs.getString( XML_name, OUString() );
40  mnDataDxfId = rAttribs.getInteger( XML_dataDxfId, -1 );
41 }
42 
44 {
45  /* XXX not implemented */
46  (void) mnId;
47 }
48 
49 const OUString& TableColumn::getName() const
50 {
51  return maName;
52 }
53 
55  WorkbookHelper( rHelper ),
56  mnCount(0)
57 {
58 }
59 
61 {
62  mnCount = rAttribs.getInteger( XML_count, 0 );
63 }
64 
66 {
67  /* XXX not implemented */
68  (void) mnCount;
69 }
70 
72 {
73  TableColumnVector::value_type xTableColumn = std::make_shared<TableColumn>( *this );
74  maTableColumnVector.push_back( xTableColumn );
75  return *xTableColumn;
76 }
77 
79 {
80  SAL_WARN_IF( static_cast<size_t>(mnCount) != maTableColumnVector.size(), "sc.filter",
81  "TableColumns::finalizeImport - count attribute doesn't match number of tableColumn elements");
82  if ( pDBData )
83  {
84  /* TODO: use svl::SharedString for names */
85  ::std::vector< OUString > aNames( maTableColumnVector.size());
86  size_t i = 0;
87  for (const auto& rxTableColumn : maTableColumnVector)
88  {
89  aNames[i] = rxTableColumn->getName();
90  ++i;
91  }
92  pDBData->SetTableColumnNames( aNames);
93  return true;
94  }
95  return false;
96 }
97 
99  WorkbookHelper( rHelper )
100 {
101 }
102 
104 {
105  TableColumnsVector::value_type xTableColumns = std::make_shared<TableColumns>( *this );
106  maTableColumnsVector.push_back( xTableColumns );
107  return *xTableColumns;
108 }
109 
111 {
112  TableColumns* pTableColumns = getActiveTableColumns();
113  if ( pTableColumns )
114  pTableColumns->finalizeImport( pDBData );
115 }
116 
118 {
119  // not more than one table columns descriptor per table
120  SAL_WARN_IF( maTableColumnsVector.size() > 1, "sc.filter",
121  "TableColumnsBuffer::getActiveTableColumns - too many table columns" );
122  // stick to the last imported table columns
123  return maTableColumnsVector.empty() ? nullptr : maTableColumnsVector.back().get();
124 }
125 
126 } // namespace oox::xls
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
TableColumn & createTableColumn()
Creates a new table column and stores it internally.
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
void importTableColumn(const AttributeList &rAttribs)
Imports table column settings from the tableColumn element.
TableColumn(const WorkbookHelper &rHelper)
value_type get(sal_Int32 nIndex) const
OptValue< OUString > getString(sal_Int32 nAttrToken) const
sal_uInt16 mnId
A column in a table (database range).
TableColumnVector maTableColumnVector
void importTableColumns(const AttributeList &rAttribs)
Imports settings from the tableColumns element.
int i
container_type::value_type value_type
TableColumns & createTableColumns()
Creates a new table columns object and stores it internally.
std::size_t mnCount
bool finalizeImport(ScDBData *pDBData)
Applies the columns to the passed database range.
#define SAL_WARN_IF(condition, area, stream)
const OUString & getName() const
Gets the name of this column.
TableColumnsBuffer(const WorkbookHelper &rHelper)
void finalizeImport(ScDBData *pDBData)
Applies the table columns to the passed database range.
TableColumnsVector maTableColumnsVector
TableColumns * getActiveTableColumns()
Returns the table columns object used.
TableColumns(const WorkbookHelper &rHelper)
SC_DLLPUBLIC void SetTableColumnNames(const ::std::vector< OUString > &rNames)
Definition: dbdata.cxx:660
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo