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

Attempt to fix Windows GPKG project storage #33265

Merged
merged 1 commit into from
Dec 8, 2019
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
15 changes: 11 additions & 4 deletions src/core/providers/ogr/qgsgeopackageprojectstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,29 @@ QgsGeoPackageProjectUri QgsGeoPackageProjectStorage::decodeUri( const QString &u
{
QUrl url = QUrl::fromEncoded( uri.toUtf8() );
QUrlQuery urlQuery( url.query() );
const QString urlAsString( url.toString( ) );

QgsGeoPackageProjectUri gpkgUri;

// Check for windows paths: github issue #33057
const QRegularExpression winLocalPath { R"(^[A-Za-z]:)" };
// Check for windows network shares: github issue #31310
const QString path { url.toString().startsWith( QStringLiteral( "//" ) ) ? url.toString() : url.path() };
gpkgUri.valid = url.isValid() && QFile::exists( path );
gpkgUri.database = path;
const QString path { ( winLocalPath.match( urlAsString ).hasMatch() ||
urlAsString.startsWith( QStringLiteral( "//" ) ) ) ?
urlAsString :
url.path() };

gpkgUri.valid = QFile::exists( path );
gpkgUri.database = path;
gpkgUri.projectName = urlQuery.queryItemValue( "projectName" );

return gpkgUri;
}

QString QgsGeoPackageProjectStorage::filePath( const QString &uri )
{
const QgsGeoPackageProjectUri gpkgUri { decodeUri( uri ) };
return gpkgUri.valid ? gpkgUri.database : QString();
return gpkgUri.valid ? gpkgUri.database : QString();
}


Expand Down
6 changes: 4 additions & 2 deletions src/gui/providers/ogr/qgsgeopackageprojectstoragedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ QgsGeoPackageProjectStorageDialog::QgsGeoPackageProjectStorageDialog( bool savin

connect( mFileWidget, &QgsFileWidget::fileChanged, this, [ = ]( const QString & path )
{
const QString fileName{QFileInfo( path ).fileName()};
const QString fileName{ QFileInfo( path ).fileName() };
if ( mCboConnection->findData( path ) == -1 )
{
mCboConnection->addItem( QFileInfo( path ).fileName(), path );
// the call to filePath standardizes the path and prevents
// an error when opening the file on windows
mCboConnection->addItem( fileName, QFileInfo( path ).filePath() );
mCboConnection->setItemData( mCboConnection->findText( fileName ), path, Qt::ItemDataRole::ToolTipRole );
}
mCboConnection->setCurrentIndex( mCboConnection->findText( fileName ) );
Expand Down