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#include "FunctionModule.h"
21
22#include "Function.h"
23
24#include <QList>
25
26using namespace Calligra::Sheets;
27
28class FunctionModule::Private
29{
30public:
31 QList<QSharedPointer<Function> > functions;
32};
33
34
35FunctionModule::FunctionModule(QObject* parent)
36 : QObject(parent)
37 , d(new Private)
38{
39}
40
41FunctionModule::~FunctionModule()
42{
43 delete d;
44}
45
46QList<QSharedPointer<Function> > FunctionModule::functions() const
47{
48 return d->functions;
49}
50
51bool FunctionModule::isRemovable()
52{
53 QList<Function*> checkedFunctions;
54 QWeakPointer<Function> weakPointer;
55 while (d->functions.count() != 0) {
56 weakPointer = d->functions.last().toWeakRef();
57 checkedFunctions.append(d->functions.takeLast().data());
58 if (!weakPointer.isNull()) {
59 // Put it and the other checked ones back in.
60 d->functions.append(weakPointer.toStrongRef());
61 // The failing on was used, so we do not put it in twice.
62 checkedFunctions.removeLast();
63 foreach(Function* function, checkedFunctions) {
64 // It is okay to recreate the shared pointers, as they were not used.
65 d->functions.append(QSharedPointer<Function>(function));
66 }
67 return false;
68 }
69 }
70 return true;
71}
72
73QString FunctionModule::id() const
74{
75 return descriptionFileName();
76}
77
78void FunctionModule::add(Function* function)
79{
80 if (!function) {
81 return;
82 }
83 d->functions.append(QSharedPointer<Function>(function));
84}
85
86#include "FunctionModule.moc"
87