File indexing completed on 2024-05-12 03:47:48
0001 /* 0002 File : MatrixPrivate.h 0003 Project : LabPlot 0004 Description : Private members of Matrix. 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2008-2009 Tilman Benkert <thzs@gmx.net> 0007 SPDX-FileCopyrightText: 2015 Alexander Semke <alexander.semke@web.de> 0008 SPDX-FileCopyrightText: 2017 Stefan Gerlach <stefan.gerlach@uni.kn> 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #ifndef MATRIXPRIVATE_H 0013 #define MATRIXPRIVATE_H 0014 0015 class MatrixPrivate { 0016 public: 0017 explicit MatrixPrivate(Matrix*, AbstractColumn::ColumnMode); 0018 ~MatrixPrivate(); 0019 0020 void insertColumns(int before, int count); 0021 void removeColumns(int first, int count); 0022 void insertRows(int before, int count); 0023 void removeRows(int first, int count); 0024 0025 QString name() const { 0026 return q->name(); 0027 } 0028 0029 // get value of cell at row/col (must be defined in header) 0030 template<typename T> 0031 T cell(int row, int col) const { 0032 Q_ASSERT(row >= 0 && row < rowCount); 0033 Q_ASSERT(col >= 0 && col < columnCount); 0034 0035 return (static_cast<QVector<QVector<T>>*>(data))->at(col).at(row); 0036 } 0037 0038 // Set value of cell at row/col (must be defined in header) 0039 template<typename T> 0040 void setCell(int row, int col, T value) { 0041 Q_ASSERT(row >= 0 && row < rowCount); 0042 Q_ASSERT(col >= 0 && col < columnCount); 0043 0044 static_cast<QVector<QVector<T>>*>(data)->operator[](col)[row] = value; 0045 0046 if (!suppressDataChange) 0047 Q_EMIT q->dataChanged(row, col, row, col); 0048 } 0049 // get column cells (must be defined in header) 0050 template<typename T> 0051 QVector<T> columnCells(int col, int first_row, int last_row) const { 0052 Q_ASSERT(first_row >= 0 && first_row < rowCount); 0053 Q_ASSERT(last_row >= 0 && last_row < rowCount); 0054 0055 if (first_row == 0 && last_row == rowCount - 1) 0056 return (static_cast<QVector<QVector<T>>*>(data))->at(col); 0057 0058 QVector<T> result; 0059 for (int i = first_row; i <= last_row; i++) 0060 result.append(static_cast<QVector<QVector<T>>*>(data)->at(col).at(i)); 0061 return result; 0062 } 0063 // set column cells (must be defined in header) 0064 template<typename T> 0065 void setColumnCells(int col, int first_row, int last_row, const QVector<T>& values) { 0066 Q_ASSERT(first_row >= 0 && first_row < rowCount); 0067 Q_ASSERT(last_row >= 0 && last_row < rowCount); 0068 Q_ASSERT(values.count() > last_row - first_row); 0069 0070 if (first_row == 0 && last_row == rowCount - 1) { 0071 static_cast<QVector<QVector<T>>*>(data)->operator[](col) = values; 0072 static_cast<QVector<QVector<T>>*>(data)->operator[](col).resize(rowCount); // values may be larger 0073 if (!suppressDataChange) 0074 Q_EMIT q->dataChanged(first_row, col, last_row, col); 0075 return; 0076 } 0077 0078 for (int i = first_row; i <= last_row; i++) 0079 static_cast<QVector<QVector<T>>*>(data)->operator[](col)[i] = values.at(i - first_row); 0080 0081 if (!suppressDataChange) 0082 Q_EMIT q->dataChanged(first_row, col, last_row, col); 0083 } 0084 // get row cells (must be defined in header) 0085 template<typename T> 0086 QVector<T> rowCells(int row, int first_column, int last_column) const { 0087 Q_ASSERT(first_column >= 0 && first_column < columnCount); 0088 Q_ASSERT(last_column >= 0 && last_column < columnCount); 0089 0090 QVector<T> result; 0091 for (int i = first_column; i <= last_column; i++) 0092 result.append(static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row]); 0093 return result; 0094 } 0095 // set row cells (must be defined in header) 0096 template<typename T> 0097 void setRowCells(int row, int first_column, int last_column, const QVector<T>& values) { 0098 Q_ASSERT(first_column >= 0 && first_column < columnCount); 0099 Q_ASSERT(last_column >= 0 && last_column < columnCount); 0100 Q_ASSERT(values.count() > last_column - first_column); 0101 0102 for (int i = first_column; i <= last_column; i++) 0103 static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row] = values.at(i - first_column); 0104 if (!suppressDataChange) 0105 Q_EMIT q->dataChanged(row, first_column, row, last_column); 0106 } 0107 0108 void clearColumn(int col); 0109 0110 void setRowHeight(int row, int height) { 0111 rowHeights[row] = height; 0112 } 0113 void setColumnWidth(int col, int width) { 0114 columnWidths[col] = width; 0115 } 0116 int rowHeight(int row) const { 0117 return rowHeights.at(row); 0118 } 0119 int columnWidth(int col) const { 0120 return columnWidths.at(col); 0121 } 0122 0123 void updateViewHeader(); 0124 void emitDataChanged(int top, int left, int bottom, int right) { 0125 Q_EMIT q->dataChanged(top, left, bottom, right); 0126 } 0127 0128 Matrix* q; 0129 void* data; 0130 AbstractColumn::ColumnMode mode; // mode (data type) of values 0131 0132 int rowCount; 0133 int columnCount; 0134 QVector<int> rowHeights; //!< Row widths 0135 QVector<int> columnWidths; //!< Columns widths 0136 Matrix::HeaderFormat headerFormat{Matrix::HeaderFormat::HeaderRowsColumns}; 0137 0138 char numericFormat{'f'}; //!< Format code for displaying numbers 0139 int precision{3}; //!< Number of significant digits 0140 double xStart{0.0}, xEnd{1.0}; 0141 double yStart{0.0}, yEnd{1.0}; 0142 QString formula; //!< formula used to calculate the cells 0143 bool suppressDataChange; 0144 }; 0145 0146 #endif