#include "MyProxyModel.h" #include "MyListModel.h" MyProxyModel::MyProxyModel(QObject *parent) : QIdentityProxyModel(parent) { } QVariant MyProxyModel::data(const QModelIndex &index, int role) const { if (!checkIndex(index, CheckIndexOptions( CheckIndexOption::IndexIsValid | CheckIndexOption::ParentIsInvalid))) { return QVariant(); } const int row(index.row()); if (row >= rowCount(index.parent())) return QVariant(); const int column(index.column()); if (column >= 1) return QVariant(); switch(role) { case Role::ID: return mapToSource(index).data(MyListModel::Role::ID); case Role::Name: return mapToSource(index).data(MyListModel::Role::Name); case Role::Icon: return mapToSource(index).data(MyListModel::Role::Icon); } return QVariant(); }