Skip to content

Commit cc9f000

Browse files
committedJan 13, 2016
use home directory as default path if nothing else can be used
1 parent a88e238 commit cc9f000

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed
 

‎src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ QgsExternalResourceConfigDlg::QgsExternalResourceConfigDlg( QgsVectorLayer* vl,
3131
mUseLink->setChecked( false );
3232
mFullUrl->setChecked( false );
3333
mDocumentViewerGroupBox->setChecked( false );
34-
mRootPath->setPlaceholderText( QSettings().value( "/UI/lastExternalResourceWidgetDir", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString() );
34+
mRootPath->setPlaceholderText( QSettings().value( "/UI/lastExternalResourceWidgetDefaultPath", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString() );
3535

3636
// Add connection to button for choosing default path
3737
connect( mRootPathButton, SIGNAL( clicked() ), this, SLOT( chooseDefaultPath() ) );
@@ -65,7 +65,7 @@ void QgsExternalResourceConfigDlg::chooseDefaultPath()
6565
}
6666
else
6767
{
68-
dir = QSettings().value( "/UI/lastExternalResourceWidgetDir", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString();
68+
dir = QSettings().value( "/UI/lastExternalResourceWidgetDefaultPath", QDir::toNativeSeparators( QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ) ).toString();
6969
}
7070

7171
QString rootName = QFileDialog::getExistingDirectory( this, tr( "Select a directory" ), dir, QFileDialog::ShowDirsOnly );

‎src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const
3636
{
3737
if ( mQgsWidget )
3838
{
39-
return mQgsWidget->documentPath();
39+
mQgsWidget->documentPath( field().type() );
4040
}
4141

4242
if ( mLineEdit )

‎src/gui/qgsexternalresourcewidget.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,22 @@ QgsExternalResourceWidget::QgsExternalResourceWidget( QWidget *parent )
5858
connect( mFilePicker, SIGNAL( fileChanged( QString ) ), this, SLOT( loadDocument( QString ) ) );
5959
}
6060

61-
QVariant QgsExternalResourceWidget::documentPath()
61+
QVariant QgsExternalResourceWidget::documentPath( QVariant::Type type ) const
6262
{
6363
QString path = mFilePicker->filePath();
64-
if ( path.isNull() || path == QSettings().value( "qgis/nullValue", "NULL" ) )
64+
if ( path.isEmpty() )
6565
{
66-
return QVariant();
66+
return QVariant( type );
6767
}
6868
else
6969
{
7070
return path;
7171
}
7272
}
7373

74-
void QgsExternalResourceWidget::setDocumentPath( QVariant value )
74+
void QgsExternalResourceWidget::setDocumentPath( QVariant path )
7575
{
76-
QString path;
77-
if ( value.isNull() )
78-
{
79-
path = QSettings().value( "qgis/nullValue", "NULL" ).toString();
80-
}
81-
else
82-
{
83-
path = value.toString();
84-
}
85-
mFilePicker->setFilePath( path );
76+
mFilePicker->setFilePath( path.toString() );
8677
}
8778

8879
QgsFilePickerWidget*QgsExternalResourceWidget::filePickerwidget()

‎src/gui/qgsexternalresourcewidget.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
#define QGSEXTERNALRESOURCEWIDGET_H
1919

2020
class QWebView;
21-
22-
class QVariant;
2321
class QgsPixmapLabel;
2422

2523
#include <QWidget>
24+
#include <QVariant>
2625

2726
#include "qgsfilepickerwidget.h"
2827

@@ -52,8 +51,11 @@ class GUI_EXPORT QgsExternalResourceWidget : public QWidget
5251

5352
explicit QgsExternalResourceWidget( QWidget *parent = 0 );
5453

55-
//! returns the value of the widget
56-
QVariant documentPath();
54+
/**
55+
* @brief documentPath returns the path of the current document in the widget
56+
* @param type determines the type of the returned null variant if the document is not defined yet
57+
*/
58+
QVariant documentPath( QVariant::Type type = QVariant::String ) const;
5759
void setDocumentPath( QVariant documentPath );
5860

5961
//! access the file picker widget to allow its configuration

‎src/gui/qgsfilepickerwidget.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ QString QgsFilePickerWidget::filePath()
7676

7777
void QgsFilePickerWidget::setFilePath( QString path )
7878
{
79+
if ( path == QSettings().value( "qgis/nullValue", "NULL" ) )
80+
{
81+
path = "";
82+
}
7983
mFilePath = path;
8084
mLineEdit->setText( path );
8185
mLinkLabel->setText( toUrl( path ) );
@@ -188,7 +192,12 @@ void QgsFilePickerWidget::openFileDialog()
188192
QUrl theUrl = QUrl::fromUserInput( oldPath );
189193
if ( !theUrl.isValid() )
190194
{
191-
oldPath = settings.value( "/UI/lastExternalResourceWidgetDir", QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() ) ).toString();
195+
QString defPath = QDir::cleanPath( QgsProject::instance()->fileInfo().absolutePath() );
196+
if ( defPath.isEmpty() )
197+
{
198+
defPath = QDir::homePath();
199+
}
200+
oldPath = settings.value( "/UI/lastExternalResourceWidgetDefaultPath", defPath ).toString();
192201
}
193202

194203
// Handle Storage
@@ -219,7 +228,7 @@ void QgsFilePickerWidget::openFileDialog()
219228
else if ( mStorageMode == Directory )
220229
{
221230
settings.setValue( "/UI/lastFileNameWidgetDir", fileName );
222-
}
231+
}
223232

224233
// Handle relative Path storage
225234
fileName = relativePath( fileName, true );
@@ -252,7 +261,7 @@ QString QgsFilePickerWidget::relativePath( QString filePath, bool removeRelative
252261
}
253262

254263

255-
QString QgsFilePickerWidget::toUrl(const QString& path ) const
264+
QString QgsFilePickerWidget::toUrl( const QString& path ) const
256265
{
257266
QString rep;
258267
if ( path.isEmpty() )

0 commit comments

Comments
 (0)