Skip to content
Snippets Groups Projects

ensure that there are no duplicate names in lists; disable cp/rm actions for empty lists

Merged Wuttke, Joachim requested to merge j.3 into main
Files
6
+ 14
13
@@ -18,8 +18,9 @@
namespace {
QStringList splitName(const QString& s) {
QRegularExpression pattern("(.*)_(\\d+)");
QStringList splitName(const QString& s)
{
QRegularExpression pattern("(.*)_(\\d+)$");
QRegularExpressionMatch match = pattern.match(s);
if (match.hasMatch()) {
QStringList groups;
@@ -36,25 +37,25 @@ QStringList splitName(const QString& s) {
void NamedItem::renumber(const QStringList& extant_names)
{
// Item name consists of a stem and an optional number
QStringList ns = splitName(name());
QStringList ns = ::splitName(name());
QString stem = ns.isEmpty() ? name() : ns[0];
// Determine highest number for given stem in extant_items
int imax = 0;
for (QString tname : extant_names) {
QStringList ts = splitName(tname);
if (ts.isEmpty()) {
if (tname == stem)
imax = std::max(imax, 1);
} else {
if (ts[0] == stem)
imax = std::max(imax, ts[1].toInt());
}
QStringList ts = ::splitName(tname);
if (ts.isEmpty()) {
if (tname == stem)
imax = std::max(imax, 1);
} else {
if (ts[0] == stem)
imax = std::max(imax, ts[1].toInt());
}
}
if (imax != 0)
setName(stem + "_" + QString::number(imax + 1));
setName(stem + "_" + QString::number(imax + 1));
if (name().contains(' '))
setName(name().replace(' ', '_'));
setName(name().replace(' ', '_'));
}
Loading