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

0001 /* This file is part of the KDE project
0002    Copyright 2009 Johannes Simon <johannes.simon@gmail.com>
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 SHEETACCESSMODEL_H
0021 #define SHEETACCESSMODEL_H
0022 
0023 #include <QStandardItemModel>
0024 
0025 #include "Sheet.h"
0026 
0027 namespace Calligra
0028 {
0029 namespace Sheets
0030 {
0031 
0032 class Damage;
0033 class Map;
0034 class Sheet;
0035 
0036 /**
0037  * @brief Class that can be used by any shape embedded in Calligra Sheets to access sheet data,
0038  * without the need to link against Calligra Sheets. It is available through the Doc's data center map,
0039  * or KoShapeLoadingContext::dataCenterMap() in the process of loading a shape from ODF.
0040  *
0041  * Essentially, this model is a list of models to access a sheet's data. It contains a single row,
0042  * and has exactly one sheet model per column. In short, a model containing models.
0043  *
0044  * To allow name-based referencing of a sheet's data (e.g. in an ODF-conform cell region like "Table1.A1:B2")
0045  * each column's header contains the name of the sheet returned by KSpread::Sheet::sheetName() .
0046  *
0047  * To access the QAbstractItemModel instance for a sheet's data, take the following code as example:
0048  * @code
0049  * QAbstractItemModel *sheetAccessModel = dynamic_cast<QAbstractItemModel*>( dataCenterMap["SheetAccessModel"] );
0050  * QModelIndex firstSheetIndex = sheetAccessModel->index( 0, 0 );
0051  * QPointer<QAbstractItemModel> firstSheet = sheetAccessModel->data( firstSheetIndex ).value< QPointer<QAbstractItemModel> >();
0052  * view->setModel( firstSheet.data() );
0053  * @endcode
0054  */
0055 class SheetAccessModel : public QStandardItemModel
0056 {
0057     Q_OBJECT
0058 
0059 public:
0060     explicit SheetAccessModel(Map *map);
0061     ~SheetAccessModel() override;
0062 
0063 public Q_SLOTS:
0064     void slotSheetAdded(Sheet *sheet);
0065     void slotSheetRemoved(Sheet *sheet);
0066         void handleDamages(const QList<Damage*> &damages);
0067 
0068 private:
0069     class Private;
0070     Private * const d;
0071 };
0072 
0073 } // namespace Sheets
0074 } // namespace Calligra
0075 
0076 #endif