File indexing completed on 2024-05-12 15:27:03
0001 /*************************************************************************** 0002 File : MatrixPrivate.h 0003 Project : LabPlot 0004 Description : Private members of Matrix. 0005 -------------------------------------------------------------------- 0006 Copyright : (C) 2008-2009 Tilman Benkert (thzs@gmx.net) 0007 Copyright : (C) 2015 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 0031 #ifndef MATRIXPRIVATE_H 0032 #define MATRIXPRIVATE_H 0033 0034 template <class T> class QVector; 0035 0036 class MatrixPrivate { 0037 public: 0038 explicit MatrixPrivate(Matrix*, AbstractColumn::ColumnMode); 0039 ~MatrixPrivate(); 0040 0041 void insertColumns(int before, int count); 0042 void removeColumns(int first, int count); 0043 void insertRows(int before, int count); 0044 void removeRows(int first, int count); 0045 0046 QString name() const { return q->name(); } 0047 0048 // get value of cell at row/col (must be defined in header) 0049 template <typename T> 0050 T cell(int row, int col) const { 0051 Q_ASSERT(row >= 0 && row < rowCount); 0052 Q_ASSERT(col >= 0 && col < columnCount); 0053 0054 return (static_cast<QVector<QVector<T>>*>(data))->at(col).at(row); 0055 } 0056 0057 // Set value of cell at row/col (must be defined in header) 0058 template <typename T> 0059 void setCell(int row, int col, T value) { 0060 Q_ASSERT(row >= 0 && row < rowCount); 0061 Q_ASSERT(col >= 0 && col < columnCount); 0062 0063 static_cast<QVector<QVector<T>>*>(data)->operator[](col)[row] = value; 0064 0065 if (!suppressDataChange) 0066 emit q->dataChanged(row, col, row, col); 0067 } 0068 // get column cells (must be defined in header) 0069 template <typename T> 0070 QVector<T> columnCells(int col, int first_row, int last_row) { 0071 Q_ASSERT(first_row >= 0 && first_row < rowCount); 0072 Q_ASSERT(last_row >= 0 && last_row < rowCount); 0073 0074 if (first_row == 0 && last_row == rowCount-1) 0075 return (static_cast<QVector<QVector<T>>*>(data))->at(col); 0076 0077 QVector<T> result; 0078 for (int i = first_row; i <= last_row; i++) 0079 result.append(static_cast<QVector<QVector<T>>*>(data)->at(col).at(i)); 0080 return result; 0081 } 0082 // set column cells (must be defined in header) 0083 template <typename T> 0084 void setColumnCells(int col, int first_row, int last_row, const QVector<T>& values) { 0085 Q_ASSERT(first_row >= 0 && first_row < rowCount); 0086 Q_ASSERT(last_row >= 0 && last_row < rowCount); 0087 Q_ASSERT(values.count() > last_row - first_row); 0088 0089 if (first_row == 0 && last_row == rowCount-1) { 0090 static_cast<QVector<QVector<T>>*>(data)->operator[](col) = values; 0091 static_cast<QVector<QVector<T>>*>(data)->operator[](col).resize(rowCount); // values may be larger 0092 if (!suppressDataChange) 0093 emit q->dataChanged(first_row, col, last_row, col); 0094 return; 0095 } 0096 0097 for (int i = first_row; i <= last_row; i++) 0098 static_cast<QVector<QVector<T>>*>(data)->operator[](col)[i] = values.at(i-first_row); 0099 0100 if (!suppressDataChange) 0101 emit q->dataChanged(first_row, col, last_row, col); 0102 } 0103 // get row cells (must be defined in header) 0104 template <typename T> 0105 QVector<T> rowCells(int row, int first_column, int last_column) { 0106 Q_ASSERT(first_column >= 0 && first_column < columnCount); 0107 Q_ASSERT(last_column >= 0 && last_column < columnCount); 0108 0109 QVector<T> result; 0110 for (int i = first_column; i <= last_column; i++) 0111 result.append(static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row]); 0112 return result; 0113 } 0114 // set row cells (must be defined in header) 0115 template <typename T> 0116 void setRowCells(int row, int first_column, int last_column, const QVector<T>& values) { 0117 Q_ASSERT(first_column >= 0 && first_column < columnCount); 0118 Q_ASSERT(last_column >= 0 && last_column < columnCount); 0119 Q_ASSERT(values.count() > last_column - first_column); 0120 0121 for (int i = first_column; i <= last_column; i++) 0122 static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row] = values.at(i-first_column); 0123 if (!suppressDataChange) 0124 emit q->dataChanged(row, first_column, row, last_column); 0125 } 0126 0127 void clearColumn(int col); 0128 0129 void setRowHeight(int row, int height) { rowHeights[row] = height; } 0130 void setColumnWidth(int col, int width) { columnWidths[col] = width; } 0131 int rowHeight(int row) const { return rowHeights.at(row); } 0132 int columnWidth(int col) const { return columnWidths.at(col); } 0133 0134 void updateViewHeader(); 0135 void emitDataChanged(int top, int left, int bottom, int right) { emit q->dataChanged(top, left, bottom, right); } 0136 0137 Matrix* q; 0138 void* data; 0139 AbstractColumn::ColumnMode mode; // mode (data type) of values 0140 0141 int rowCount; 0142 int columnCount; 0143 QVector<int> rowHeights; //!< Row widths 0144 QVector<int> columnWidths; //!< Columns widths 0145 Matrix::HeaderFormat headerFormat; 0146 0147 char numericFormat; //!< Format code for displaying numbers 0148 int precision; //!< Number of significant digits 0149 double xStart, xEnd; 0150 double yStart, yEnd; 0151 QString formula; //!<formula used to calculate the cells 0152 bool suppressDataChange; 0153 }; 0154 0155 #endif