| 3115 | } |
| 3116 | |
| 3117 | void ShaderViewer::combineStructures(RDTreeWidgetItem *root, int skipPrefixLength) |
| 3118 | { |
| 3119 | RDTreeWidgetItem temp; |
| 3120 | |
| 3121 | // we perform a filter moving from root to temp. At each point we check the node: |
| 3122 | // * if the node has no struct or array prefix, it gets moved |
| 3123 | // * if the node does have a prefix, we sweep finding all matching elements with the same prefix, |
| 3124 | // strip the prefix off them and make a combined node, then recurse to combine anything |
| 3125 | // underneath. We aren't greedy in picking prefixes so this should generate a struct/array tree. |
| 3126 | // * in the event that a node has no matching elements we move it across as if it had no prefix. |
| 3127 | // * we iterate from last to first, because when combining elements that may be spread out in the |
| 3128 | // list of children, we want to combine up to the position of the last item, not the position of |
| 3129 | // the first. |
| 3130 | |
| 3131 | for(int c = root->childCount() - 1; c >= 0;) |
| 3132 | { |
| 3133 | RDTreeWidgetItem *child = root->takeChild(c); |
| 3134 | c--; |
| 3135 | |
| 3136 | QString name = child->text(0); |
| 3137 | |
| 3138 | int dotIndex = name.indexOf(QLatin1Char('.'), skipPrefixLength); |
| 3139 | int arrIndex = name.indexOf(QLatin1Char('['), skipPrefixLength); |
| 3140 | |
| 3141 | // if this node doesn't have any segments, just move it across. |
| 3142 | if(dotIndex < 0 && arrIndex < 0) |
| 3143 | { |
| 3144 | temp.insertChild(0, child); |
| 3145 | continue; |
| 3146 | } |
| 3147 | |
| 3148 | // store the index of the first separator |
| 3149 | int sepIndex = dotIndex; |
| 3150 | bool isLeafArray = (sepIndex == -1); |
| 3151 | if(sepIndex == -1 || (arrIndex > 0 && arrIndex < sepIndex)) |
| 3152 | sepIndex = arrIndex; |
| 3153 | |
| 3154 | // we have a valid node to match against, record the prefix (including separator character) |
| 3155 | QString prefix = name.mid(0, sepIndex + 1); |
| 3156 | |
| 3157 | QVector<RDTreeWidgetItem *> matches = {child}; |
| 3158 | |
| 3159 | // iterate down from the next item |
| 3160 | for(int n = c; n >= 0; n--) |
| 3161 | { |
| 3162 | RDTreeWidgetItem *testNode = root->child(n); |
| 3163 | |
| 3164 | QString testName = testNode->text(0); |
| 3165 | |
| 3166 | QString testprefix = testName.mid(0, sepIndex + 1); |
| 3167 | |
| 3168 | // no match - continue |
| 3169 | if(testprefix != prefix) |
| 3170 | continue; |
| 3171 | |
| 3172 | // match, take this child |
| 3173 | matches.push_back(root->takeChild(n)); |
| 3174 |
nothing calls this directly
no test coverage detected