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 <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"
19 #include "document.hxx"
20 #include "uiitems.hxx"
21 #include "reffact.hxx"
22 #include "strload.hxx"
23 #include "docfunc.hxx"
24 #include "StatisticsDialogs.hrc"
25 #include "TableFillingAndNavigationTools.hxx"
27 #include "MatrixComparisonGenerator.hxx"
31 void lclWriteCorrelationFormulas(
32 AddressWalkerWriter
& aOutput
, FormulaTemplate
& aTemplate
,
33 const ScRangeList
& aRangeList
, const OUString
& aTemplateString
)
35 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
38 for (size_t j
= 0; j
< aRangeList
.size(); j
++)
42 aTemplate
.setTemplate(aTemplateString
);
43 aTemplate
.applyRange("%VAR1%", *aRangeList
[i
]);
44 aTemplate
.applyRange("%VAR2%", *aRangeList
[j
]);
45 aOutput
.writeFormula(aTemplate
.getTemplate());
54 ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
55 SfxBindings
* pSfxBindings
, SfxChildWindow
* pChildWindow
,
56 vcl::Window
* pParent
, ScViewData
* pViewData
, const OUString
& rID
,
57 const OUString
& rUiXmlDescription
) :
58 ScStatisticsInputOutputDialog(pSfxBindings
, pChildWindow
, pParent
, pViewData
, rID
, rUiXmlDescription
)
61 ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
64 sal_Int16
ScMatrixComparisonGenerator::GetUndoNameId()
66 return STR_CORRELATION_UNDO_NAME
;
69 ScRange
ScMatrixComparisonGenerator::ApplyOutput(ScDocShell
* pDocShell
)
71 AddressWalkerWriter
output(mOutputAddress
, pDocShell
, mDocument
,
72 formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH
, mAddressDetails
.eConv
));
73 FormulaTemplate
aTemplate(mDocument
);
75 SCTAB inTab
= mInputRange
.aStart
.Tab();
77 ScRangeList aRangeList
;
79 if (mGroupedBy
== BY_COLUMN
)
80 aRangeList
= MakeColumnRangeList(inTab
, mInputRange
.aStart
, mInputRange
.aEnd
);
82 aRangeList
= MakeRowRangeList(inTab
, mInputRange
.aStart
, mInputRange
.aEnd
);
85 output
.writeString(getLabel());
88 const OUString
strWildcardNumber("%NUMBER%");
90 // write labels to columns
91 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
93 if (mGroupedBy
== BY_COLUMN
)
94 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_COLUMN_LABEL_TEMPLATE
));
96 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ROW_LABEL_TEMPLATE
));
98 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
99 output
.writeString(aTemplate
.getTemplate());
103 // write labels to rows
104 output
.resetColumn();
106 for (size_t i
= 0; i
< aRangeList
.size(); i
++)
108 if (mGroupedBy
== BY_COLUMN
)
109 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_COLUMN_LABEL_TEMPLATE
));
111 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ROW_LABEL_TEMPLATE
));
113 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
114 output
.writeString(aTemplate
.getTemplate());
118 // write correlation formulas
122 lclWriteCorrelationFormulas(output
, aTemplate
, aRangeList
, getTemplate());
124 return ScRange(output
.mMinimumAddress
, output
.mMaximumAddress
);
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */