File indexing completed on 2024-04-21 16:12:19
0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0002 // SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0003 0004 #include "qobjectlistmodel.h" 0005 0006 QVariant QObjectListModel::data(const QModelIndex &index, int intRole) const 0007 { 0008 if (!index.isValid()) { 0009 return {}; 0010 } 0011 0012 switch (static_cast<Role>(intRole)) { 0013 case Role::Object: 0014 return QVariant::fromValue(object(index)); 0015 case Role::UserRole: 0016 return {}; 0017 } 0018 0019 return {}; 0020 } 0021 0022 QHash<int, QByteArray> QObjectListModel::roleNames() const 0023 { 0024 static QHash<int, QByteArray> roles; 0025 if (!roles.isEmpty()) { 0026 return roles; 0027 } 0028 0029 roles = QAbstractListModel::roleNames(); 0030 const QMetaEnum roleEnum = QMetaEnum::fromType<Role>(); 0031 for (int i = 0; i < roleEnum.keyCount(); ++i) { 0032 const int value = roleEnum.value(i); 0033 Q_ASSERT(value != -1); 0034 roles[value] = QByteArray("ROLE_") + roleEnum.valueToKey(value); 0035 } 0036 return roles; 0037 }