Skip to content
Permalink
Browse files

[file widget] add a save file mode to allow file creation

  • Loading branch information
nirvn committed Dec 7, 2017
1 parent bac80aa commit cddca2f8501ab1c98ec776316a7c5cba9f384757
Showing with 25 additions and 0 deletions.
  1. +12 −0 src/gui/qgsfilewidget.cpp
  2. +13 −0 src/gui/qgsfilewidget.h
@@ -262,6 +262,17 @@ void QgsFileWidget::openFileDialog()
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Select a directory" );
fileName = QFileDialog::getExistingDirectory( this, title, QFileInfo( oldPath ).absoluteFilePath(), QFileDialog::ShowDirsOnly );
break;
case SaveFile:
title = !mDialogTitle.isEmpty() ? mDialogTitle : tr( "Create or select a file" );
if ( !confirmOverwrite() )
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter, nullptr, QFileDialog::DontConfirmOverwrite );
}
else
{
fileName = QFileDialog::getSaveFileName( this, title, QFileInfo( oldPath ).absoluteFilePath(), mFilter );
}
break;
}

if ( fileName.isEmpty() && fileNames.isEmpty( ) )
@@ -283,6 +294,7 @@ void QgsFileWidget::openFileDialog()
switch ( mStorageMode )
{
case GetFile:
case SaveFile:
settings.setValue( QStringLiteral( "UI/lastFileNameWidgetDir" ), QFileInfo( fileName ).absolutePath() );
break;
case GetDirectory:
@@ -65,6 +65,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
GetFile, //! Select a single file
GetDirectory, //! Select a directory
GetMultipleFiles, //! Select multiple files
SaveFile, //! Select a single new or pre-existing file
};

/**
@@ -120,6 +121,17 @@ class GUI_EXPORT QgsFileWidget : public QWidget
*/
void setFilter( const QString &filter );

/**
* Sets whether a confirmation to overwrite an existing file will appear
* \param confirmOverwrite If set to true, an overwrite confirmation will be shown
*/
void setConfirmOverwrite( bool confirmOverwrite ) { mConfirmOverwrite = confirmOverwrite; }

/**
* Returns whether a confirmation will be shown when overwriting an existing file
*/
bool confirmOverwrite() const { return mConfirmOverwrite; }

//! determines if the tool button is shown
bool fileWidgetButtonVisible() const;
//! determines if the tool button is shown
@@ -173,6 +185,7 @@ class GUI_EXPORT QgsFileWidget : public QWidget
QString mDialogTitle;
QString mFilter;
QString mDefaultRoot;
bool mConfirmOverwrite = true;
StorageMode mStorageMode = GetFile;
RelativeStorage mRelativeStorage = Absolute;

0 comments on commit cddca2f

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