File indexing completed on 2024-05-19 16:07:25
0001 /* This file is part of the KDE project 0002 * Copyright (c) 2010 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef MATRIXDATAMODEL_H 0021 #define MATRIXDATAMODEL_H 0022 0023 #include <QAbstractTableModel> 0024 #include <QVector> 0025 0026 class MatrixDataModel : public QAbstractTableModel 0027 { 0028 public: 0029 /// Creates a new matrix data model 0030 explicit MatrixDataModel(QObject *parent = 0); 0031 0032 /// Sets the matrix data and rows/columns to use 0033 void setMatrix(const QVector<qreal> &matrix, int rows, int cols); 0034 0035 /// Returns the matrix data 0036 QVector<qreal> matrix() const; 0037 0038 // reimplemented 0039 int rowCount(const QModelIndex &/*parent*/) const override; 0040 // reimplemented 0041 int columnCount(const QModelIndex &/*parent*/) const override; 0042 // reimplemented 0043 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0044 // reimplemented 0045 bool setData(const QModelIndex &index, const QVariant &value, int /*role*/) override; 0046 // reimplemented 0047 Qt::ItemFlags flags(const QModelIndex &/*index*/) const override; 0048 0049 private: 0050 QVector<qreal> m_matrix; ///< the matrix data to handle 0051 int m_rows; ///< the number or rows in the matrix 0052 int m_cols; ///< the number of columns in the matrix 0053 }; 0054 0055 #endif // MATRIXDATAMODEL_H