QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgsinstallgridshiftdialog.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsinstallgridshiftdialog.cpp
3 -------------------
4 begin : September 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19#include "moc_qgsinstallgridshiftdialog.cpp"
20#include "qgsgui.h"
21#include "qgssettings.h"
22#include "qgsapplication.h"
23
24#include <QFileDialog>
25#include <QMessageBox>
26
28
29QgsInstallGridShiftFileDialog::QgsInstallGridShiftFileDialog( const QString &gridName, QWidget *parent )
30 : QDialog( parent )
31 , mGridName( gridName )
32{
33 setupUi( this );
35
36 mInstallButton->setText( tr( "Install %1 from Folder…" ).arg( mGridName ) );
37
38 connect( mInstallButton, &QPushButton::clicked, this, &QgsInstallGridShiftFileDialog::installFromFile );
39}
40
41void QgsInstallGridShiftFileDialog::setDescription( const QString &html )
42{
43 mSummaryLabel->setHtml( html );
44}
45
46void QgsInstallGridShiftFileDialog::setDownloadMessage( const QString &message )
47{
48 mDownloadLabel->setText( message );
49}
50
51void QgsInstallGridShiftFileDialog::installFromFile()
52{
53 QgsSettings settings;
54 const QString initialDir = settings.value( QStringLiteral( "lastTransformGridFolder" ), QDir::homePath(), QgsSettings::App ).toString();
55 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
57 if ( gridFilePath.isEmpty() )
58 {
59 return; //canceled by the user
60 }
61
62 const QFileInfo fi( gridFilePath );
63 settings.setValue( QStringLiteral( "lastTransformGridFolder" ), fi.absolutePath(), QgsSettings::App );
64
65 const QString baseGridPath = QgsApplication::qgisSettingsDirPath() + QStringLiteral( "proj" );
66
67 const QString destFilePath = baseGridPath + '/' + mGridName;
68 const QString destPath = QFileInfo( destFilePath ).absolutePath();
69
70 if ( !QDir( destPath ).exists() )
71 QDir().mkpath( destPath );
72
73 if ( QFile::copy( gridFilePath, destFilePath ) )
74 {
75 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 ) );
76 accept();
77 }
78 else
79 {
80 QMessageBox::critical( this, tr( "Install Grid File" ), tr( "Could not copy %1 to %2. Please check folder permissions and retry." ).arg( mGridName, destFilePath ) );
81 }
82}
83
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition qgsgui.cpp:209
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.