Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancing photo renaming with custom expressions #3514

Merged
merged 6 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/attributes/attributecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,11 @@ void AttributeController::renamePhotos()
const QString src = InputUtils::getAbsolutePath( mFeatureLayerPair.feature().attribute( item->fieldIndex() ).toString(), prefix );
QFileInfo fi( src );
QString newName = QStringLiteral( "%1.%2" ).arg( val.toString() ).arg( fi.completeSuffix() );

// Remove leading slashes from newName following issue #3415
const QRegularExpression leadingSlashes( "^/+" );
newName.remove( leadingSlashes );

const QString dst = InputUtils::getAbsolutePath( newName, prefix );
if ( InputUtils::renameFile( src, dst ) )
{
Expand Down
9 changes: 8 additions & 1 deletion app/test/testattributecontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,9 @@ void TestAttributeController::testPhotoRenaming()
InputUtils::cpDir( TestUtils::testDataDir() + "/test_photo_rename", projectDir );

QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photo2.jpg" ) ) );
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photos/Survey.jpg" ) ) );

QVERIFY( QgsProject::instance()->read( projectDir + QStringLiteral( "/test_photo_rename.qgz" ) ) );

Expand All @@ -726,15 +728,20 @@ void TestAttributeController::testPhotoRenaming()

const TabItem *tab = controller.tabItem( 0 );
const QVector<QUuid> items = tab->formItems();
QCOMPARE( items.size(), 4 );
QCOMPARE( items.size(), 5 );

controller.setFormValue( items.at( 2 ), QStringLiteral( "test" ) );
controller.setFormValue( items.at( 3 ), QStringLiteral( "photo.jpg" ) );
controller.setFormValue( items.at( 4 ), QStringLiteral( "photo2.jpg" ) );
controller.save();

QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photo.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/image_test.jpg" ) ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 3 ), QStringLiteral( "image_test.jpg" ) );

QVERIFY( !QFile::exists( projectDir + QStringLiteral( "/photo2.jpg" ) ) );
QVERIFY( QFile::exists( projectDir + QStringLiteral( "/photos/Survey.jpg" ) ) );
QCOMPARE( controller.featureLayerPair().feature().attribute( 4 ), QVariant( "photos/Survey.jpg" ) );
}

void TestAttributeController::testHtmlAndTextWidgets()
Expand Down
Binary file modified test/test_data/test_photo_rename/Survey_points.gpkg
Binary file not shown.
Binary file added test/test_data/test_photo_rename/photo2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test/test_data/test_photo_rename/test_photo_rename.qgz
Binary file not shown.
Loading