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
4
+ 12
11
@@ -18,7 +18,8 @@
namespace {
QStringList splitName(const QString& s) {
QStringList splitName(const QString& s)
{
QRegularExpression pattern("(.*)_(\\d+)$");
QRegularExpressionMatch match = pattern.match(s);
if (match.hasMatch()) {
@@ -42,19 +43,19 @@ void NamedItem::renumber(const QStringList& extant_names)
// 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