File indexing completed on 2024-05-19 15:02:17
0001 /*************************************************************************** 0002 File : SpreadsheetCommentsHeaderModel.cpp 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2007 by Tilman Benkert (thzs@gmx.net) 0006 0007 ***************************************************************************/ 0008 0009 /*************************************************************************** 0010 * * 0011 * This program is free software; you can redistribute it and/or modify * 0012 * it under the terms of the GNU General Public License as published by * 0013 * the Free Software Foundation; either version 2 of the License, or * 0014 * (at your option) any later version. * 0015 * * 0016 * This program is distributed in the hope that it will be useful, * 0017 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0019 * GNU General Public License for more details. * 0020 * * 0021 * You should have received a copy of the GNU General Public License * 0022 * along with this program; if not, write to the Free Software * 0023 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0024 * Boston, MA 02110-1301 USA * 0025 * * 0026 ***************************************************************************/ 0027 0028 #include "commonfrontend/spreadsheet/SpreadsheetCommentsHeaderModel.h" 0029 0030 /*! 0031 \class SpreadsheetCommentsHeaderModel 0032 \brief Model class wrapping a SpreadsheetModel to display column comments in a SpreadsheetCommentsHeaderView 0033 0034 \ingroup commonfrontend 0035 */ 0036 0037 SpreadsheetCommentsHeaderModel::SpreadsheetCommentsHeaderModel(SpreadsheetModel* spreadsheet_model, QObject* parent) 0038 : QAbstractTableModel(parent), m_spreadsheet_model(spreadsheet_model) { 0039 0040 connect(m_spreadsheet_model, &SpreadsheetModel::headerDataChanged, 0041 this, &SpreadsheetCommentsHeaderModel::headerDataChanged); 0042 connect(m_spreadsheet_model, &SpreadsheetModel::headerDataChanged, 0043 this, &SpreadsheetCommentsHeaderModel::headerDataChanged); 0044 connect(m_spreadsheet_model, &SpreadsheetModel::columnsAboutToBeInserted, 0045 this, &SpreadsheetCommentsHeaderModel::columnsAboutToBeInserted); 0046 connect(m_spreadsheet_model, &SpreadsheetModel::columnsAboutToBeRemoved, 0047 this, &SpreadsheetCommentsHeaderModel::columnsAboutToBeRemoved); 0048 connect(m_spreadsheet_model, &SpreadsheetModel::columnsInserted, 0049 this, &SpreadsheetCommentsHeaderModel::columnsInserted); 0050 connect(m_spreadsheet_model, &SpreadsheetModel::columnsRemoved, 0051 this, &SpreadsheetCommentsHeaderModel::columnsRemoved); 0052 } 0053 0054 Qt::ItemFlags SpreadsheetCommentsHeaderModel::flags(const QModelIndex& index ) const { 0055 if (index.isValid()) 0056 return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 0057 else 0058 return Qt::ItemIsEnabled; 0059 } 0060 0061 QVariant SpreadsheetCommentsHeaderModel::data(const QModelIndex& index, int role) const { 0062 Q_UNUSED(index); 0063 Q_UNUSED(role); 0064 return QVariant(); 0065 } 0066 0067 QVariant SpreadsheetCommentsHeaderModel::headerData(int section, Qt::Orientation orientation, int role) const { 0068 if (orientation != Qt::Horizontal || role != Qt::DisplayRole || section < 0 || section >= columnCount()) 0069 return QVariant(); 0070 0071 return QVariant(m_spreadsheet_model->headerData(section, Qt::Horizontal, static_cast<int>(SpreadsheetModel::CustomDataRole::CommentRole))); 0072 } 0073 0074 int SpreadsheetCommentsHeaderModel::rowCount(const QModelIndex& parent) const{ 0075 Q_UNUSED(parent) 0076 return m_spreadsheet_model->rowCount(); 0077 } 0078 0079 int SpreadsheetCommentsHeaderModel::columnCount(const QModelIndex& parent) const{ 0080 Q_UNUSED(parent) 0081 return m_spreadsheet_model->columnCount(); 0082 }