labplot  2.8.2
About: LabPlot is an application for plotting and analysis of 2D and 3D functions and data. It is a complete rewrite of LabPlot1 and lacks in the first release a lot of features available in the predecessor. On the other hand, the GUI and the usability is more superior.
  Fossies Dox: labplot-2.8.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

MatrixPrivate.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : MatrixPrivate.h
3  Project : LabPlot
4  Description : Private members of Matrix.
5  --------------------------------------------------------------------
6  Copyright : (C) 2008-2009 Tilman Benkert (thzs@gmx.net)
7  Copyright : (C) 2015 Alexander Semke (alexander.semke@web.de)
8  Copyright : (C) 2017 Stefan Gerlach (stefan.gerlach@uni.kn)
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the Free Software *
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27  * Boston, MA 02110-1301 USA *
28  * *
29  ***************************************************************************/
30 
31 #ifndef MATRIXPRIVATE_H
32 #define MATRIXPRIVATE_H
33 
34 template <class T> class QVector;
35 
37 public:
40 
41  void insertColumns(int before, int count);
42  void removeColumns(int first, int count);
43  void insertRows(int before, int count);
44  void removeRows(int first, int count);
45 
46  QString name() const { return q->name(); }
47 
48  // get value of cell at row/col (must be defined in header)
49  template <typename T>
50  T cell(int row, int col) const {
51  Q_ASSERT(row >= 0 && row < rowCount);
52  Q_ASSERT(col >= 0 && col < columnCount);
53 
54  return (static_cast<QVector<QVector<T>>*>(data))->at(col).at(row);
55  }
56 
57  // Set value of cell at row/col (must be defined in header)
58  template <typename T>
59  void setCell(int row, int col, T value) {
60  Q_ASSERT(row >= 0 && row < rowCount);
61  Q_ASSERT(col >= 0 && col < columnCount);
62 
63  static_cast<QVector<QVector<T>>*>(data)->operator[](col)[row] = value;
64 
65  if (!suppressDataChange)
66  emit q->dataChanged(row, col, row, col);
67  }
68  // get column cells (must be defined in header)
69  template <typename T>
70  QVector<T> columnCells(int col, int first_row, int last_row) {
71  Q_ASSERT(first_row >= 0 && first_row < rowCount);
72  Q_ASSERT(last_row >= 0 && last_row < rowCount);
73 
74  if (first_row == 0 && last_row == rowCount-1)
75  return (static_cast<QVector<QVector<T>>*>(data))->at(col);
76 
77  QVector<T> result;
78  for (int i = first_row; i <= last_row; i++)
79  result.append(static_cast<QVector<QVector<T>>*>(data)->at(col).at(i));
80  return result;
81  }
82  // set column cells (must be defined in header)
83  template <typename T>
84  void setColumnCells(int col, int first_row, int last_row, const QVector<T>& values) {
85  Q_ASSERT(first_row >= 0 && first_row < rowCount);
86  Q_ASSERT(last_row >= 0 && last_row < rowCount);
87  Q_ASSERT(values.count() > last_row - first_row);
88 
89  if (first_row == 0 && last_row == rowCount-1) {
90  static_cast<QVector<QVector<T>>*>(data)->operator[](col) = values;
91  static_cast<QVector<QVector<T>>*>(data)->operator[](col).resize(rowCount); // values may be larger
92  if (!suppressDataChange)
93  emit q->dataChanged(first_row, col, last_row, col);
94  return;
95  }
96 
97  for (int i = first_row; i <= last_row; i++)
98  static_cast<QVector<QVector<T>>*>(data)->operator[](col)[i] = values.at(i-first_row);
99 
100  if (!suppressDataChange)
101  emit q->dataChanged(first_row, col, last_row, col);
102  }
103  // get row cells (must be defined in header)
104  template <typename T>
105  QVector<T> rowCells(int row, int first_column, int last_column) {
106  Q_ASSERT(first_column >= 0 && first_column < columnCount);
107  Q_ASSERT(last_column >= 0 && last_column < columnCount);
108 
109  QVector<T> result;
110  for (int i = first_column; i <= last_column; i++)
111  result.append(static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row]);
112  return result;
113  }
114  // set row cells (must be defined in header)
115  template <typename T>
116  void setRowCells(int row, int first_column, int last_column, const QVector<T>& values) {
117  Q_ASSERT(first_column >= 0 && first_column < columnCount);
118  Q_ASSERT(last_column >= 0 && last_column < columnCount);
119  Q_ASSERT(values.count() > last_column - first_column);
120 
121  for (int i = first_column; i <= last_column; i++)
122  static_cast<QVector<QVector<T>>*>(data)->operator[](i)[row] = values.at(i-first_column);
123  if (!suppressDataChange)
124  emit q->dataChanged(row, first_column, row, last_column);
125  }
126 
127  void clearColumn(int col);
128 
129  void setRowHeight(int row, int height) { rowHeights[row] = height; }
130  void setColumnWidth(int col, int width) { columnWidths[col] = width; }
131  int rowHeight(int row) const { return rowHeights.at(row); }
132  int columnWidth(int col) const { return columnWidths.at(col); }
133 
134  void updateViewHeader();
135  void emitDataChanged(int top, int left, int bottom, int right) { emit q->dataChanged(top, left, bottom, right); }
136 
138  void* data;
139  AbstractColumn::ColumnMode mode; // mode (data type) of values
140 
141  int rowCount;
143  QVector<int> rowHeights; //!< Row widths
144  QVector<int> columnWidths; //!< Columns widths
146 
147  char numericFormat; //!< Format code for displaying numbers
148  int precision; //!< Number of significant digits
149  double xStart, xEnd;
150  double yStart, yEnd;
151  QString formula; //!<formula used to calculate the cells
153 };
154 
155 #endif
QString name() const
void removeRows(int first, int count)
Definition: Matrix.cpp:965
void clearColumn(int col)
Fill column with zeroes.
Definition: Matrix.cpp:1003
Matrix::HeaderFormat headerFormat
void insertColumns(int before, int count)
Definition: Matrix.cpp:840
void removeColumns(int first, int count)
Definition: Matrix.cpp:887
QVector< T > columnCells(int col, int first_row, int last_row)
Definition: MatrixPrivate.h:70
void setCell(int row, int col, T value)
Definition: MatrixPrivate.h:59
void setRowCells(int row, int first_column, int last_column, const QVector< T > &values)
T cell(int row, int col) const
Definition: MatrixPrivate.h:50
int precision
Number of significant digits.
QVector< T > rowCells(int row, int first_column, int last_column)
int rowHeight(int row) const
char numericFormat
Format code for displaying numbers.
QString formula
formula used to calculate the cells
QVector< int > columnWidths
Columns widths.
void setColumnWidth(int col, int width)
void setRowHeight(int row, int height)
int columnWidth(int col) const
void updateViewHeader()
Definition: Matrix.cpp:833
bool suppressDataChange
QVector< int > rowHeights
Row widths.
void insertRows(int before, int count)
Definition: Matrix.cpp:921
AbstractColumn::ColumnMode mode
void setColumnCells(int col, int first_row, int last_row, const QVector< T > &values)
Definition: MatrixPrivate.h:84
void emitDataChanged(int top, int left, int bottom, int right)
QString name() const
Definition: MatrixPrivate.h:46
MatrixPrivate(Matrix *, AbstractColumn::ColumnMode)
Definition: Matrix.cpp:785
Definition: Matrix.h:41
HeaderFormat
Definition: Matrix.h:46
void dataChanged(int top, int left, int bottom, int right)