File indexing completed on 2024-12-15 03:45:01
0001 /* 0002 SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: MIT 0005 */ 0006 0007 #include "extrarowsproxymodel.h" 0008 0009 using namespace KUserFeedback::Console; 0010 0011 ExtraRowsProxyModel::ExtraRowsProxyModel(QObject* parent) : 0012 QIdentityProxyModel(parent) 0013 { 0014 } 0015 0016 ExtraRowsProxyModel::~ExtraRowsProxyModel() = default; 0017 0018 int ExtraRowsProxyModel::rowCount(const QModelIndex& parent) const 0019 { 0020 if (!sourceModel()) 0021 return 0; 0022 if (parent.isValid()) 0023 return sourceModel()->rowCount(mapToSource(parent)); 0024 return sourceModel()->rowCount() + m_extraRowCount; 0025 } 0026 0027 QVariant ExtraRowsProxyModel::data(const QModelIndex& index, int role) const 0028 { 0029 if (!sourceModel()) 0030 return {}; 0031 if (!index.isValid() || index.parent().isValid() || index.row() < sourceModel()->rowCount()) 0032 return QIdentityProxyModel::data(index, role); 0033 return extraData(index.row() - sourceModel()->rowCount(), index.column(), role); 0034 } 0035 0036 QModelIndex ExtraRowsProxyModel::index(int row, int column, const QModelIndex& parent) const 0037 { 0038 if (!sourceModel()) 0039 return {}; 0040 if (parent.isValid() || row < sourceModel()->rowCount()) 0041 return QIdentityProxyModel::index(row, column, parent); 0042 if (row >= rowCount()) 0043 return {}; 0044 return createIndex(row, column); 0045 } 0046 0047 QModelIndex ExtraRowsProxyModel::parent(const QModelIndex& child) const 0048 { 0049 if (!sourceModel()) 0050 return {}; 0051 if (child.internalId() == 0 && child.row() >= sourceModel()->rowCount()) 0052 return {}; 0053 return QIdentityProxyModel::parent(child); 0054 } 0055 0056 0057 QVariant ExtraRowsProxyModel::extraData(int row, int column, int role) const 0058 { 0059 // TODO split into separate model! 0060 Q_UNUSED(row); 0061 if (role == Qt::DisplayRole) 0062 return headerData(column, Qt::Horizontal, Qt::DisplayRole); 0063 return {}; 0064 } 0065 0066 #include "moc_extrarowsproxymodel.cpp"