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

Fix sketching over image attachments sometimes not working #5857

Merged
merged 2 commits into from
Dec 2, 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
25 changes: 19 additions & 6 deletions src/core/platforms/platformutilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,27 @@ bool PlatformUtilities::rmFile( const QString &filename ) const
return file.remove( filename );
}

bool PlatformUtilities::renameFile( const QString &filename, const QString &newname ) const
bool PlatformUtilities::renameFile( const QString &oldFilePath, const QString &newFilePath, bool overwrite ) const
{
QFileInfo fi( newname );
QDir dir( fi.absolutePath() );
dir.mkpath( fi.absolutePath() );
QFileInfo oldFi( oldFilePath );
QFileInfo newFi( newFilePath );
if ( oldFi.absoluteFilePath() == newFi.absoluteFilePath() )
{
return true;
}

QFile file( filename );
return file.rename( newname );
// Insure the path exists
QDir dir( newFi.absolutePath() );
dir.mkpath( newFi.absolutePath() );

// If the renamed file exists, overwrite
if ( newFi.exists() && overwrite )
{
QFile newfile( newFilePath );
newfile.remove();
}

return QFile::rename( oldFilePath, newFilePath );
}

QString PlatformUtilities::applicationDirectory() const
Expand Down
2 changes: 1 addition & 1 deletion src/core/platforms/platformutilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class QFIELD_CORE_EXPORT PlatformUtilities : public QObject
// TODO: move these functions to fileutils. Make sure to adjust any qml code relying on this.
Q_INVOKABLE bool createDir( const QString &path, const QString &dirname ) const;
Q_INVOKABLE bool rmFile( const QString &filename ) const;
Q_INVOKABLE bool renameFile( const QString &filename, const QString &newname ) const;
Q_INVOKABLE bool renameFile( const QString &oldFilePath, const QString &newFilePath, bool overwrite = true ) const;


/**
Expand Down
4 changes: 4 additions & 0 deletions src/qml/editorwidgets/ExternalResource.qml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ EditorWidgetBase {
filepath = filepath.replace('{filename}', FileUtils.fileName(path));
filepath = filepath.replace('{extension}', FileUtils.fileSuffix(path));
platformUtilities.renameFile(path, prefixToRelativePath + filepath);

// In order to insure an edited image gets refreshed in the feature form, reset the source
image.source = '';
image.source = UrlUtils.fromString(prefixToRelativePath + filepath);
valueChangeRequested(filepath, false);
enabled = false;
}
Expand Down
Loading