Skip to content
Permalink
Browse files

use home directory as default path if nothing else can be used

  • Loading branch information
3nids committed Jan 11, 2016
1 parent a88e238 commit cc9f0000be205348d522da329e975c6c429535eb
@@ -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 );
@@ -36,7 +36,7 @@ QVariant QgsExternalResourceWidgetWrapper::value() const
{
if ( mQgsWidget )
{
return mQgsWidget->documentPath();
mQgsWidget->documentPath( field().type() );
}

if ( mLineEdit )
@@ -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()
@@ -18,11 +18,10 @@
#define QGSEXTERNALRESOURCEWIDGET_H

class QWebView;

class QVariant;
class QgsPixmapLabel;

#include <QWidget>
#include <QVariant>

#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
@@ -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() )

0 comments on commit cc9f000

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