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

0001 /* This file is part of the KDE project
0002    Copyright 2007 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 #ifndef CALLIGRA_SHEETS_NAMED_AREA_MANAGER
0021 #define CALLIGRA_SHEETS_NAMED_AREA_MANAGER
0022 
0023 #include <QList>
0024 #include <QObject>
0025 
0026 #include "Region.h"
0027 
0028 #include "sheets_odf_export.h"
0029 
0030 class QDomDocument;
0031 class QDomElement;
0032 class QString;
0033 class KoXmlElement;
0034 
0035 namespace Calligra
0036 {
0037 namespace Sheets
0038 {
0039 class Map;
0040 class Region;
0041 
0042 /**
0043  * Manages named cell areas.
0044  */
0045 class CALLIGRA_SHEETS_ODF_EXPORT NamedAreaManager : public QObject
0046 {
0047     Q_OBJECT
0048 
0049 public:
0050     /**
0051      * Constructor.
0052      */
0053     explicit NamedAreaManager(const Map *map);
0054 
0055     /**
0056      * Destructor.
0057      */
0058     ~NamedAreaManager() override;
0059 
0060     const Map *map() const;
0061 
0062     void remove(Sheet* sheet);
0063 
0064     Region namedArea(const QString& name) const;
0065     Sheet* sheet(const QString& name) const;
0066     bool contains(const QString& name) const;
0067 
0068     /**
0069      * Returns the list of all registered named areas.
0070      * \return the list of named areas
0071      */
0072     QList<QString> areaNames() const;
0073 
0074     void regionChanged(const Region& region);
0075     void updateAllNamedAreas();
0076 
0077     /// \ingroup NativeFormat
0078     void loadXML(const KoXmlElement& element);
0079     /// \ingroup NativeFormat
0080     QDomElement saveXML(QDomDocument& doc) const;
0081 
0082 public Q_SLOTS:
0083     /**
0084      * Adds a named area.
0085      * \note The name is valid for the whole document.
0086      * \param region the cell range to be named
0087      * \param name the name of the new area
0088      */
0089     void insert(const Region& region, const QString& name);
0090 
0091     void remove(const QString& name);
0092 
0093 Q_SIGNALS:
0094     void namedAreaAdded(const QString&);
0095     void namedAreaRemoved(const QString&);
0096     void namedAreaModified(const QString&);
0097 
0098 private:
0099     class Private;
0100     Private * const d;
0101 };
0102 
0103 } // namespace Sheets
0104 } // namespace Calligra
0105 
0106 #endif // CALLIGRA_SHEETS_NAMED_AREA_MANAGER