kspread
functions.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KSPREAD_FUNCTIONS
00023 #define KSPREAD_FUNCTIONS
00024
00025 #include <qstringlist.h>
00026 #include <qvaluevector.h>
00027
00028 class QDomElement;
00029
00030 namespace KSpread
00031 {
00032 class Sheet;
00033 class Value;
00034 class ValueCalc;
00035
00036 typedef QValueVector<Value> valVector;
00037
00038 struct rangeInfo {
00039 int col1, col2, row1, row2;
00040 };
00041 struct FuncExtra {
00042
00043 QValueVector<rangeInfo> ranges;
00044 Sheet *sheet;
00045 int myrow, mycol;
00046 };
00047
00048 typedef Value (*FunctionPtr)(valVector, ValueCalc *, FuncExtra *);
00049
00050 class Function
00051 {
00052 public:
00053 Function (const QString& name, FunctionPtr ptr);
00054 ~Function();
00059 void setParamCount (int min, int max = 0);
00061 bool paramCountOkay (int count);
00065 void setAcceptArray (bool accept = true);
00066 bool needsExtra ();
00067 void setNeedsExtra (bool extra);
00068 QString name() const;
00069 QString localizedName() const;
00070 QString helpText() const;
00071 void setHelpText( const QString& text );
00072 Value exec (valVector args, ValueCalc *calc, FuncExtra *extra = 0);
00073
00074 private:
00075 class Private;
00076 Private* d;
00077 };
00078
00079 enum ParameterType { KSpread_Int, KSpread_Float, KSpread_String, KSpread_Boolean, KSpread_Any };
00080
00081 class FunctionParameter
00082 {
00083 public:
00084 FunctionParameter();
00085 FunctionParameter( const FunctionParameter& param );
00086 FunctionParameter( const QDomElement& element );
00087
00088 QString helpText() const { return m_help; }
00089 ParameterType type() const { return m_type; }
00090 bool hasRange() const { return m_range; }
00091
00092 private:
00093 QString m_help;
00094 ParameterType m_type;
00095 bool m_range;
00096 };
00097
00098 class FunctionDescription
00099 {
00100 public:
00101 FunctionDescription();
00102 FunctionDescription (const QDomElement& element);
00103 FunctionDescription (const FunctionDescription& desc);
00104
00105 const QStringList& examples() { return m_examples; }
00106 const QStringList& syntax() { return m_syntax; }
00107 const QStringList& related() { return m_related; }
00108 const QStringList& helpText() const { return m_help; }
00109 QString name() const { return m_name; }
00110 ParameterType type() const { return m_type; }
00111
00112 int params() const { return m_params.count(); }
00113 FunctionParameter& param( int i ) { return m_params[ i ]; }
00114
00115 void setGroup( const QString& g ) { m_group = g; }
00116 QString group() const { return m_group; }
00117
00118 QString toQML() const;
00119
00120 private:
00121 QString m_group;
00122 QStringList m_examples;
00123 QStringList m_syntax;
00124 QStringList m_related;
00125 QStringList m_help;
00126 QString m_name;
00127 ParameterType m_type;
00128 QValueList<FunctionParameter> m_params;
00129 };
00130
00131 class FunctionRepository
00132 {
00133 public:
00134 FunctionRepository();
00135 ~FunctionRepository();
00136
00137 static FunctionRepository *self();
00138
00139 void add (Function *function);
00140
00141 Function *function (const QString& name);
00142
00143 FunctionDescription *functionInfo (const QString& name);
00144
00146 QStringList functionNames (const QString& group = QString::null);
00147
00148 const QStringList &groups () const { return m_groups; }
00149
00150 private:
00151
00152 class Private;
00153 Private* d;
00154
00155 static FunctionRepository* s_self;
00156
00158 void loadFile (const QString& filename);
00159
00160 QStringList m_groups;
00161
00162
00163 FunctionRepository( const FunctionRepository& );
00164 FunctionRepository& operator=( const FunctionRepository& );
00165 };
00166
00167
00168 }
00169
00170
00171 #endif // KSPREAD_FUNCTIONS
|