diff --git a/src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp b/src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp index 8acb4ee8bb6d..7097fe49991f 100644 --- a/src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp +++ b/src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp @@ -31,7 +31,7 @@ QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg( QgsVectorLayer* vl, mUseLink->setChecked( false ); mFullUrl->setChecked( false ); mDocumentViewerGroupBox->setChecked( false ); - mRootPath->setPlaceholderText( QSettings().value( "/UI/lastExternalResourceWidgetDir", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString() ); + mRootPath->setPlaceholderText( QSettings().value( "/UI/lastExternalResourceWidgetDefaultPath", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString() ); // Add connection to button for choosing default path connect( mRootPathButton, SIGNAL( clicked() ), this, SLOT( chooseDefaultPath() ) ); @@ -65,7 +65,7 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath() } else { - dir = QSettings().value( "/UI/lastExternalResourceWidgetDir", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString(); + dir = QSettings().value( "/UI/lastExternalResourceWidgetDefaultPath", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString(); } QString rootName = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), dir, QFileDialog::ShowDirsOnly ); diff --git a/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp b/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp index a0f1a71907f1..ba3b51d1dd47 100644 --- a/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp @@ -36,7 +36,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const { if ( mQgsWidget ) { - return mQgsWidget->documentPath(); + mQgsWidget->documentPath( field().type() ); } if ( mLineEdit ) diff --git a/src/gui/qgsexternalresourcewidget.cpp b/src/gui/qgsexternalresourcewidget.cpp index 8110bd337f22..edcfee5a0224 100644 --- a/src/gui/qgsexternalresourcewidget.cpp +++ b/src/gui/qgsexternalresourcewidget.cpp @@ -58,12 +58,12 @@ QgsExternalResourceWidget::QgsExternalResourceWidget( QWidget *parent ) connect( mFilePicker, SIGNAL( fileChanged( QString ) ), this, SLOT( loadDocument( QString ) ) ); } -QVariant QgsExternalResourceWidget::documentPath() +QVariant QgsExternalResourceWidget::documentPath( QVariant::Type type ) const { QString path = mFilePicker->filePath(); - if ( path.isNull() || path == QSettings().value( "qgis/nullValue", "NULL" ) ) + if ( path.isEmpty() ) { - return QVariant(); + return QVariant( type ); } else { @@ -71,18 +71,9 @@ QVariant QgsExternalResourceWidget::documentPath() } } -void QgsExternalResourceWidget::setDocumentPath( QVariant value ) +void QgsExternalResourceWidget::setDocumentPath( QVariant path ) { - QString path; - if ( value.isNull() ) - { - path = QSettings().value( "qgis/nullValue", "NULL" ).toString(); - } - else - { - path = value.toString(); - } - mFilePicker->setFilePath( path ); + mFilePicker->setFilePath( path.toString() ); } QgsFilePickerWidget*QgsExternalResourceWidget::filePickerwidget() diff --git a/src/gui/qgsexternalresourcewidget.h b/src/gui/qgsexternalresourcewidget.h index 011f22c0d07b..7ced67757bdd 100644 --- a/src/gui/qgsexternalresourcewidget.h +++ b/src/gui/qgsexternalresourcewidget.h @@ -18,11 +18,10 @@ #define QGSEXTERNALRESOURCEWIDGET_H class QWebView; - -class QVariant; class QgsPixmapLabel; #include +#include #include "qgsfilepickerwidget.h" @@ -52,8 +51,11 @@ class GUI_EXPORT QgsExternalResourceWidget : public QWidget explicit QgsExternalResourceWidget( QWidget *parent = 0 ); - //! returns the value of the widget - QVariant documentPath(); + /** + * @brief documentPath returns the path of the current document in the widget + * @param type determines the type of the returned null variant if the document is not defined yet + */ + QVariant documentPath( QVariant::Type type = QVariant::String ) const; void setDocumentPath( QVariant documentPath ); //! access the file picker widget to allow its configuration diff --git a/src/gui/qgsfilepickerwidget.cpp b/src/gui/qgsfilepickerwidget.cpp index b6cfa98fe277..092bdd9e32d3 100644 --- a/src/gui/qgsfilepickerwidget.cpp +++ b/src/gui/qgsfilepickerwidget.cpp @@ -76,6 +76,10 @@ QString QgsFilePickerWidget::filePath() void QgsFilePickerWidget::setFilePath( QString path ) { + if ( path == QSettings().value( "qgis/nullValue", "NULL" ) ) + { + path = ""; + } mFilePath = path; mLineEdit->setText( path ); mLinkLabel->setText( toUrl( path ) ); @@ -188,7 +192,12 @@ void QgsFilePickerWidget::openFileDialog() QUrl theUrl = QUrl::fromUserInput( oldPath ); if ( !theUrl.isValid() ) { - oldPath = settings.value( "/UI/lastExternalResourceWidgetDir", QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ).toString(); + QString defPath = QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ); + if ( defPath.isEmpty() ) + { + defPath = QDir::homePath(); + } + oldPath = settings.value( "/UI/lastExternalResourceWidgetDefaultPath", defPath ).toString(); } // Handle Storage @@ -219,7 +228,7 @@ void QgsFilePickerWidget::openFileDialog() else if ( mStorageMode == Directory ) { settings.setValue( "/UI/lastFileNameWidgetDir", fileName ); -} + } // Handle relative Path storage fileName = relativePath( fileName, true ); @@ -252,7 +261,7 @@ QString QgsFilePickerWidget::relativePath( QString filePath, bool removeRelative } -QString QgsFilePickerWidget::toUrl(const QString& path ) const +QString QgsFilePickerWidget::toUrl( const QString& path ) const { QString rep; if ( path.isEmpty() )