mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-10 00:05:25 -04:00
[file widget] add a save file mode to allow file creation
This commit is contained in:
parent
bac80aa93a
commit
cddca2f850
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user