1/* This file is part of the KDE project
2 Copyright 2009 Johannes Simon <johannes.simon@gmail.com>
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 SHEETACCESSMODEL_H
21#define SHEETACCESSMODEL_H
22
23#include <QStandardItemModel>
24
25#include "Sheet.h"
26
27namespace Calligra
28{
29namespace Sheets
30{
31
32class Damage;
33class Map;
34class Sheet;
35
36/**
37 * @brief Class that can be used by any shape embedded in KSpread to access sheet data,
38 * without the need to link against KSpread. It is available through the Doc's data center map,
39 * or KoShapeLoadingContext::dataCenterMap() in the process of loading a shape from ODF.
40 *
41 * Essentially, this model is a list of models to access a sheet's data. It contains a single row,
42 * and has exactly one sheet model per column. In short, a model containing models.
43 *
44 * To allow name-based referencing of a sheet's data (e.g. in an ODF-conform cell region like "Table1.A1:B2")
45 * each column's header contains the name of the sheet returned by KSpread::Sheet::sheetName() .
46 *
47 * To access the QAbstractItemModel instance for a sheet's data, take the following code as example:
48 * @code
49 * QAbstractItemModel *sheetAccessModel = dynamic_cast<QAbstractItemModel*>( dataCenterMap["SheetAccessModel"] );
50 * QModelIndex firstSheetIndex = sheetAccessModel->index( 0, 0 );
51 * QPointer<QAbstractItemModel> firstSheet = sheetAccessModel->data( firstSheetIndex ).value< QPointer<QAbstractItemModel> >();
52 * view->setModel( firstSheet.data() );
53 * @endcode
54 */
55class SheetAccessModel : public QStandardItemModel
56{
57 Q_OBJECT
58
59public:
60 explicit SheetAccessModel(Map *map);
61 virtual ~SheetAccessModel();
62
63public Q_SLOTS:
64 void slotSheetAdded(Sheet *sheet);
65 void slotSheetRemoved(Sheet *sheet);
66 void handleDamages(const QList<Damage*> &damages);
67
68private:
69 class Private;
70 Private * const d;
71};
72
73} // namespace Sheets
74} // namespace Calligra
75
76#endif
77