void KSnapshotObject::autoincFilename() { // Extract the filename from the path QFileInfo info(file_path_); QString name= info.fileName(); // If the name contains a number then increment it QRegExp numSearch( "(^|[^\\d])(\\d+)" ); // we want to match as far left as possible, and when the number is at the start of the name // Does it have a number? int start = numSearch.lastIndexIn( name ); if (start != -1) { // It has a number, increment it start = numSearch.pos( 2 ); // we are only interested in the second group QString numAsStr = numSearch.capturedTexts()[ 2 ]; QString number = QString::number( numAsStr.toInt() + 1 ); number = number.rightJustified( numAsStr.length(), '0' ); name.replace( start, numAsStr.length(), number ); } else { // no number start = name.lastIndexOf('.'); if (start != -1) { // has a . somewhere, e.g. it has an extension name.insert(start, '1'); } else { // no extension, just tack it on to the end name += '1'; } } //Rebuild the path QString newUrl = info.absolutePath() + '/' + name; changeUrl( newUrl ); }
void KSnapshot::autoincFilename() { // Extract the filename from the path QString name= filename.fileName(); // If the name contains a number then increment it QRegExp numSearch("[0-9]+"); // Does it have a number? int start = numSearch.search(name); if (start != -1) { // It has a number, increment it int len = numSearch.matchedLength(); QString numAsStr= name.mid(start, len); QString number = QString::number(numAsStr.toInt() + 1); number = number.rightJustify( len, '0'); name.replace(start, len, number ); } else { // no number start = name.findRev('.'); if (start != -1) { // has a . somewhere, e.g. it has an extension name.insert(start, '1'); } else { // no extension, just tack it on to the end name += '1'; } } //Rebuild the path KURL newURL = filename; newURL.setFileName( name ); setURL( newURL.url() ); }