File indexing completed on 2024-05-12 15:27:12

0001 /***************************************************************************
0002     File                 : SpreadsheetModel.h
0003     Project              : LabPlot
0004     Description          : Model for the access to a Spreadsheet
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2007 Tilman Benkert (thzs@gmx.net)
0007     Copyright            : (C) 2009 Knut Franke (knut.franke@gmx.de)
0008     Copyright            : (C) 2013-2016 Alexander Semke (alexander.semke@web.de)
0009 
0010  ***************************************************************************/
0011 
0012 /***************************************************************************
0013  *                                                                         *
0014  *  This program is free software; you can redistribute it and/or modify   *
0015  *  it under the terms of the GNU General Public License as published by   *
0016  *  the Free Software Foundation; either version 2 of the License, or      *
0017  *  (at your option) any later version.                                    *
0018  *                                                                         *
0019  *  This program is distributed in the hope that it will be useful,        *
0020  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0021  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0022  *  GNU General Public License for more details.                           *
0023  *                                                                         *
0024  *   You should have received a copy of the GNU General Public License     *
0025  *   along with this program; if not, write to the Free Software           *
0026  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0027  *   Boston, MA  02110-1301  USA                                           *
0028  *                                                                         *
0029  ***************************************************************************/
0030 
0031 #ifndef SPREADSHEETMODEL_H
0032 #define SPREADSHEETMODEL_H
0033 
0034 #include <QAbstractItemModel>
0035 
0036 class QStringList;
0037 class Column;
0038 class Spreadsheet;
0039 class AbstractAspect;
0040 class AbstractColumn;
0041 
0042 class SpreadsheetModel : public QAbstractItemModel {
0043     Q_OBJECT
0044 
0045 public:
0046     explicit SpreadsheetModel(Spreadsheet*);
0047 
0048     enum class CustomDataRole {
0049         MaskingRole = Qt::UserRole, //!< bool determining whether the cell is masked
0050         FormulaRole = Qt::UserRole+1, //!< the cells formula
0051         CommentRole = Qt::UserRole+2, //!< the column comment (for headerData())
0052     };
0053 
0054     Qt::ItemFlags flags( const QModelIndex & index ) const override;
0055     QVariant data(const QModelIndex& index, int role) const override;
0056     QVariant headerData(int section, Qt::Orientation orientation,int role) const override;
0057     int rowCount(const QModelIndex& parent = QModelIndex()) const override;
0058     int columnCount(const QModelIndex& parent = QModelIndex()) const override;
0059     bool setData(const QModelIndex& index, const QVariant& value, int role) override;
0060     QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
0061     QModelIndex parent(const QModelIndex& child) const override;
0062     bool hasChildren (const QModelIndex& parent = QModelIndex() ) const override;
0063 
0064     Column* column(int index);
0065 
0066     void activateFormulaMode(bool on);
0067     bool formulaModeActive() const;
0068 
0069     void updateHorizontalHeader();
0070     void suppressSignals(bool);
0071 
0072 private slots:
0073     void handleAspectAdded(const AbstractAspect*);
0074     void handleAspectAboutToBeRemoved(const AbstractAspect*);
0075     void handleAspectRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child);
0076 
0077     void handleDescriptionChange(const AbstractAspect*);
0078     void handleModeChange(const AbstractColumn*);
0079     void handleDigitsChange();
0080     void handlePlotDesignationChange(const AbstractColumn*);
0081     void handleDataChange(const AbstractColumn*);
0082     void handleRowsInserted(const AbstractColumn* col, int before, int count);
0083     void handleRowsRemoved(const AbstractColumn* col, int first, int count);
0084 
0085 protected:
0086     void updateVerticalHeader();
0087 
0088 private:
0089     Spreadsheet* m_spreadsheet;
0090     bool m_formula_mode{false};
0091     QVector<int> m_vertical_header_data;
0092     QStringList m_horizontal_header_data;
0093     int m_defaultHeaderHeight;
0094     bool m_suppressSignals{false};
0095     int m_rowCount{0};
0096     int m_columnCount{0};
0097 };
0098 
0099 #endif