Coverage Report

Created: 2026-10-14 09:33

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