summaryrefslogtreecommitdiff
path: root/sc/inc/units.hxx
blob: 381ec7dc08e150617861b5d8acf6049fa74e03cd (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* -*- 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_INC_UNITS_HXX
#define INCLUDED_SC_INC_UNITS_HXX

#include <rtl/ustring.hxx>

#include <boost/shared_ptr.hpp>

class ScAddress;
class ScDocument;
class ScRange;
class ScTokenArray;

namespace sc {
namespace units {

class UnitsImpl;

class Units {
public:
    static ::boost::shared_ptr< Units > GetUnits();

    virtual bool verifyFormula(ScTokenArray* pArray, const ScAddress& rFormulaAddress, ScDocument* pDoc) = 0;

    /*
     * Split the input into value and unit, where rInput == rValue + rUnit.
     * (We assume that the unit is always the last part of the input string.)
     *
     * Returns whether or not the string has been split.
     * rValue and rUnit are always set to valid values, irrespective of string
     * splitting having actually taken place.
     */
    virtual bool splitUnitsFromInputString(const OUString& rInput, OUString& rValue, OUString& rUnit) = 0;

    /**
     * Check whether a cell should have it's data converted to another unit for
     * sensible unit verification.
     *
     * Returns true if the cell has a local unit annotation (e.g. contains "10cm",
     * but split into value (10) and unit format ('#"cm"')), but the column header
     * defines a different unit (e.g. "length [m]).
     * The data returned can then be used by convertCellToHeaderUnit if the user
     * desires conversion in this case.
     *
     * If returning false, the header and cell units will be empty and the address invalid.
     */
    virtual bool isCellConversionRecommended(const ScAddress& rCellAddress,
                                             ScDocument* pDoc,
                                             OUString& rHeaderUnit,
                                             ScAddress& rHeaderCellAddress,
                                             OUString& rCellUnit) = 0;

    /**
     * Convert a cell with local unit annotation to store data in the units represented by
     * its (column-level) header.
     *
     * This method should only be used with the data provided by isCellConversionRecommended.
     * It will remove the cell's local unit annotation, and not add any of it's own annotation.
     * You should use the (yet to be implemented) convertCells() method for more generic
     * unit conversion.
     *
     * Returns true for successful conversion, false if an error occured (e.g. if the data
     * has been modified in the meantime, i.e. that the units no longer correspond
     * to the expected annotation or header).
     */
    virtual bool convertCellToHeaderUnit(const ScAddress& rCellAddress,
                                         ScDocument* pDoc,
                                         const OUString& rsNewUnit,
                                         const OUString& rsOldUnit) = 0;

    /**
     * Convert cells from one unit to another.
     *
     * If possible the input unit will be determined automatically (using local
     * and header units).
     *
     * Returns false if input units are not compatible with the desired output units,
     * (including the case where some of the input units are compatibles but others
     *  aren't).
     *
     * Local and header unit annotations are modified as appropriate such that the output
     * remains unambiguous. Hence, if the header cell is included in rRange, its unit
     * annotation is also updated as appropriate. If instead the header is excluded,
     * but all other cells are selected in a column, then local annotations are added.
     *
     * rsInputUnit overrides the automatic determination of input units, i.e. disables
     * input unit detection.
     */
    virtual bool convertCellUnits(const ScRange& rRange,
                                  ScDocument* pDoc,
                                  const OUString& rsOutputUnit) = 0;

    virtual ~Units() {}
};

}} // namespace sc::units

#endif // INCLUDED_SC_INC_UNITS_HXX

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