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