Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/StatisticsDialogs/MatrixComparisonGenerator.cxx
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
 */
10
11
#include <rangelst.hxx>
12
#include <TableFillingAndNavigationTools.hxx>
13
#include <MatrixComparisonGenerator.hxx>
14
#include <scresid.hxx>
15
#include <strings.hrc>
16
17
namespace
18
{
19
    void lclWriteCorrelationFormulas(
20
            AddressWalkerWriter& aOutput, FormulaTemplate& aTemplate,
21
            const ScRangeList& aRangeList, const OUString& aTemplateString)
22
0
    {
23
0
        for (size_t i = 0; i < aRangeList.size(); i++)
24
0
        {
25
0
            aOutput.resetRow();
26
0
            for (size_t j = 0; j < aRangeList.size(); j++)
27
0
            {
28
0
                if (j >= i)
29
0
                {
30
0
                    aTemplate.setTemplate(aTemplateString);
31
0
                    aTemplate.applyRange(u"%VAR1%", aRangeList[i]);
32
0
                    aTemplate.applyRange(u"%VAR2%", aRangeList[j]);
33
0
                    aOutput.writeFormula(aTemplate.getTemplate());
34
0
                }
35
0
                aOutput.nextRow();
36
0
            }
37
0
            aOutput.nextColumn();
38
0
        }
39
0
    }
40
}
41
42
ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
43
                                    SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
44
                                    weld::Window* pParent, ScViewData& rViewData,
45
                                    const OUString& rUiXmlDescription,
46
                                    const OUString& rID)
47
0
    : ScStatisticsInputOutputDialog(pSfxBindings, pChildWindow, pParent, rViewData, rUiXmlDescription, rID)
48
0
{}
49
50
ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
51
0
{}
52
53
TranslateId ScMatrixComparisonGenerator::GetUndoNameId()
54
0
{
55
0
    return STR_CORRELATION_UNDO_NAME;
56
0
}
57
58
ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
59
0
{
60
0
    AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
61
0
            formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
62
0
    FormulaTemplate aTemplate(&mDocument);
63
64
0
    SCTAB inTab = mInputRange.aStart.Tab();
65
66
0
    ScRangeList aRangeList = (mGroupedBy == BY_COLUMN) ?
67
0
        MakeColumnRangeList(inTab, mInputRange.aStart, mInputRange.aEnd) :
68
0
        MakeRowRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
69
70
    // labels
71
0
    output.writeString(getLabel());
72
0
    output.nextColumn();
73
74
0
    static constexpr OUString strWildcardNumber(u"%NUMBER%"_ustr);
75
76
    // write labels to columns
77
0
    for (size_t i = 0; i < aRangeList.size(); i++)
78
0
    {
79
0
        if (mGroupedBy == BY_COLUMN)
80
0
            aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
81
0
        else
82
0
            aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
83
84
0
        aTemplate.applyNumber(strWildcardNumber, i + 1);
85
0
        output.writeString(aTemplate.getTemplate());
86
0
        output.nextColumn();
87
0
    }
88
89
    // write labels to rows
90
0
    output.resetColumn();
91
0
    output.nextRow();
92
0
    for (size_t i = 0; i < aRangeList.size(); i++)
93
0
    {
94
0
        if (mGroupedBy == BY_COLUMN)
95
0
            aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
96
0
        else
97
0
            aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
98
99
0
        aTemplate.applyNumber(strWildcardNumber, i + 1);
100
0
        output.writeString(aTemplate.getTemplate());
101
0
        output.nextRow();
102
0
    }
103
104
    // write correlation formulas
105
0
    output.reset();
106
0
    output.push(1, 1);
107
108
0
    lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
109
110
0
    return ScRange(output.mMinimumAddress, output.mMaximumAddress);
111
0
}
112
113
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */