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 {
lclWriteCorrelationFormulas(AddressWalkerWriter & aOutput,FormulaTemplate & aTemplate,const ScRangeList & aRangeList,const OUString & aTemplateString)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("%VAR1%", aRangeList[i]);
32 aTemplate.applyRange("%VAR2%", aRangeList[j]);
33 aOutput.writeFormula(aTemplate.getTemplate());
34 }
35 aOutput.nextRow();
36 }
37 aOutput.nextColumn();
38 }
39 }
40 }
41
ScMatrixComparisonGenerator(SfxBindings * pSfxBindings,SfxChildWindow * pChildWindow,weld::Window * pParent,ScViewData * pViewData,const OUString & rUiXmlDescription,const OString & rID)42 ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
43 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
44 weld::Window* pParent, ScViewData* pViewData,
45 const OUString& rUiXmlDescription,
46 const OString& rID)
47 : ScStatisticsInputOutputDialog(pSfxBindings, pChildWindow, pParent, pViewData, rUiXmlDescription, rID)
48 {}
49
~ScMatrixComparisonGenerator()50 ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
51 {}
52
GetUndoNameId()53 const char* ScMatrixComparisonGenerator::GetUndoNameId()
54 {
55 return STR_CORRELATION_UNDO_NAME;
56 }
57
ApplyOutput(ScDocShell * pDocShell)58 ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
59 {
60 AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
61 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
62 FormulaTemplate aTemplate(mDocument);
63
64 SCTAB inTab = mInputRange.aStart.Tab();
65
66 ScRangeList aRangeList = (mGroupedBy == BY_COLUMN) ?
67 MakeColumnRangeList(inTab, mInputRange.aStart, mInputRange.aEnd) :
68 MakeRowRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
69
70 // labels
71 output.writeString(getLabel());
72 output.nextColumn();
73
74 const OUString strWildcardNumber("%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: */
114