| 3717 | } |
| 3718 | |
| 3719 | QModelIndex StructuredDataItemModel::index(int row, int column, const QModelIndex &parent) const |
| 3720 | { |
| 3721 | if(row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent)) |
| 3722 | return QModelIndex(); |
| 3723 | |
| 3724 | SDObject *par = NULL; |
| 3725 | |
| 3726 | if(parent.isValid()) |
| 3727 | { |
| 3728 | Index decodedParent = decodeIndex(parent); |
| 3729 | |
| 3730 | // the children of page nodes are real nodes. We cache the array member's index here too for |
| 3731 | // parent() lookups |
| 3732 | if(decodedParent.tag == PageNode) |
| 3733 | { |
| 3734 | int idx = decodedParent.indexInArray + row; |
| 3735 | |
| 3736 | m_ArrayMembers[decodedParent.obj->GetChild(idx)] = idx; |
| 3737 | |
| 3738 | return createIndex(row, column, encodeIndex({ArrayMember, decodedParent.obj, idx})); |
| 3739 | } |
| 3740 | else if(decodedParent.tag == ArrayMember) |
| 3741 | { |
| 3742 | par = decodedParent.obj->GetChild(decodedParent.indexInArray); |
| 3743 | } |
| 3744 | else |
| 3745 | { |
| 3746 | par = decodedParent.obj; |
| 3747 | } |
| 3748 | |
| 3749 | // if this parent node is a large array, the children are page nodes, otherwise the child is a |
| 3750 | // direct node |
| 3751 | if(isLargeArray(par)) |
| 3752 | { |
| 3753 | return createIndex(row, column, encodeIndex({PageNode, par, row * ArrayPageSize})); |
| 3754 | } |
| 3755 | else |
| 3756 | { |
| 3757 | if(par->type.flags & SDTypeFlags::HiddenChildren) |
| 3758 | { |
| 3759 | // if this node has hidden children, get the index relative to only visible children |
| 3760 | int idx = 0; |
| 3761 | for(size_t i = 0; i < par->NumChildren(); i++) |
| 3762 | { |
| 3763 | SDObject *ch = par->GetChild(i); |
| 3764 | |
| 3765 | if(ch->type.flags & SDTypeFlags::Hidden) |
| 3766 | continue; |
| 3767 | |
| 3768 | if(idx == row) |
| 3769 | return createIndex(row, column, encodeIndex({Direct, ch, 0})); |
| 3770 | |
| 3771 | idx++; |
| 3772 | } |
| 3773 | } |
| 3774 | |
| 3775 | return createIndex(row, column, encodeIndex({Direct, par->GetChild(row), 0})); |
| 3776 | } |
no test coverage detected