File indexing completed on 2024-05-12 03:48:26
0001 /* 0002 File : SpreadsheetCommentsHeaderModel.cpp 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 SPDX-FileCopyrightText: 2007 Tilman Benkert <thzs@gmx.net> 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "commonfrontend/spreadsheet/SpreadsheetCommentsHeaderModel.h" 0010 0011 /*! 0012 \class SpreadsheetCommentsHeaderModel 0013 \brief Model class wrapping a SpreadsheetModel to display column comments in a SpreadsheetCommentsHeaderView 0014 0015 \ingroup commonfrontend 0016 */ 0017 0018 SpreadsheetCommentsHeaderModel::SpreadsheetCommentsHeaderModel(SpreadsheetModel* spreadsheet_model, QObject* parent) 0019 : QAbstractTableModel(parent) 0020 , m_spreadsheet_model(spreadsheet_model) { 0021 connect(m_spreadsheet_model, &SpreadsheetModel::headerDataChanged, this, &SpreadsheetCommentsHeaderModel::headerDataChanged); 0022 connect(m_spreadsheet_model, &SpreadsheetModel::columnsAboutToBeInserted, this, &SpreadsheetCommentsHeaderModel::columnsAboutToBeInserted); 0023 connect(m_spreadsheet_model, &SpreadsheetModel::columnsAboutToBeRemoved, this, &SpreadsheetCommentsHeaderModel::columnsAboutToBeRemoved); 0024 connect(m_spreadsheet_model, &SpreadsheetModel::columnsInserted, this, &SpreadsheetCommentsHeaderModel::columnsInserted); 0025 connect(m_spreadsheet_model, &SpreadsheetModel::columnsRemoved, this, &SpreadsheetCommentsHeaderModel::columnsRemoved); 0026 } 0027 0028 Qt::ItemFlags SpreadsheetCommentsHeaderModel::flags(const QModelIndex& index) const { 0029 if (index.isValid()) 0030 return Qt::ItemIsEnabled | Qt::ItemIsSelectable; 0031 else 0032 return Qt::ItemIsEnabled; 0033 } 0034 0035 QVariant SpreadsheetCommentsHeaderModel::data(const QModelIndex& /*index*/, int /*role*/) const { 0036 return {}; 0037 } 0038 0039 QVariant SpreadsheetCommentsHeaderModel::headerData(int section, Qt::Orientation orientation, int role) const { 0040 if (orientation != Qt::Horizontal || role != Qt::DisplayRole || section < 0 || section >= columnCount()) 0041 return {}; 0042 0043 return {m_spreadsheet_model->headerData(section, Qt::Horizontal, static_cast<int>(SpreadsheetModel::CustomDataRole::CommentRole))}; 0044 } 0045 0046 int SpreadsheetCommentsHeaderModel::rowCount(const QModelIndex& /*parent*/) const { 0047 return m_spreadsheet_model->rowCount(); 0048 } 0049 0050 int SpreadsheetCommentsHeaderModel::columnCount(const QModelIndex& /*parent*/) const { 0051 return m_spreadsheet_model->columnCount(); 0052 }