1 /*************************************************************************** 2 FET 3 ------------------- 4 copyright : (C) by Lalescu Liviu 5 email : Please see https://lalescu.ro/liviu/ for details about contacting Liviu Lalescu (in particular, you can find here the e-mail address) 6 *************************************************************************** 7 sparseitemmodel.h - description 8 ------------------- 9 begin : 2010 10 copyright : (C) 2010 by Liviu Lalescu 11 : https://lalescu.ro/liviu/ 12 *************************************************************************** 13 * * 14 * This program is free software: you can redistribute it and/or modify * 15 * it under the terms of the GNU Affero General Public License as * 16 * published by the Free Software Foundation, either version 3 of the * 17 * License, or (at your option) any later version. * 18 * * 19 ***************************************************************************/ 20 21 #ifndef SPARSEITEMMODEL_H 22 #define SPARSEITEMMODEL_H 23 24 #include <QAbstractItemModel> 25 #include <QHash> 26 #include <QPair> 27 #include <QString> 28 #include <QStringList> 29 30 class SparseItemModel: public QAbstractItemModel{ 31 int n_rows; 32 int n_columns; 33 34 public: 35 36 QHash<QPair<int, int> , QString> items; 37 QStringList horizontalHeaderItems; 38 QStringList verticalHeaderItems; 39 40 SparseItemModel(); 41 42 QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const ; 43 QModelIndex parent ( const QModelIndex & index ) const ; 44 int rowCount ( const QModelIndex & parent = QModelIndex() ) const ; 45 int columnCount ( const QModelIndex & parent = QModelIndex() ) const ; 46 QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const ; 47 QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const ; 48 49 void clear(); 50 void clearDataAndHeaders(); 51 void resize(int _nr, int _nc); 52 void allItemsChanged(); 53 void allHeadersChanged(); 54 }; 55 56 #endif 57