1 | /* This file is part of the KDE project |
2 | Copyright (C) 2003,2004 Ariya Hidayat <ariya@kde.org> |
3 | Copyright (C) 2005 Tomas Mecir <mecirt@gmail.com> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; only |
8 | version 2 of the License. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | |
22 | #ifndef CALLIGRA_SHEETS_FUNCTIONS |
23 | #define CALLIGRA_SHEETS_FUNCTIONS |
24 | |
25 | #include <QList> |
26 | #include <QStringList> |
27 | #include <QVector> |
28 | |
29 | #include "Region.h" |
30 | #include "Value.h" |
31 | |
32 | #include "calligra_sheets_export.h" |
33 | |
34 | class QDomElement; |
35 | |
36 | namespace Calligra |
37 | { |
38 | namespace Sheets |
39 | { |
40 | class Sheet; |
41 | class ValueCalc; |
42 | class Function; |
43 | |
44 | typedef QVector<Value> valVector; |
45 | |
46 | struct rangeInfo { |
47 | int col1, col2, row1, row2; |
48 | int columns() { |
49 | return col2 - col1 + 1; |
50 | } |
51 | int rows() { |
52 | return row2 - row1 + 1; |
53 | } |
54 | }; |
55 | struct { |
56 | // here we'll add all the extras a function may need |
57 | Function* ; |
58 | QVector<rangeInfo> ; |
59 | QVector<Region> ; |
60 | Sheet *; |
61 | int , ; |
62 | }; |
63 | |
64 | typedef Value(*FunctionPtr)(valVector, ValueCalc *, FuncExtra *); |
65 | |
66 | /** |
67 | * \ingroup Value |
68 | * A function pointer and context. |
69 | */ |
70 | class CALLIGRA_SHEETS_ODF_EXPORT Function |
71 | { |
72 | public: |
73 | (const QString& name, FunctionPtr ptr); |
74 | virtual ~Function(); |
75 | /** |
76 | setParamCount sets allowed parameter count for a function. |
77 | if max=0, it means max=min. If max=-1, there is no upper limit. |
78 | */ |
79 | void setParamCount(int min, int max = 0); |
80 | /** is it okay for the function to receive this many parameters ? */ |
81 | bool paramCountOkay(int count); |
82 | /** when set to true, the function can receive arrays. When set to |
83 | false, the auto-array mechamism will be used for arrays (so the |
84 | function will receive simple values, not arrays). */ |
85 | void setAcceptArray(bool accept = true); |
86 | bool (); |
87 | void (bool ); |
88 | QString name() const; |
89 | QString localizedName() const; |
90 | QString helpText() const; |
91 | void setHelpText(const QString& text); |
92 | Value (valVector args, ValueCalc *calc, FuncExtra * = 0); |
93 | |
94 | QString alternateName() const; |
95 | void setAlternateName(const QString &name); |
96 | |
97 | private: |
98 | Q_DISABLE_COPY(Function) |
99 | |
100 | class Private; |
101 | Private * const d; |
102 | }; |
103 | |
104 | /** |
105 | * \ingroup Value |
106 | * A helper-class to call a function. |
107 | */ |
108 | class CALLIGRA_SHEETS_ODF_EXPORT FunctionCaller { |
109 | public: |
110 | FunctionPtr m_ptr; |
111 | valVector m_args; |
112 | ValueCalc *m_calc; |
113 | FuncExtra *; |
114 | |
115 | (FunctionPtr ptr, const valVector &args, ValueCalc *calc, FuncExtra * = 0); |
116 | Value exec(); |
117 | Value exec(const valVector &args); |
118 | }; |
119 | |
120 | } // namespace Sheets |
121 | } // namespace Calligra |
122 | |
123 | #endif // CALLIGRA_SHEETS_FUNCTIONS |
124 | |