summaryrefslogtreecommitdiff
path: root/sc/inc/pivot/PivotTableFormatOutput.hxx
blob: 3bbd19b28f36a527af7296c2b8a255a2d2b39f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#pragma once

#include <com/sun/star/uno/Sequence.hxx>
#include <tools/long.hxx>
#include <address.hxx>
#include <dptypes.hxx>
#include "PivotTableFormats.hxx"

#include <memory>
#include <vector>

namespace com::sun::star::sheet
{
struct MemberResult;
}

class ScDPObject;
struct ScDPOutLevelData;

namespace sc
{
/// Direction or orientation of the results
enum class FormatResultDirection
{
    ROW,
    COLUMN
};

/// A field data for a format output,
struct FormatOutputField
{
    tools::Long nDimension = -2;
    OUString aName;
    sal_Int32 nIndex = -1;
    bool bMatchesAll = false;
    bool bSet = false;
};

/// Data for a entry of a format output, which matches a one format entry
struct FormatOutputEntry
{
    FormatType eType = FormatType::None;
    std::optional<SCTAB> onTab = std::nullopt;
    std::shared_ptr<ScPatternAttr> pPattern;

    std::vector<FormatOutputField> aRowOutputFields;
    std::vector<FormatOutputField> aColumnOutputFields;
};

/// data of one "field" that is part of a line
struct FieldData
{
    tools::Long mnDimension = -2;
    OUString aName;
    tools::Long nIndex;

    bool bIsSet = false;
    bool bIsMember = false;
    bool bSubtotal = false;
    bool bContinue = false;
};

/// data for a "line" of one row/column axis
struct LineData
{
    /// primary axis depending if we are row or column oriented (when selecting a column or row we get a "line")
    std::optional<SCCOLROW> oLine = std::nullopt;
    /// secondary axis depending if we are row or column oriented (position in a line)
    std::optional<SCCOLROW> oPosition = std::nullopt;
    /// fields of a line
    std::vector<FieldData> maFields;
};

/** Format output class, which is responsible to check if any of the formats and matches the
 *  pivot table output, and applies the cell attributes when the match is found. */
class FormatOutput
{
private:
    ScDPObject& mrObject;

public:
    FormatOutput(ScDPObject& rObject)
        : mrObject(rObject)
    {
    }

    std::unique_ptr<sc::PivotTableFormats> mpFormats;
    std::vector<sc::FormatOutputEntry> maFormatOutputEntries;

    std::vector<LineData> maRowLines;
    std::vector<LineData> maColumnLines;

    void setFormats(sc::PivotTableFormats const& rPivotTableFormats)
    {
        mpFormats.reset(new sc::PivotTableFormats(rPivotTableFormats));
    }

    void insertFieldMember(size_t nFieldIndex, const ScDPOutLevelData& rField,
                           tools::Long nMemberIndex, css::sheet::MemberResult const& rMember,
                           SCCOL nColPos, SCROW nRowPos, FormatResultDirection eResultDirection);

    void insertEmptyDataColumn(SCCOL nColPos, SCROW nRowPos);

    void apply(ScDocument& rDocument);
    void prepare(SCTAB nTab, std::vector<ScDPOutLevelData> const& rColumnFields,
                 std::vector<ScDPOutLevelData> const& rRowFields, bool bColumnFieldIsDataOnly);
};

} // end sc

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */