This algorithm tries to maintain the relative order of colors.
| 157 | |
| 158 | // This algorithm tries to maintain the relative order of colors. |
| 159 | MapColorMap Map::MapColorSet::importSet(const Map::MapColorSet& other, std::vector< bool >* filter, Map* map) |
| 160 | { |
| 161 | MapColorMap out_pointermap; |
| 162 | |
| 163 | // Determine number of colors to import |
| 164 | std::size_t import_count = other.colors.size(); |
| 165 | if (filter) |
| 166 | { |
| 167 | Q_ASSERT(filter->size() == other.colors.size()); |
| 168 | |
| 169 | for (std::size_t i = 0, end = other.colors.size(); i != end; ++i) |
| 170 | { |
| 171 | MapColor* color = other.colors[i]; |
| 172 | if (!(*filter)[i] || out_pointermap.contains(color)) |
| 173 | { |
| 174 | continue; |
| 175 | } |
| 176 | |
| 177 | out_pointermap[color] = nullptr; // temporary used as a flag |
| 178 | |
| 179 | // Determine referenced spot colors, and add them to the filter |
| 180 | if (color->getSpotColorMethod() == MapColor::CustomColor) |
| 181 | { |
| 182 | for (const SpotColorComponent& component : color->getComponents()) |
| 183 | { |
| 184 | if (!out_pointermap.contains(component.spot_color)) |
| 185 | { |
| 186 | // Add this spot color to the filter |
| 187 | int j = 0; |
| 188 | while (other.colors[j] != component.spot_color) |
| 189 | ++j; |
| 190 | (*filter)[j] = true; |
| 191 | out_pointermap[component.spot_color] = nullptr; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | import_count = out_pointermap.size(); |
| 197 | out_pointermap.clear(); |
| 198 | } |
| 199 | |
| 200 | if (import_count > 0) |
| 201 | { |
| 202 | colors.reserve(colors.size() + import_count); |
| 203 | |
| 204 | // The conflict resolution algorithm below is simplified by setting |
| 205 | // iterator `selected_item` to a real list element which is not related |
| 206 | // to the actual color sets we are merging. This is the extra element |
| 207 | // identified as `end_of_merge_list`. |
| 208 | MapColorSetMergeList merge_list{other.colors.size() + 1}; |
| 209 | const auto end_of_merge_list = end(merge_list) - 1; |
| 210 | |
| 211 | bool priorities_changed = false; |
| 212 | |
| 213 | // Initialize merge_list |
| 214 | auto merge_list_item = merge_list.begin(); |
| 215 | for (std::size_t i = 0; i < other.colors.size(); ++i) |
| 216 | { |
no test coverage detected