68 if (!
d->directory.exists()) {
77 QHash<int, QString> files;
80 Q_FOREACH (QString file, fileNames) {
81 QRegularExpressionMatch match = fileRegex.match(file);
83 if (match.hasMatch()) {
84 int index = match.captured(1).toInt();
85 files.insert(index, file);
86 indecies.push_back(index);
91 std::sort(indecies.begin(), indecies.end());
93 QHash<int, int> holes;
96 for (
auto it = indecies.begin(); it != indecies.end(); ++it) {
98 int diff = curIndex - prevIndex;
101 holes.insert(curIndex, diff - 1);
104 prevIndex = curIndex;
108 if (holes.isEmpty()) {
115 for (
auto it = indecies.begin(); it != indecies.end(); ++it) {
118 if (holes.contains(ind)) {
119 offset += holes[ind];
126 QString oldName = files[ind];
127 QString newName = QString(
"%2.%3").arg(QString(
"%1").arg(ind - offset, 7, 10, QLatin1Char(
'0')),
130 int tailIndex =
d->tails.indexOf(oldName);
131 if (tailIndex != -1) {
132 new_tails[tailIndex] = newName;
136 d->directory.rename(oldName, newName);
139 if (
d->tails != new_tails) {
140 d->tails = new_tails;