File indexing completed on 2024-04-28 16:21:23

0001 /* This file is part of the KDE project
0002    Copyright 2008 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "FunctionModule.h"
0021 
0022 #include "Function.h"
0023 
0024 #include <QList>
0025 
0026 using namespace Calligra::Sheets;
0027 
0028 class Q_DECL_HIDDEN FunctionModule::Private
0029 {
0030 public:
0031     QList<QSharedPointer<Function> > functions;
0032 };
0033 
0034 
0035 FunctionModule::FunctionModule(QObject* parent)
0036         : QObject(parent)
0037         , d(new Private)
0038 {
0039 }
0040 
0041 FunctionModule::~FunctionModule()
0042 {
0043     delete d;
0044 }
0045 
0046 QList<QSharedPointer<Function> > FunctionModule::functions() const
0047 {
0048     return d->functions;
0049 }
0050 
0051 bool FunctionModule::isRemovable()
0052 {
0053     QList<Function*> checkedFunctions;
0054     QWeakPointer<Function> weakPointer;
0055     while (d->functions.count() != 0) {
0056         weakPointer = d->functions.last().toWeakRef();
0057         checkedFunctions.append(d->functions.takeLast().data());
0058         if (!weakPointer.isNull()) {
0059             // Put it and the other checked ones back in.
0060             d->functions.append(weakPointer.toStrongRef());
0061             // The failing on was used, so we do not put it in twice.
0062             checkedFunctions.removeLast();
0063             foreach(Function* function, checkedFunctions) {
0064                 // It is okay to recreate the shared pointers, as they were not used.
0065                 d->functions.append(QSharedPointer<Function>(function));
0066             }
0067             return false;
0068         }
0069     }
0070     return true;
0071 }
0072 
0073 QString FunctionModule::id() const
0074 {
0075     return descriptionFileName();
0076 }
0077 
0078 void FunctionModule::add(Function* function)
0079 {
0080     if (!function) {
0081         return;
0082     }
0083     d->functions.append(QSharedPointer<Function>(function));
0084 }