tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / MatrixComparisonGenerator.cxx
blobf2059ff822a88238b61857946ee9fa5e1e8fc2fd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 */
11 #include <rangelst.hxx>
12 #include <TableFillingAndNavigationTools.hxx>
13 #include <MatrixComparisonGenerator.hxx>
14 #include <scresid.hxx>
15 #include <strings.hrc>
17 namespace
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++)
25 aOutput.resetRow();
26 for (size_t j = 0; j < aRangeList.size(); j++)
28 if (j >= i)
30 aTemplate.setTemplate(aTemplateString);
31 aTemplate.applyRange(u"%VAR1%", aRangeList[i]);
32 aTemplate.applyRange(u"%VAR2%", aRangeList[j]);
33 aOutput.writeFormula(aTemplate.getTemplate());
35 aOutput.nextRow();
37 aOutput.nextColumn();
42 ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
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)
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);
70 // labels
71 output.writeString(getLabel());
72 output.nextColumn();
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));
81 else
82 aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
84 aTemplate.applyNumber(strWildcardNumber, i + 1);
85 output.writeString(aTemplate.getTemplate());
86 output.nextColumn();
89 // write labels to rows
90 output.resetColumn();
91 output.nextRow();
92 for (size_t i = 0; i < aRangeList.size(); i++)
94 if (mGroupedBy == BY_COLUMN)
95 aTemplate.setTemplate(ScResId(STR_COLUMN_LABEL_TEMPLATE));
96 else
97 aTemplate.setTemplate(ScResId(STR_ROW_LABEL_TEMPLATE));
99 aTemplate.applyNumber(strWildcardNumber, i + 1);
100 output.writeString(aTemplate.getTemplate());
101 output.nextRow();
104 // write correlation formulas
105 output.reset();
106 output.push(1, 1);
108 lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
110 return ScRange(output.mMinimumAddress, output.mMaximumAddress);
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */