LibreOffice Module sc (master)  1
chartpos.hxx
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 #pragma once
21 
22 #include "rangelst.hxx"
23 #include <tools/solar.h>
24 #include <memory>
25 #include <map>
26 
27 // map of row number to ScAddress*
28 typedef std::map<sal_uLong, std::unique_ptr<ScAddress>> RowMap;
29 // map of column number to RowMap
30 typedef std::map<sal_uLong, RowMap> ColumnMap;
31 
33 {
34  friend class ScChartPositioner;
35 
36  std::unique_ptr<std::unique_ptr<ScAddress>[]> ppData;
37  std::unique_ptr<std::unique_ptr<ScAddress>[]> ppColHeader;
38  std::unique_ptr<std::unique_ptr<ScAddress>[]> ppRowHeader;
42 
43  ScChartPositionMap( SCCOL nChartCols, SCROW nChartRows,
44  SCCOL nColAdd, // header columns
45  SCROW nRowAdd, // header rows
46  ColumnMap& rCols // table with col tables with address*
47  );
48 
49  ScChartPositionMap( const ScChartPositionMap& ) = delete;
51 
52 public:
54 
55  SCCOL GetColCount() const { return nColCount; }
56  SCROW GetRowCount() const { return nRowCount; }
57 
58  bool IsValid( SCCOL nCol, SCROW nRow ) const
59  { return nCol < nColCount && nRow < nRowCount; }
60  // data column by column
61  sal_uLong GetIndex( SCCOL nCol, SCROW nRow ) const
62  { return static_cast<sal_uLong>(nCol) * nRowCount + nRow; }
63 
64  const ScAddress* GetPosition( sal_uLong nIndex ) const
65  {
66  if ( nIndex < nCount )
67  return ppData[ nIndex ].get();
68  return nullptr;
69  }
70 
72  const ScAddress* GetPosition( SCCOL nChartCol, SCROW nChartRow ) const
73  {
74  if ( IsValid( nChartCol, nChartRow ) )
75  return ppData[ GetIndex( nChartCol, nChartRow ) ].get();
76  return nullptr;
77  }
78  const ScAddress* GetColHeaderPosition( SCCOL nChartCol ) const
79  {
80  if ( nChartCol < nColCount )
81  return ppColHeader[ nChartCol ].get();
82  return nullptr;
83  }
84  const ScAddress* GetRowHeaderPosition( SCROW nChartRow ) const
85  {
86  if ( nChartRow < nRowCount )
87  return ppRowHeader[ nChartRow ].get();
88  return nullptr;
89  }
90 };
91 
92 enum class ScChartGlue {
93  NA,
94  NONE, // old mimic
95  Cols, // old mimic
96  Rows,
97  Both
98 };
99 
100 class ScDocument;
101 
102 class ScChartPositioner final // only parameter struct
103 {
106  std::unique_ptr<ScChartPositionMap> pPositionMap;
113 
114  void CheckColRowHeaders();
115 
116  void GlueState(); // summarised areas
117  void CreatePositionMap();
118 
119 public:
120  ScChartPositioner( ScDocument& rDoc, SCTAB nTab,
121  SCCOL nStartColP, SCROW nStartRowP,
122  SCCOL nEndColP, SCROW nEndRowP );
123  ScChartPositioner( ScDocument& rDoc, const ScRangeListRef& rRangeList );
124  ScChartPositioner( const ScChartPositioner& rPositioner );
125 
127 
128  const ScRangeListRef& GetRangeList() const { return aRangeListRef; }
129  void SetRangeList( const ScRange& rNew );
130 
131  void SetHeaders(bool bCol, bool bRow) { bColHeaders=bCol; bRowHeaders=bRow; }
132  bool HasColHeaders() const { return bColHeaders; }
133  bool HasRowHeaders() const { return bRowHeaders; }
134 
135  void InvalidateGlue();
137 };
138 
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const ScAddress * GetRowHeaderPosition(SCROW nChartRow) const
Definition: chartpos.hxx:84
const ScRangeListRef & GetRangeList() const
Definition: chartpos.hxx:128
sal_uIntPtr sal_uLong
const ScAddress * GetPosition(sal_uLong nIndex) const
Definition: chartpos.hxx:64
std::unique_ptr< std::unique_ptr< ScAddress >[]> ppColHeader
Definition: chartpos.hxx:37
SCCOL GetColCount() const
deletes all ScAddress*
Definition: chartpos.hxx:55
ScChartGlue eGlue
Definition: chartpos.hxx:107
ScRangeListRef aRangeListRef
Definition: chartpos.hxx:104
std::map< sal_uLong, std::unique_ptr< ScAddress > > RowMap
Definition: chartpos.hxx:28
ScChartPositioner(ScDocument &rDoc, SCTAB nTab, SCCOL nStartColP, SCROW nStartRowP, SCCOL nEndColP, SCROW nEndRowP)
Definition: chartpos.cxx:43
void SetRangeList(const ScRange &rNew)
Definition: chartpos.cxx:87
ScChartPositionMap(SCCOL nChartCols, SCROW nChartRows, SCCOL nColAdd, SCROW nRowAdd, ColumnMap &rCols)
Definition: chartpos.cxx:445
ScChartGlue
Definition: chartpos.hxx:92
bool HasRowHeaders() const
Definition: chartpos.hxx:133
void InvalidateGlue()
Definition: chartpos.cxx:439
std::unique_ptr< ScChartPositionMap > pPositionMap
Definition: chartpos.hxx:106
sal_Int16 SCCOL
Definition: types.hxx:21
void CheckColRowHeaders()
Definition: chartpos.cxx:269
std::unique_ptr< std::unique_ptr< ScAddress >[]> ppData
Definition: chartpos.hxx:36
const ScAddress * GetColHeaderPosition(SCCOL nChartCol) const
Definition: chartpos.hxx:78
sal_uLong nCount
Definition: chartpos.hxx:39
SCROW GetRowCount() const
Definition: chartpos.hxx:56
void SetHeaders(bool bCol, bool bRow)
Definition: chartpos.hxx:131
ScChartPositionMap & operator=(const ScChartPositionMap &)=delete
sal_Int32 SCROW
Definition: types.hxx:17
void CreatePositionMap()
Definition: chartpos.cxx:339
sal_uLong GetIndex(SCCOL nCol, SCROW nRow) const
Definition: chartpos.hxx:61
ScDocument & rDocument
Definition: chartpos.hxx:105
bool HasColHeaders() const
Definition: chartpos.hxx:132
const ScAddress * GetPosition(SCCOL nChartCol, SCROW nChartRow) const
might be NULL indicating "no value"
Definition: chartpos.hxx:72
std::map< sal_uLong, RowMap > ColumnMap
Definition: chartpos.hxx:30
std::unique_ptr< std::unique_ptr< ScAddress >[]> ppRowHeader
Definition: chartpos.hxx:38
bool IsValid(SCCOL nCol, SCROW nRow) const
Definition: chartpos.hxx:58
const ScChartPositionMap * GetPositionMap()
Definition: chartpos.cxx:333
sal_Int16 SCTAB
Definition: types.hxx:22