23 #include <QFileDialog>
24 #include <QMessageBox>
28 QgsInstallGridShiftFileDialog::QgsInstallGridShiftFileDialog(
const QString &gridName, QWidget *parent )
30 , mGridName( gridName )
35 mInstallButton->setText( tr(
"Install %1 from Folder…" ).arg( mGridName ) );
37 connect( mInstallButton, &QPushButton::clicked,
this, &QgsInstallGridShiftFileDialog::installFromFile );
40 void QgsInstallGridShiftFileDialog::setDescription(
const QString &html )
42 mSummaryLabel->setHtml( html );
45 void QgsInstallGridShiftFileDialog::setDownloadMessage(
const QString &message )
47 mDownloadLabel->setText( message );
50 void QgsInstallGridShiftFileDialog::installFromFile()
53 const QString initialDir = settings.
value( QStringLiteral(
"lastTransformGridFolder" ), QDir::homePath(),
QgsSettings::App ).toString();
54 const QString gridFilePath = QFileDialog::getOpenFileName(
nullptr, tr(
"Install %1" ).arg( mGridName ), initialDir, QStringLiteral(
"%1 (%1);;" ).arg( mGridName ) + tr(
"Grid Shift Files" ) + QStringLiteral(
" (*.gsb *.GSB *.tif);;" ) + QObject::tr(
"All files" ) +
" (*)" );
56 if ( gridFilePath.isEmpty() )
61 const QFileInfo fi( gridFilePath );
66 const QString destFilePath = baseGridPath +
'/' + mGridName;
67 const QString destPath = QFileInfo( destFilePath ).absolutePath();
69 if ( !QDir( destPath ).exists() )
70 QDir().mkpath( destPath );
72 if ( QFile::copy( gridFilePath, destFilePath ) )
74 QMessageBox::information(
this, tr(
"Install Grid File" ), tr(
"The %1 grid shift file has been successfully installed. Please restart QGIS for this change to take effect." ).arg( mGridName ) );
79 QMessageBox::critical(
this, tr(
"Install Grid File" ), tr(
"Could not copy %1 to %2. Please check folder permissions and retry." ).arg( mGridName, destFilePath ) );