Line data Source code
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 <sfx2/dispatch.hxx>
12 : #include <svl/zforlist.hxx>
13 : #include <svl/undo.hxx>
14 :
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 "docfunc.hxx"
24 : #include "StatisticsDialogs.hrc"
25 : #include "TableFillingAndNavigationTools.hxx"
26 :
27 : #include "MatrixComparisonGenerator.hxx"
28 :
29 : namespace
30 : {
31 0 : void lclWriteCorrelationFormulas(
32 : AddressWalkerWriter& aOutput, FormulaTemplate& aTemplate,
33 : const ScRangeList& aRangeList, const OUString& aTemplateString)
34 : {
35 0 : for (size_t i = 0; i < aRangeList.size(); i++)
36 : {
37 0 : aOutput.resetRow();
38 0 : for (size_t j = 0; j < aRangeList.size(); j++)
39 : {
40 0 : if (j >= i)
41 : {
42 0 : aTemplate.setTemplate(aTemplateString);
43 0 : aTemplate.applyRange("%VAR1%", *aRangeList[i]);
44 0 : aTemplate.applyRange("%VAR2%", *aRangeList[j]);
45 0 : aOutput.writeFormula(aTemplate.getTemplate());
46 : }
47 0 : aOutput.nextRow();
48 : }
49 0 : aOutput.nextColumn();
50 : }
51 0 : }
52 : }
53 :
54 0 : ScMatrixComparisonGenerator::ScMatrixComparisonGenerator(
55 : SfxBindings* pSfxBindings, SfxChildWindow* pChildWindow,
56 : vcl::Window* pParent, ScViewData* pViewData, const OString& rID,
57 : const OUString& rUiXmlDescription) :
58 0 : ScStatisticsInputOutputDialog(pSfxBindings, pChildWindow, pParent, pViewData, rID, rUiXmlDescription)
59 0 : {}
60 :
61 0 : ScMatrixComparisonGenerator::~ScMatrixComparisonGenerator()
62 0 : {}
63 :
64 0 : sal_Int16 ScMatrixComparisonGenerator::GetUndoNameId()
65 : {
66 0 : return STR_CORRELATION_UNDO_NAME;
67 : }
68 :
69 0 : ScRange ScMatrixComparisonGenerator::ApplyOutput(ScDocShell* pDocShell)
70 : {
71 : AddressWalkerWriter output(mOutputAddress, pDocShell, mDocument,
72 0 : formula::FormulaGrammar::mergeToGrammar( formula::FormulaGrammar::GRAM_ENGLISH, mAddressDetails.eConv));
73 0 : FormulaTemplate aTemplate(mDocument);
74 :
75 0 : SCTAB inTab = mInputRange.aStart.Tab();
76 :
77 0 : ScRangeList aRangeList;
78 :
79 0 : if (mGroupedBy == BY_COLUMN)
80 0 : aRangeList = MakeColumnRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
81 : else
82 0 : aRangeList = MakeRowRangeList(inTab, mInputRange.aStart, mInputRange.aEnd);
83 :
84 : // labels
85 0 : output.writeString(getLabel());
86 0 : output.nextColumn();
87 :
88 0 : const OUString strWildcardNumber("%NUMBER%");
89 :
90 : // write labels to columns
91 0 : for (size_t i = 0; i < aRangeList.size(); i++)
92 : {
93 0 : if (mGroupedBy == BY_COLUMN)
94 0 : aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
95 : else
96 0 : aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
97 :
98 0 : aTemplate.applyNumber(strWildcardNumber, i + 1);
99 0 : output.writeString(aTemplate.getTemplate());
100 0 : output.nextColumn();
101 : }
102 :
103 : // write labels to rows
104 0 : output.resetColumn();
105 0 : output.nextRow();
106 0 : for (size_t i = 0; i < aRangeList.size(); i++)
107 : {
108 0 : if (mGroupedBy == BY_COLUMN)
109 0 : aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_COLUMN_LABEL_TEMPLATE));
110 : else
111 0 : aTemplate.setTemplate(SC_STRLOAD(RID_STATISTICS_DLGS, STR_ROW_LABEL_TEMPLATE));
112 :
113 0 : aTemplate.applyNumber(strWildcardNumber, i + 1);
114 0 : output.writeString(aTemplate.getTemplate());
115 0 : output.nextRow();
116 : }
117 :
118 : // write correlation formulas
119 0 : output.reset();
120 0 : output.push(1, 1);
121 :
122 0 : lclWriteCorrelationFormulas(output, aTemplate, aRangeList, getTemplate());
123 :
124 0 : return ScRange(output.mMinimumAddress, output.mMaximumAddress);
125 228 : }
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|