| 136 | |
| 137 | |
| 138 | int ProjectBuildSetModel::findInsertionPlace( const QStringList& itemPath ) |
| 139 | { |
| 140 | /* |
| 141 | * The ordering cache list is a superset of the build set, and must be ordered in the same way. |
| 142 | * Example: |
| 143 | * (items) A - B ----- D --------- G |
| 144 | * (orderingCache) A - B - C - D - E - F - G |
| 145 | * |
| 146 | * We scan orderingCache until we find the required item (absent in items: say, F). |
| 147 | * In process of scanning we synchronize position in orderingCache with position in items; |
| 148 | * so, when we reach F, we have D as last synchronization point and hence return it |
| 149 | * as the insertion place (actually, we return the next item's index - here, index of G). |
| 150 | * |
| 151 | * If an item cannot be found in the ordering list, we append it to the list. |
| 152 | */ |
| 153 | |
| 154 | Q_D(ProjectBuildSetModel); |
| 155 | |
| 156 | int insertionIndex = 0; |
| 157 | bool found = false; |
| 158 | // Points to the item which is next to last synchronization point. |
| 159 | QList<BuildItem>::iterator nextItemIterator = d->items.begin(); |
| 160 | |
| 161 | for (auto& orderedItemPath : std::as_const(d->orderingCache)) { |
| 162 | if (itemPath == orderedItemPath) { |
| 163 | found = true; |
| 164 | break; |
| 165 | } |
| 166 | if (nextItemIterator != d->items.end() && |
| 167 | nextItemIterator->itemPath() == orderedItemPath) { |
| 168 | ++insertionIndex; |
| 169 | ++nextItemIterator; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if( !found ) { |
| 174 | d->orderingCache.append(itemPath); |
| 175 | } |
| 176 | Q_ASSERT( insertionIndex >= 0 && insertionIndex <= d->items.size() ); |
| 177 | return insertionIndex; |
| 178 | } |
| 179 | |
| 180 | void ProjectBuildSetModel::removeItemsWithCache( const QList<int>& itemIndices ) |
| 181 | { |