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 QFileInfo fi( gridFilePath );
65 if ( !QDir( baseGridPath ).exists() )
66 QDir().mkdir( baseGridPath );
68 const QString destPath = baseGridPath +
'/' + fi.fileName();
70 if ( QFile::copy( gridFilePath, destPath ) )
72 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 ) );
77 QMessageBox::critical(
this, tr(
"Install Grid File" ), tr(
"Could not copy %1 to %2. Please check folder permissions and retry." ).arg( mGridName, destPath ) );