LibreOffice Module sc (master) 1
MatrixComparisonGenerator.cxx
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 */
10
11#include <rangelst.hxx>
14#include <scresid.hxx>
15#include <strings.hrc>
16
17namespace
18{
19 void lclWriteCorrelationFormulas(
20 AddressWalkerWriter& aOutput, FormulaTemplate& aTemplate,
21 const ScRangeList& aRangeList, const OUString& aTemplateString)
22 {
23 for (size_t i = 0; i < aRangeList.size(); i++)
24 {
25 aOutput.resetRow();
26 for (size_t j = 0; j < aRangeList.size(); j++)
27 {
28 if (j >= i)
29 {
30 aTemplate.setTemplate(aTemplateString);
31 aTemplate.applyRange(u"%VAR1%", aRangeList[i]);
32 aTemplate.applyRange(u"%VAR2%", aRangeList[j]);
33 aOutput.writeFormula(aTemplate.getTemplate());
34 }
35 aOutput.nextRow();
36 }
37 aOutput.nextColumn();
38 }
39 }
40}
41
43 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
44 weld::Window* pParent, ScViewData& rViewData,
45 const OUString& rUiXmlDescription,
46 const OUString& rID)
47 : ScStatisticsInputOutputDialog(pSfxBindings, pChildWindow, pParent, rViewData, rUiXmlDescription, rID)
48{}
49
51{}
52
54{
55 return STR_CORRELATION_UNDO_NAME;
56}
57
59{
62 FormulaTemplate aTemplate(&mDocument);
63
64 SCTAB inTab = mInputRange.aStart.Tab();
65
66 ScRangeList aRangeList = (mGroupedBy == BY_COLUMN) ?
69
70 // labels
71 output.writeString(getLabel());
72 output.nextColumn();
73
74 static constexpr OUStringLiteral strWildcardNumber(u"%NUMBER%");
75
76 // write labels to columns
77 for (size_t i = 0; i < aRangeList.size(); i++)
78 {
79 if (mGroupedBy == BY_COLUMN)
80 aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
81 else
82 aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
83
84 aTemplate.applyNumber(strWildcardNumber, i + 1);
85 output.writeString(aTemplate.getTemplate());
86 output.nextColumn();
87 }
88
89 // write labels to rows
90 output.resetColumn();
91 output.nextRow();
92 for (size_t i = 0; i < aRangeList.size(); i++)
93 {
94 if (mGroupedBy == BY_COLUMN)
95 aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
96 else
97 aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
98
99 aTemplate.applyNumber(strWildcardNumber, i + 1);
100 output.writeString(aTemplate.getTemplate());
101 output.nextRow();
102 }
103
104 // write correlation formulas
105 output.reset();
106 output.push(1, 1);
107
108 lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
109
110 return ScRange(output.mMinimumAddress, output.mMaximumAddress);
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void writeFormula(const OUString &aFormula)
void writeString(const OUString &aString)
void push(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
void setTemplate(const OUString &aTemplate)
void applyRange(std::u16string_view aVariable, const ScRange &aRange, bool b3D=true)
void applyNumber(std::u16string_view aVariable, sal_Int32 aValue)
SCTAB Tab() const
Definition: address.hxx:283
ScMatrixComparisonGenerator(SfxBindings *pSfxBindings, SfxChildWindow *pChildWindow, weld::Window *pParent, ScViewData &rViewData, const OUString &rUiXmlDescription, const OUString &rID)
virtual TranslateId GetUndoNameId() override
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
virtual OUString getLabel()=0
virtual OUString getTemplate()=0
size_t size() const
Definition: rangelst.hxx:89
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
static ScRangeList MakeColumnRangeList(SCTAB aTab, ScAddress const &aStart, ScAddress const &aEnd)
static ScRangeList MakeRowRangeList(SCTAB aTab, ScAddress const &aStart, ScAddress const &aEnd)
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
float u
int i
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:225
sal_Int16 SCTAB
Definition: types.hxx:22