71 QVariant
data(
const QModelIndex &index,
int role)
const override {
72 if (index.isValid() &&
73 index.row() < m_data.size() &&
75 role == Qt::EditRole) {
77 if constexpr (std::is_same_v<TYPE, QVariant>) {
78 return m_data[index.row()];
79 }
else if constexpr(std::is_base_of_v<QObject, TYPE>) {
80 QQmlEngine::setObjectOwnership(m_data[index.row()], QQmlEngine::CppOwnership);
82 return QVariant::fromValue(m_data[index.row()]);
84 }
else if constexpr (std::is_same_v<TYPE, QSharedPointer<QObject>> ||
85 std::is_base_of_v<QObject, typename TYPE::element_type>) {
86 QObject* ptr = m_data[index.row()].get();
88 QQmlEngine::setObjectOwnership(ptr, QQmlEngine::CppOwnership);
89 return QVariant::fromValue(ptr);
91 return QVariant::fromValue(m_data[index.row()]);
105 const int diff = newData.size() - m_data.size();
108 beginInsertRows(QModelIndex{}, m_data.size(), m_data.size() + diff - 1);
112 emit dataChanged(index(0, 0),
113 index(m_data.size() - diff - 1, 0));
114 }
else if (diff == 0) {
117 emit dataChanged(index(0, 0),
118 index(m_data.size() - diff - 1, 0));
120 beginRemoveRows(QModelIndex{}, m_data.size() + diff, m_data.size() - 1);
125 emit dataChanged(index(0, 0),
126 index(m_data.size() - 1, 0));