| 964 | } |
| 965 | |
| 966 | QVariant ProjectModel::data( const QModelIndex& index, int role ) const |
| 967 | { |
| 968 | static const QSet<int> allowedRoles = { |
| 969 | Qt::DisplayRole, |
| 970 | Qt::ToolTipRole, |
| 971 | Qt::DecorationRole, |
| 972 | ProjectItemRole, |
| 973 | ProjectRole, |
| 974 | UrlRole |
| 975 | }; |
| 976 | if( allowedRoles.contains(role) && index.isValid() ) { |
| 977 | ProjectBaseItem* item = itemFromIndex( index ); |
| 978 | if( item ) { |
| 979 | switch(role) { |
| 980 | case Qt::DecorationRole: |
| 981 | return QIcon::fromTheme(item->iconName()); |
| 982 | case Qt::ToolTipRole: |
| 983 | return item->path().pathOrUrl(); |
| 984 | case Qt::DisplayRole: |
| 985 | return item->text(); |
| 986 | case ProjectItemRole: |
| 987 | return QVariant::fromValue<ProjectBaseItem*>(item); |
| 988 | case UrlRole: |
| 989 | return item->path().toUrl(); |
| 990 | case ProjectRole: |
| 991 | return QVariant::fromValue<QObject*>(item->project()); |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | return QVariant(); |
| 996 | } |
| 997 | |
| 998 | ProjectModel::ProjectModel( QObject *parent ) |
| 999 | : QAbstractItemModel(parent) |