File indexing completed on 2024-05-19 03:49:06
0001 /* 0002 File : SpreadsheetModel.h 0003 Project : LabPlot 0004 Description : Model for the access to a Spreadsheet 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2007 Tilman Benkert <thzs@gmx.net> 0007 SPDX-FileCopyrightText: 2009 Knut Franke <knut.franke@gmx.de> 0008 SPDX-FileCopyrightText: 2013-2021 Alexander Semke <alexander.semke@web.de> 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #ifndef SPREADSHEETMODEL_H 0013 #define SPREADSHEETMODEL_H 0014 0015 #include "backend/core/AbstractColumn.h" 0016 #include <QAbstractItemModel> 0017 0018 class Column; 0019 class Spreadsheet; 0020 class AbstractAspect; 0021 0022 class SpreadsheetModel : public QAbstractItemModel { 0023 Q_OBJECT 0024 0025 public: 0026 explicit SpreadsheetModel(Spreadsheet*); 0027 0028 enum class CustomDataRole { 0029 MaskingRole = Qt::UserRole, //!< bool determining whether the cell is masked 0030 FormulaRole = Qt::UserRole + 1, //!< the cells formula 0031 CommentRole = Qt::UserRole + 2, //!< the column comment (for headerData()) 0032 }; 0033 0034 Qt::ItemFlags flags(const QModelIndex&) const override; 0035 QVariant data(const QModelIndex&, int role) const override; 0036 QVariant headerData(int section, Qt::Orientation orientation, int role) const override; 0037 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 0038 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 0039 bool setData(const QModelIndex&, const QVariant& value, int role) override; 0040 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 0041 QModelIndex parent(const QModelIndex& child) const override; 0042 bool hasChildren(const QModelIndex& parent = QModelIndex()) const override; 0043 0044 Column* column(int index); 0045 0046 void activateFormulaMode(bool on); 0047 bool formulaModeActive() const; 0048 0049 void updateHorizontalHeader(bool sendSignal = true); 0050 void suppressSignals(bool); 0051 0052 void setSearchText(const QString&); 0053 QModelIndex index(const QString&) const; 0054 0055 private Q_SLOTS: 0056 void handleAspectsAboutToBeInserted(int first, int last); 0057 void handleAspectsInserted(int first, int last); 0058 void handleAspectsAboutToBeRemoved(int first, int last); 0059 void handleAspectsRemoved(); 0060 void handleAspectCountChanged(); 0061 0062 void handleAspectAboutToBeAdded(const AbstractAspect*, int index, const AbstractAspect*); 0063 void handleAspectAdded(const AbstractAspect* aspect); 0064 void handleAspectAboutToBeRemoved(const AbstractAspect* aspect); 0065 void handleAspectRemoved(const AbstractAspect* parent, const AbstractAspect* before, const AbstractAspect* child); 0066 0067 void handleDescriptionChange(const AbstractAspect*); 0068 void handleModeChange(const AbstractColumn*); 0069 void handleDigitsChange(); 0070 void handlePlotDesignationChange(const AbstractColumn*); 0071 void handleDataChange(const AbstractColumn*); 0072 void handleRowsInserted(int newRowCount); 0073 void handleRowsRemoved(int newRowCount); 0074 void handleRowsAboutToBeInserted(int before, int last); 0075 void handleRowsAboutToBeRemoved(int first, int last); 0076 0077 void handleRowCountChanged(int newRowCount); 0078 0079 protected: 0080 void updateVerticalHeader(); 0081 0082 private: 0083 Spreadsheet* m_spreadsheet; 0084 bool m_formula_mode{false}; 0085 QStringList m_horizontal_header_data; 0086 int m_defaultHeaderHeight; 0087 bool m_suppressSignals{false}; 0088 bool m_spreadsheetColumnCountChanging{false}; 0089 int m_rowCount{0}; 0090 int m_verticalHeaderCount{0}; 0091 int m_columnCount{0}; 0092 QString m_searchText; 0093 0094 QVariant color(const AbstractColumn*, int row, AbstractColumn::Formatting) const; 0095 }; 0096 0097 #endif