1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
11 #include <rangelst.hxx>
12 #include <TableFillingAndNavigationTools.hxx>
13 #include <MatrixComparisonGenerator.hxx>
14 #include <scresid.hxx>
15 #include <strings.hrc>
19 void lclWriteCorrelationFormulas(
20 AddressWalkerWriter
& aOutput
, FormulaTemplate
& aTemplate
,
21 const ScRangeList
& aRangeList
, const OUString
& aTemplateString
)
23 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
26 for (size_t j
= 0; j
< aRangeList
.size(); j
++)
30 aTemplate
.setTemplate(aTemplateString
);
31 aTemplate
.applyRange(u
"%VAR1%", aRangeList
[i
]);
32 aTemplate
.applyRange(u
"%VAR2%", aRangeList
[j
]);
33 aOutput
.writeFormula(aTemplate
.getTemplate());
42 ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
43 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
44 weld::Window
* pParent
, ScViewData
& rViewData
,
45 const OUString
& rUiXmlDescription
,
47 : ScStatisticsInputOutputDialog(pSfxBindings
, pChildWindow
, pParent
, rViewData
, rUiXmlDescription
, rID
)
50 ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
53 TranslateId
ScMatrixComparisonGenerator::GetUndoNameId()
55 return STR_CORRELATION_UNDO_NAME
;
58 ScRange
ScMatrixComparisonGenerator::ApplyOutput(ScDocShell
* pDocShell
)
60 AddressWalkerWriter
output(mOutputAddress
, pDocShell
, mDocument
,
61 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
62 FormulaTemplate
aTemplate(&mDocument
);
64 SCTAB inTab
= mInputRange
.aStart
.Tab();
66 ScRangeList aRangeList
= (mGroupedBy
== BY_COLUMN
) ?
67 MakeColumnRangeList(inTab
, mInputRange
.aStart
, mInputRange
.aEnd
) :
68 MakeRowRangeList(inTab
, mInputRange
.aStart
, mInputRange
.aEnd
);
71 output
.writeString(getLabel());
74 static constexpr OUString
strWildcardNumber(u
"%NUMBER%"_ustr
);
76 // write labels to columns
77 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
79 if (mGroupedBy
== BY_COLUMN
)
80 aTemplate
.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE
));
82 aTemplate
.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE
));
84 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
85 output
.writeString(aTemplate
.getTemplate());
89 // write labels to rows
92 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
94 if (mGroupedBy
== BY_COLUMN
)
95 aTemplate
.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE
));
97 aTemplate
.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE
));
99 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
100 output
.writeString(aTemplate
.getTemplate());
104 // write correlation formulas
108 lclWriteCorrelationFormulas(output
, aTemplate
, aRangeList
, getTemplate());
110 return ScRange(output
.mMinimumAddress
, output
.mMaximumAddress
);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */