Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / StatisticsDialogs / MatrixComparisonGenerator.cxx
bloba5e5001e645b87b0bfaa939049d2dde28a97ddfa
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 <sfx2/dispatch.hxx>
12 #include <svl/zforlist.hxx>
13 #include <svl/undo.hxx>
15 #include "formulacell.hxx"
16 #include "rangelst.hxx"
17 #include "scitems.hxx"
18 #include "docsh.hxx"
19 #include "document.hxx"
20 #include "uiitems.hxx"
21 #include "reffact.hxx"
22 #include "strload.hxx"
23 #include "random.hxx"
24 #include "docfunc.hxx"
25 #include "StatisticsDialogs.hrc"
26 #include "TableFillingAndNavigationTools.hxx"
28 #include "MatrixComparisonGenerator.hxx"
30 namespace
32 static const OUString strWildcard1("%VAR1%");
33 static const OUString strWildcard2("%VAR2%");
35 static const OUString strWildcardNumber("%NUMBER%");
37 void lclWriteCorrelationFormulas(
38 AddressWalkerWriter& aOutput, FormulaTemplate& aTemplate,
39 ScRangeList aRangeList, const OUString& aTemplateString)
41 for (size_t i = 0; i < aRangeList.size(); i++)
43 aOutput.resetRow();
44 for (size_t j = 0; j < aRangeList.size(); j++)
46 if (j >= i)
48 aTemplate.setTemplate(aTemplateString);
49 aTemplate.applyRange(strWildcard1, *aRangeList[i]);
50 aTemplate.applyRange(strWildcard2, *aRangeList[j]);
51 aOutput.writeFormula(aTemplate.getTemplate());
53 aOutput.nextRow();
55 aOutput.nextColumn();
60 ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
61 SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
62 Window* pParent, ScViewData* pViewData, const OString& rID,
63 const OUString& rUiXmlDescription) :
64 ScStatisticsInputOutputDialog(pSfxBindings, pChildWindow, pParent, pViewData, rID, rUiXmlDescription)
67 ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
70 sal_Int16 ScMatrixComparisonGenerator::GetUndoNameId()
72 return STR_CORRELATION_UNDO_NAME;
75 ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
77 AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
78 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
79 FormulaTemplate aTemplate(mDocument, mAddressDetails);
81 SCTAB inTab = mInputRange.aStart.Tab();
83 ScRangeList aRangeList;
85 if (mGroupedBy == BY_COLUMN)
86 aRangeList = MakeColumnRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
87 else
88 aRangeList = MakeRowRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
90 // labels
91 output.writeString(getLabel());
92 output.nextColumn();
94 // write labels to columns
95 for (size_t i = 0; i < aRangeList.size(); i++)
97 if (mGroupedBy == BY_COLUMN)
98 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
99 else
100 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
102 aTemplate.applyNumber(strWildcardNumber, i + 1);
103 output.writeString(aTemplate.getTemplate());
104 output.nextColumn();
107 // write labels to rows
108 output.resetColumn();
109 output.nextRow();
110 for (size_t i = 0; i < aRangeList.size(); i++)
112 if (mGroupedBy == BY_COLUMN)
113 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
114 else
115 aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
117 aTemplate.applyNumber(strWildcardNumber, i + 1);
118 output.writeString(aTemplate.getTemplate());
119 output.nextRow();
122 // write correlation formulas
123 output.reset();
124 output.push(1, 1);
126 lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
128 return ScRange(output.mMinimumAddress, output.mMaximumAddress);
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */