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

0001 /* This file is part of the KDE project
0002    Copyright 2007 Stefan Nikolaus <stefan.nikolaus@kdemail.net>
0003     Copyright (C) 2008 Thomas Zander <zander@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef CALLIGRA_SHEETS_BINDING_MODEL
0022 #define CALLIGRA_SHEETS_BINDING_MODEL
0023 
0024 #include "Region.h"
0025 
0026 #include <KoChartModel.h>
0027 
0028 #include <QAbstractTableModel>
0029 
0030 namespace Calligra
0031 {
0032 namespace Sheets
0033 {
0034 class Binding;
0035 
0036 /**
0037  * A model for a cell range acting as data source.
0038  */
0039 class BindingModel : public QAbstractTableModel, public KoChart::ChartModel
0040 {
0041     Q_OBJECT
0042     Q_INTERFACES(KoChart::ChartModel)
0043 public:
0044     explicit BindingModel(Binding* binding, QObject *parent = 0);
0045 
0046     // QAbstractTableModel interface
0047     QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
0048     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0049     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0050     QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
0051 
0052     // KoChart::ChartModel interface
0053     QHash<QString, QVector<QRect> > cellRegion() const override;
0054     bool setCellRegion(const QString& regionName) override;
0055     bool isCellRegionValid(const QString& regionName) const override;
0056 
0057     const Region& region() const;
0058     void setRegion(const Region& region);
0059 
0060     void emitDataChanged(const QRect& range);
0061     void emitChanged(const Region& region);
0062 
0063 Q_SIGNALS:
0064     void changed(const Region& region);
0065 
0066 private:
0067     Region m_region;
0068     Binding* m_binding;
0069 };
0070 
0071 } // namespace Sheets
0072 } // namespace Calligra
0073 
0074 #endif // CALLIGRA_SHEETS_BINDING_MODEL