Skip to content
Permalink
Browse files

Save and reload export settings

  • Loading branch information
NEDJIMAbelgacem committed Jul 11, 2020
1 parent 269210f commit 8cb43155fcec2d7a84b4a1fa14f416e0c46294d8
@@ -14,3 +14,30 @@
***************************************************************************/

#include "qgs3dmapexportsettings.h"
#include "qgssettings.h"

Qgs3DMapExportSettings::Qgs3DMapExportSettings( QObject *parent ): QObject( parent )
{
QgsSettings settings;
mSceneName = settings.value( QStringLiteral( "UI/last3DSceneExportName" ), QStringLiteral( "Scene" ) ).toString();
mSceneFolderPath = settings.value( QStringLiteral( "UI/last3DSceneExportDir" ), QDir::homePath() ).toString();
mTerrainResolution = settings.value( QStringLiteral( "UI/last3DSceneExportTerrainResolution" ), 128 ).toInt();
mTerrainTextureResolution = settings.value( QStringLiteral( "UI/last3DSceneExportTerrainTextureResolution" ), 512 ).toInt();
mScale = settings.value( QStringLiteral( "UI/last3DSceneExportModelScale" ), 1.0f ).toFloat();
mSmoothEdges = settings.value( QStringLiteral( "UI/last3DSceneExportSmoothEdges" ), false ).toBool();
mExportNormals = settings.value( QStringLiteral( "UI/last3DSceneExportExportNormals" ), true ).toBool();
mExportTextures = settings.value( QStringLiteral( "UI/last3DSceneExportExportTextures" ), true ).toBool();
}

Qgs3DMapExportSettings::~Qgs3DMapExportSettings()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "UI/last3DSceneExportName" ), mSceneName );
settings.setValue( QStringLiteral( "UI/last3DSceneExportDir" ), mSceneFolderPath );
settings.setValue( QStringLiteral( "UI/last3DSceneExportTerrainResolution" ), mTerrainResolution );
settings.setValue( QStringLiteral( "UI/last3DSceneExportTerrainTextureResolution" ), mTerrainTextureResolution );
settings.setValue( QStringLiteral( "UI/last3DSceneExportModelScale" ), mScale );
settings.setValue( QStringLiteral( "UI/last3DSceneExportSmoothEdges" ), mSmoothEdges );
settings.setValue( QStringLiteral( "UI/last3DSceneExportExportNormals" ), mExportNormals );
settings.setValue( QStringLiteral( "UI/last3DSceneExportExportTextures" ), mExportTextures );
}
@@ -33,7 +33,10 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
Q_OBJECT
public:
//! Constructor
Qgs3DMapExportSettings( QObject *parent = nullptr ): QObject( parent ) { }
Qgs3DMapExportSettings( QObject *parent = nullptr );

//! destructor (save the export settings before deallocation)
~Qgs3DMapExportSettings();

//! Returns the scene name
QString sceneName() const { return mSceneName; }
@@ -33,15 +33,7 @@ QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExport
{
ui->setupUi( this );

QgsSettings settings;
ui->selectFolderWidget->setStorageMode( QgsFileWidget::StorageMode::GetDirectory );
QString initialPath = settings.value( QStringLiteral( "UI/last3DSceneExportDir" ), QDir::homePath() ).toString();
ui->selectFolderWidget->setDefaultRoot( initialPath );

ui->sceneNameLineEdit->setText( exportSettings->sceneName() );
ui->selectFolderWidget->setFilePath( exportSettings->sceneFolderPath() );
ui->terrainResolutionSpinBox->setValue( exportSettings->terrrainResolution() );
ui->smoothEdgesCheckBox->setChecked( exportSettings->smoothEdges() );
loadSettings();

connect( ui->sceneNameLineEdit, &QLineEdit::textChanged, [ = ]( const QString & ) { settingsChanged(); } );
connect( ui->selectFolderWidget, &QgsFileWidget::fileChanged, [ = ]( const QString & ) { settingsChanged(); } );
@@ -61,6 +53,18 @@ QgsMap3DExportWidget::~QgsMap3DExportWidget()
delete ui;
}

void QgsMap3DExportWidget::loadSettings()
{
ui->sceneNameLineEdit->setText( mExportSettings->sceneName() );
ui->selectFolderWidget->setFilePath( mExportSettings->sceneFolderPath() );
ui->terrainResolutionSpinBox->setValue( mExportSettings->terrrainResolution() );
ui->terrainTextureResolutionSpinBox->setValue( mExportSettings->terrainTextureResolution() );
ui->smoothEdgesCheckBox->setChecked( mExportSettings->smoothEdges() );
ui->exportNormalsCheckBox->setChecked( mExportSettings->exportNormals() );
ui->exportTexturesCheckBox->setChecked( mExportSettings->exportTextures() );
ui->scaleSpinBox->setValue( mExportSettings->scale() );
}

void QgsMap3DExportWidget::settingsChanged()
{
mExportSettings->setSceneName( ui->sceneNameLineEdit->text() );
@@ -76,6 +80,4 @@ void QgsMap3DExportWidget::settingsChanged()
void QgsMap3DExportWidget::exportScene()
{
mScene->exportScene( *mExportSettings );
QgsSettings settings;
settings.setValue( QStringLiteral( "UI/last3DSceneExportDir" ), mExportSettings->sceneFolderPath() );
}
@@ -34,6 +34,7 @@ class QgsMap3DExportWidget : public QWidget
explicit QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExportSettings *exportSettings, QWidget *parent = nullptr );
~QgsMap3DExportWidget();

void loadSettings();
void exportScene();
private slots:
void settingsChanged();

0 comments on commit 8cb4315

Please sign in to comment.
You can’t perform that action at this time.