Skip to content

Commit

Permalink
use home directory as default path if nothing else can be used
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Jan 13, 2016
1 parent a88e238 commit cc9f000
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/gui/editorwidgets/qgsexternalresourceconfigdlg.cpp
Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsexternalresourcewidgetwrapper.cpp
Expand Up @@ -36,7 +36,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const
{
if ( mQgsWidget )
{
return mQgsWidget->documentPath();
mQgsWidget->documentPath( field().type() );
}

if ( mLineEdit )
Expand Down
19 changes: 5 additions & 14 deletions src/gui/qgsexternalresourcewidget.cpp
Expand Up @@ -58,31 +58,22 @@ 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
{
return path;
}
}

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()
Expand Down
10 changes: 6 additions & 4 deletions src/gui/qgsexternalresourcewidget.h
Expand Up @@ -18,11 +18,10 @@
#define QGSEXTERNALRESOURCEWIDGET_H

class QWebView;

class QVariant;
class QgsPixmapLabel;

#include <QWidget>
#include <QVariant>

#include "qgsfilepickerwidget.h"

Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions src/gui/qgsfilepickerwidget.cpp
Expand Up @@ -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 ) );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -219,7 +228,7 @@ void QgsFilePickerWidget::openFileDialog()
else if ( mStorageMode == Directory )
{
settings.setValue( "/UI/lastFileNameWidgetDir", fileName );
}
}

// Handle relative Path storage
fileName = relativePath( fileName, true );
Expand Down Expand Up @@ -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() )
Expand Down

0 comments on commit cc9f000

Please sign in to comment.