summaryrefslogtreecommitdiff
path: root/sc/source/ui/inc/RegressionDialog.hxx
blob: 722fece342790095afd3f3785a4ecc399603f058 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#ifndef INCLUDED_SC_SOURCE_UI_INC_REGRESSIONDIALOG_HXX
#define INCLUDED_SC_SOURCE_UI_INC_REGRESSIONDIALOG_HXX

#include "StatisticsTwoVariableDialog.hxx"

class ScRegressionDialog : public ScStatisticsTwoVariableDialog
{
    VclPtr<CheckBox>     mpWithLabelsCheckBox;
    VclPtr<RadioButton>  mpLinearRadioButton;
    VclPtr<RadioButton>  mpLogarithmicRadioButton;
    VclPtr<RadioButton>  mpPowerRadioButton;
    VclPtr<FixedText>    mpErrorMessage;
    VclPtr<NumericField> mpConfidenceLevelField;
    VclPtr<CheckBox>     mpCalcResidualsCheckBox;

    bool mbUnivariate;
    size_t mnNumIndependentVars;
    size_t mnNumObservations;
    bool mbUse3DAddresses;

public:
    ScRegressionDialog(
        SfxBindings* pB, SfxChildWindow* pCW,
        vcl::Window* pParent, ScViewData* pViewData );

    virtual ~ScRegressionDialog() override;

    virtual bool Close() override;

protected:
    void dispose() override;
    virtual const char* GetUndoNameId() override;
    virtual ScRange ApplyOutput(ScDocShell* pDocShell) override;
    virtual bool InputRangesValid() override;

private:

    using CellValueGetter = const OUString&(size_t, size_t);
    using CellWriter = void(const OUString&, size_t, size_t);

    size_t GetRegressionTypeIndex();
    ScRange GetDataRange(const ScRange& rRange);
    OUString GetVariableNameFormula(bool bXVar, size_t nIndex, bool bWithLog);
    OUString GetXVariableNameFormula(size_t nIndex, bool bWithLog);
    OUString GetYVariableNameFormula(bool bWithLog);

    // Helper methods for writing different parts of regression results.
    void WriteRawRegressionResults(AddressWalkerWriter& rOutput,
                                   FormulaTemplate& rTemplate,
                                   size_t nRegressionIndex);
    void WriteRegressionStatistics(AddressWalkerWriter& rOutput,
                                   FormulaTemplate& rTemplate);
    void WriteRegressionANOVAResults(AddressWalkerWriter& rOutput,
                                     FormulaTemplate& rTemplate);
    void WriteRegressionEstimatesWithCI(AddressWalkerWriter& rOutput,
                                        FormulaTemplate& rTemplate,
                                        bool bTakeLogX);
    void WritePredictionsWithResiduals(AddressWalkerWriter& rOutput,
                                       FormulaTemplate& rTemplate,
                                       size_t nRegressionIndex);
    // Generic table writer
    void WriteTable(std::function<CellValueGetter>& rCellGetter, size_t nRowsInTable,
                    size_t nColsInTable, AddressWalkerWriter& rOutput,
                    std::function<CellWriter>& rFunc);

    DECL_LINK( CheckBoxHdl, CheckBox&, void );
    DECL_LINK( NumericFieldHdl, Edit&, void );
};


#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */