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"
24 #include "docfunc.hxx"
25 #include "StatisticsDialogs.hrc"
26 #include "TableFillingAndNavigationTools.hxx"
28 #include "MatrixComparisonGenerator.hxx"
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
++)
44 for (size_t j
= 0; j
< aRangeList
.size(); j
++)
48 aTemplate
.setTemplate(aTemplateString
);
49 aTemplate
.applyRange(strWildcard1
, *aRangeList
[i
]);
50 aTemplate
.applyRange(strWildcard2
, *aRangeList
[j
]);
51 aOutput
.writeFormula(aTemplate
.getTemplate());
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
);
88 aRangeList
= MakeRowRangeList(inTab
, mInputRange
.aStart
, mInputRange
.aEnd
);
91 output
.writeString(getLabel());
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
));
100 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ROW_LABEL_TEMPLATE
));
102 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
103 output
.writeString(aTemplate
.getTemplate());
107 // write labels to rows
108 output
.resetColumn();
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
));
115 aTemplate
.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS
, STR_ROW_LABEL_TEMPLATE
));
117 aTemplate
.applyNumber(strWildcardNumber
, i
+ 1);
118 output
.writeString(aTemplate
.getTemplate());
122 // write correlation formulas
126 lclWriteCorrelationFormulas(output
, aTemplate
, aRangeList
, getTemplate());
128 return ScRange(output
.mMinimumAddress
, output
.mMaximumAddress
);
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */