File indexing completed on 2024-05-12 15:27:02
0001 /*************************************************************************** 0002 File : Matrix.h 0003 Project : Matrix 0004 Description : Spreadsheet with a MxN matrix data model 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2008-2009 Tilman Benkert (thzs@gmx.net) 0007 Copyright : (C) 2015-2017 Alexander Semke (alexander.semke@web.de) 0008 Copyright : (C) 2017 Stefan Gerlach (stefan.gerlach@uni.kn) 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 #ifndef MATRIX_H 0031 #define MATRIX_H 0032 0033 #include "backend/datasources/AbstractDataSource.h" 0034 #include "backend/datasources/filters/AbstractFileFilter.h" 0035 #include "backend/lib/macros.h" 0036 0037 class MatrixPrivate; 0038 class MatrixModel; 0039 class MatrixView; 0040 0041 class Matrix : public AbstractDataSource { 0042 Q_OBJECT 0043 Q_ENUMS(HeaderFormat) 0044 0045 public: 0046 enum class HeaderFormat {HeaderRowsColumns, HeaderValues, HeaderRowsColumnsValues}; 0047 0048 explicit Matrix(const QString& name, bool loading = false, 0049 const AbstractColumn::ColumnMode = AbstractColumn::ColumnMode::Numeric); 0050 Matrix(int rows, int cols, const QString& name, 0051 const AbstractColumn::ColumnMode = AbstractColumn::ColumnMode::Numeric); 0052 ~Matrix() override; 0053 0054 QIcon icon() const override; 0055 QMenu* createContextMenu() override; 0056 QWidget* view() const override; 0057 0058 bool exportView() const override; 0059 bool printView() override; 0060 bool printPreview() const override; 0061 0062 void* data() const; 0063 void setData(void*); 0064 0065 BASIC_D_ACCESSOR_DECL(AbstractColumn::ColumnMode, mode, Mode) 0066 BASIC_D_ACCESSOR_DECL(int, rowCount, RowCount) 0067 BASIC_D_ACCESSOR_DECL(int, columnCount, ColumnCount) 0068 BASIC_D_ACCESSOR_DECL(char, numericFormat, NumericFormat) 0069 BASIC_D_ACCESSOR_DECL(int, precision, Precision) 0070 BASIC_D_ACCESSOR_DECL(HeaderFormat, headerFormat, HeaderFormat) 0071 BASIC_D_ACCESSOR_DECL(double, xStart, XStart) 0072 BASIC_D_ACCESSOR_DECL(double, xEnd, XEnd) 0073 BASIC_D_ACCESSOR_DECL(double, yStart, YStart) 0074 BASIC_D_ACCESSOR_DECL(double, yEnd, YEnd) 0075 CLASS_D_ACCESSOR_DECL(QString, formula, Formula) 0076 0077 void setSuppressDataChangedSignal(bool); 0078 void setChanged(); 0079 0080 int rowHeight(int row) const; 0081 void setRowHeight(int row, int height); 0082 int columnWidth(int col) const; 0083 void setColumnWidth(int col, int width); 0084 0085 void setDimensions(int rows, int cols); 0086 void setCoordinates(double x1, double x2, double y1, double y2); 0087 0088 void insertColumns(int before, int count); 0089 void appendColumns(int count); 0090 void removeColumns(int first, int count); 0091 void clearColumn(int); 0092 0093 void insertRows(int before, int count); 0094 void appendRows(int count); 0095 void removeRows(int first, int count); 0096 void clearRow(int); 0097 0098 template <typename T> T cell(int row, int col) const; 0099 template <typename T> QString text(int row, int col); 0100 template <typename T> void setCell(int row, int col, T value); 0101 void clearCell(int row, int col); 0102 0103 template <typename T> QVector<T> columnCells(int col, int first_row, int last_row); 0104 template <typename T> void setColumnCells(int col, int first_row, int last_row, const QVector<T>& values); 0105 template <typename T> QVector<T> rowCells(int row, int first_column, int last_column); 0106 template <typename T> void setRowCells(int row, int first_column, int last_column, const QVector<T>& values); 0107 0108 void copy(Matrix* other); 0109 0110 void save(QXmlStreamWriter*) const override; 0111 bool load(XmlStreamReader*, bool preview) override; 0112 0113 int prepareImport(std::vector<void*>& dataContainer, AbstractFileFilter::ImportMode, 0114 int rows, int cols, QStringList colNameList, QVector<AbstractColumn::ColumnMode>) override; 0115 void finalizeImport(int columnOffset, int startColumn, int endColumn, 0116 const QString& dateTimeFormat, AbstractFileFilter::ImportMode) override; 0117 0118 typedef MatrixPrivate Private; 0119 0120 public slots: 0121 void clear(); 0122 void transpose(); 0123 void mirrorVertically(); 0124 void mirrorHorizontally(); 0125 0126 void addColumns(); 0127 void addRows(); 0128 void duplicate(); 0129 0130 signals: 0131 void requestProjectContextMenu(QMenu*); 0132 void columnsAboutToBeInserted(int before, int count); 0133 void columnsInserted(int first, int count); 0134 void columnsAboutToBeRemoved(int first, int count); 0135 void columnsRemoved(int first, int count); 0136 void rowsAboutToBeInserted(int before, int count); 0137 void rowsInserted(int first, int count); 0138 void rowsAboutToBeRemoved(int first, int count); 0139 void rowsRemoved(int first, int count); 0140 void dataChanged(int top, int left, int bottom, int right); 0141 void coordinatesChanged(); 0142 0143 void rowCountChanged(int); 0144 void columnCountChanged(int); 0145 0146 void xStartChanged(double); 0147 void xEndChanged(double); 0148 void yStartChanged(double); 0149 void yEndChanged(double); 0150 0151 void numericFormatChanged(char); 0152 void precisionChanged(int); 0153 void headerFormatChanged(Matrix::HeaderFormat); 0154 0155 private: 0156 void init(); 0157 0158 MatrixPrivate* const d; 0159 mutable MatrixModel* m_model{nullptr}; 0160 mutable MatrixView* m_view{nullptr}; 0161 0162 friend class MatrixPrivate; 0163 }; 0164 0165 #endif