LibreOffice Module sc (master)  1
MatrixComparisonGenerator.cxx
Go to the documentation of this file.
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>
14 #include <scresid.hxx>
15 #include <strings.hrc>
16 
17 namespace
18 {
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 
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 
51 {}
52 
54 {
55  return STR_CORRELATION_UNDO_NAME;
56 }
57 
59 {
60  AddressWalkerWriter output(mOutputAddress, pDocShell, &mDocument,
62  FormulaTemplate aTemplate(&mDocument);
63 
64  SCTAB inTab = mInputRange.aStart.Tab();
65 
66  ScRangeList aRangeList = (mGroupedBy == BY_COLUMN) ?
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: */
void applyNumber(const OUString &aVariable, sal_Int32 aValue)
ScAddress aStart
Definition: address.hxx:500
void writeFormula(const OUString &aFormula)
static ScRangeList MakeRowRangeList(SCTAB aTab, ScAddress const &aStart, ScAddress const &aEnd)
void writeString(const OUString &aString)
virtual OUString getLabel()=0
ScAddress aEnd
Definition: address.hxx:501
void push(SCCOL aRelativeCol=0, SCROW aRelativeRow=0, SCTAB aRelativeTab=0)
formula::FormulaGrammar::AddressConvention eConv
Definition: address.hxx:213
static Grammar mergeToGrammar(const Grammar eGrammar, const AddressConvention eConv)
SCTAB Tab() const
Definition: address.hxx:271
virtual const char * GetUndoNameId() override
int i
size_t size() const
Definition: rangelst.hxx:90
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
void applyRange(const OUString &aVariable, const ScRange &aRange, bool b3D=true)
virtual OUString getTemplate()=0
virtual ScRange ApplyOutput(ScDocShell *pDocShell) override
void setTemplate(const OUString &aTemplate)
static ScRangeList MakeColumnRangeList(SCTAB aTab, ScAddress const &aStart, ScAddress const &aEnd)
sal_Int16 SCTAB
Definition: types.hxx:23
ScMatrixComparisonGenerator(SfxBindings *pSfxBindings, SfxChildWindow *pChildWindow, weld::Window *pParent, ScViewData *pViewData, const OUString &rUiXmlDescription, const OString &rID)