1/* This file is part of the KDE project
2 Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18*/
19
20#ifndef CALLIGRA_SHEETS_FUNCTION_MODULE
21#define CALLIGRA_SHEETS_FUNCTION_MODULE
22
23#include <calligraversion.h>
24
25#include <QList>
26#include <QObject>
27#include <QSharedPointer>
28#include <QString>
29#include <kpluginfactory.h>
30
31#include "calligra_sheets_export.h"
32
33namespace Calligra
34{
35namespace Sheets
36{
37class Function;
38
39/**
40 * \ingroup Value
41 * A function module provides several Function objects.
42 */
43class CALLIGRA_SHEETS_ODF_EXPORT FunctionModule : public QObject
44{
45 Q_OBJECT
46public:
47 /**
48 * Creates the function module.
49 * The derived class should create here the Function objects and
50 * should register them via \ref add.
51 */
52 explicit FunctionModule(QObject *parent);
53
54 /**
55 * Destroys the module and the provided Function objects.
56 * Check, if this module isRemovable(), before you unload the plugin.
57 */
58 virtual ~FunctionModule();
59
60 /**
61 * Returns the file name of the XML description for the functions.
62 */
63 virtual QString descriptionFileName() const = 0;
64
65 /**
66 * Returns a list of the provided Function objects.
67 */
68 QList<QSharedPointer<Function> > functions() const;
69
70 /**
71 * Checks whether this module can be removed, because none of its
72 * Function objects is in use.
73 * Used by the FunctionModuleRegistry to check, if the plugin can be unloaded.
74 * \return \c true on success; \c false on failure
75 */
76 bool isRemovable();
77
78 /**
79 * Returns the identifier (if defined). Function of the KoGenericRegistry
80 * template, that has to be implemented.
81 */
82 virtual QString id() const;
83
84protected:
85 /**
86 * Adds \p function to the list of provided Function objects.
87 */
88 void add(Function* function);
89
90private:
91 class Private;
92 Private * const d;
93};
94
95} // namespace Sheets
96} // namespace Calligra
97
98/**
99* Register a function module when it is contained in a loadable plugin
100*/
101#ifndef SHEETS_NO_PLUGINMODULES
102#define CALLIGRA_SHEETS_EXPORT_FUNCTION_MODULE(libname, classname) \
103 K_PLUGIN_FACTORY(factory, registerPlugin<classname>();) \
104 K_EXPORT_PLUGIN(factory("calligra-sheets-functions-" #libname)) \
105 K_EXPORT_PLUGIN_VERSION(CALLIGRA_VERSION)
106#else
107#define CALLIGRA_SHEETS_EXPORT_FUNCTION_MODULE(libname, classname)
108#endif
109
110#endif // CALLIGRA_SHEETS_FUNCTION_MODULE
111