DisplayLabels.h header
#include <ew/app/DisplayLabels.h>
Namespace ew::app
Functions
QStringList ew::app::disambiguateLabels(const QStringList &labels)
Returns a copy of labels with every entry made unique, preserving order and length so the result stays positionally 1:1 with the input.
This exists to make selection dialogs safe. A common pattern builds a parallel (QStringList labels, container ids) pair, shows the labels in a picker, then recovers the chosen item with labels.indexOf(chosen). QStringList::indexOf returns the first match, so when two entries share a label – two entities with the same name, several "(unnamed)"/"(untitled)" placeholders, two same-named files – the recovered index points at the wrong id and the wrong object is acted on. Feeding the labels through this function first guarantees the shown list has no duplicates, so indexOf maps back to exactly the picked position.
The first occurrence of a label is kept verbatim; each later duplicate gets a " (N)" suffix, with N advanced until the candidate collides with nothing already emitted (so a literal "Name (2)" in the input can never be shadowed).