QGIS API Documentation  3.23.0-Master (eb871beae0)
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Properties | Friends | List of all members
QgsFileWidget Class Reference

The QgsFileWidget class creates a widget for selecting a file or a folder. More...

#include <qgsfilewidget.h>

Inheritance diagram for QgsFileWidget:
Inheritance graph
[legend]

Public Types

enum  RelativeStorage { Absolute , RelativeProject , RelativeDefaultPath }
 The RelativeStorage enum determines if path is absolute, relative to the current project path or relative to a defined default path. More...
 
enum  StorageMode { GetFile , GetDirectory , GetMultipleFiles , SaveFile }
 The StorageMode enum determines if the file picker should pick files or directories. More...
 

Signals

void fileChanged (const QString &path)
 Emitted whenever the current file or directory path is changed. More...
 

Public Member Functions

 QgsFileWidget (QWidget *parent=nullptr)
 QgsFileWidget creates a widget for selecting a file or a folder. More...
 
bool confirmOverwrite () const
 Returns whether a confirmation will be shown when overwriting an existing file. More...
 
QString defaultRoot () const
 Returns the default root path. More...
 
QString dialogTitle () const
 Returns the open file dialog title. More...
 
QString filePath ()
 Returns the current file path(s). More...
 
bool fileWidgetButtonVisible () const
 Returns true if the tool button is shown. More...
 
QString filter () const
 returns the filters used for QDialog::getOpenFileName More...
 
bool fullUrl () const
 Returns true if the links shown use the full path. More...
 
QgsFilterLineEditlineEdit ()
 Returns a pointer to the widget's line edit, which can be used to customize the appearance and behavior of the line edit portion of the widget. More...
 
QFileDialog::Options options () const
 Returns the additional options used for QFileDialog. More...
 
QgsFileWidget::RelativeStorage relativeStorage () const
 Returns if the relative path is with respect to the project path or the default path. More...
 
QString selectedFilter () const
 Returns the selected filter from the last opened file dialog. More...
 
void setConfirmOverwrite (bool confirmOverwrite)
 Sets whether a confirmation to overwrite an existing file will appear. More...
 
void setDefaultRoot (const QString &defaultRoot)
 Returns the default root path used as the first shown location when picking a file and used if the RelativeStorage is RelativeDefaultPath. More...
 
void setDialogTitle (const QString &title)
 Sets the title to use for the open file dialog. More...
 
void setFilePath (const QString &path)
 Sets the current file path. More...
 
void setFileWidgetButtonVisible (bool visible)
 Sets whether the tool button is visible. More...
 
void setFilter (const QString &filter)
 setFilter sets the filter used by the model to filters. More...
 
void setFullUrl (bool fullUrl)
 Sets whether links shown use the full path. More...
 
void setOptions (QFileDialog::Options options)
 Set additional options used for QFileDialog. More...
 
virtual void setReadOnly (bool readOnly)
 Sets whether the widget should be read only. More...
 
void setRelativeStorage (QgsFileWidget::RelativeStorage relativeStorage)
 Sets whether the relative path is with respect to the project path or the default path. More...
 
void setSelectedFilter (const QString &selectedFilter)
 Sets the selected filter when the file dialog opens. More...
 
void setStorageMode (QgsFileWidget::StorageMode storageMode)
 Sets the widget's storage mode (i.e. More...
 
void setUseLink (bool useLink)
 Sets whether the file path will be shown as a link. More...
 
QgsFileWidget::StorageMode storageMode () const
 Returns the widget's storage mode (i.e. More...
 
bool useLink () const
 Returns true if the file path will be shown as a link. More...
 

Static Public Member Functions

static QStringList splitFilePaths (const QString &path)
 Split the the quoted and space separated path and returns a list of strings. More...
 

Protected Member Functions

QString relativePath (const QString &filePath, bool removeRelative) const
 Returns a filePath with relative path options applied (or not) ! More...
 
void setFilePaths (const QStringList &filePaths)
 Update filePath according to filePaths list. More...
 
virtual void setSelectedFileNames (QStringList fileNames)
 Called whenever user select fileNames from dialog. More...
 
QString toUrl (const QString &path) const
 returns a HTML code with a link to the given file path More...
 
virtual void updateLayout ()
 Update buttons visibility. More...
 

Static Protected Member Functions

static bool isMultiFiles (const QString &path)
 Returns true if path is a multifiles. More...
 

Protected Attributes

bool mButtonVisible = true
 
bool mConfirmOverwrite = true
 
QString mDefaultRoot
 
QString mDialogTitle
 
QString mFilePath
 
QToolButton * mFileWidgetButton = nullptr
 
QString mFilter
 
bool mFullUrl = false
 
bool mIsLinkEdited = false
 
QHBoxLayout * mLayout = nullptr
 
QgsFileDropEdit * mLineEdit = nullptr
 
QToolButton * mLinkEditButton = nullptr
 
QLabel * mLinkLabel = nullptr
 
QFileDialog::Options mOptions = QFileDialog::Options()
 
bool mReadOnly = false
 
RelativeStorage mRelativeStorage = Absolute
 
QString mSelectedFilter
 
StorageMode mStorageMode = GetFile
 
bool mUseLink = false
 

Properties

QString defaultRoot
 
QString dialogTitle
 
bool fileWidgetButtonVisible
 
QString filter
 
bool fullUrl
 
QFileDialog::Options options
 
RelativeStorage relativeStorage
 
StorageMode storageMode
 
bool useLink
 

Friends

class TestQgsExternalResourceWidgetWrapper
 
class TestQgsExternalStorageFileWidget
 
class TestQgsFileWidget
 

Detailed Description

The QgsFileWidget class creates a widget for selecting a file or a folder.

Definition at line 38 of file qgsfilewidget.h.

Member Enumeration Documentation

◆ RelativeStorage

The RelativeStorage enum determines if path is absolute, relative to the current project path or relative to a defined default path.

Enumerator
Absolute 
RelativeProject 
RelativeDefaultPath 

Definition at line 78 of file qgsfilewidget.h.

◆ StorageMode

The StorageMode enum determines if the file picker should pick files or directories.

Enumerator
GetFile 

Select a single file.

GetDirectory 

Select a directory.

GetMultipleFiles 

Select multiple files.

SaveFile 

Select a single new or pre-existing file.

Definition at line 66 of file qgsfilewidget.h.

Constructor & Destructor Documentation

◆ QgsFileWidget()

QgsFileWidget::QgsFileWidget ( QWidget *  parent = nullptr)
explicit

QgsFileWidget creates a widget for selecting a file or a folder.

Definition at line 36 of file qgsfilewidget.cpp.

Member Function Documentation

◆ confirmOverwrite()

bool QgsFileWidget::confirmOverwrite ( ) const
inline

Returns whether a confirmation will be shown when overwriting an existing file.

See also
setConfirmOverwrite()

Definition at line 197 of file qgsfilewidget.h.

◆ defaultRoot()

QString QgsFileWidget::defaultRoot ( ) const

Returns the default root path.

See also
setDefaultRoot()

Definition at line 225 of file qgsfilewidget.cpp.

◆ dialogTitle()

QString QgsFileWidget::dialogTitle ( ) const

Returns the open file dialog title.

See also
setDialogTitle()

Definition at line 122 of file qgsfilewidget.cpp.

◆ fileChanged

void QgsFileWidget::fileChanged ( const QString &  path)
signal

Emitted whenever the current file or directory path is changed.

◆ filePath()

QString QgsFileWidget::filePath ( )

Returns the current file path(s).

When multiple files are selected they are quoted and separated by a single space (for example: '"/path/foo" "path/bar"')

See also
setFilePath()
splitFilePaths()

Definition at line 80 of file qgsfilewidget.cpp.

◆ fileWidgetButtonVisible()

bool QgsFileWidget::fileWidgetButtonVisible ( ) const

Returns true if the tool button is shown.

See also
setFileWidgetButtonVisible()

Definition at line 153 of file qgsfilewidget.cpp.

◆ filter()

QString QgsFileWidget::filter ( ) const

returns the filters used for QDialog::getOpenFileName

Definition at line 132 of file qgsfilewidget.cpp.

◆ fullUrl()

bool QgsFileWidget::fullUrl ( ) const

Returns true if the links shown use the full path.

See also
setFullUrl()

Definition at line 215 of file qgsfilewidget.cpp.

◆ isMultiFiles()

bool QgsFileWidget::isMultiFiles ( const QString &  path)
staticprotected

Returns true if path is a multifiles.

Definition at line 164 of file qgsfilewidget.cpp.

◆ lineEdit()

QgsFilterLineEdit * QgsFileWidget::lineEdit ( )

Returns a pointer to the widget's line edit, which can be used to customize the appearance and behavior of the line edit portion of the widget.

Since
QGIS 3.0

Definition at line 256 of file qgsfilewidget.cpp.

◆ options()

QFileDialog::Options QgsFileWidget::options ( ) const

Returns the additional options used for QFileDialog.

See also
setOptions()
Since
QGIS 3.14

Definition at line 143 of file qgsfilewidget.cpp.

◆ relativePath()

QString QgsFileWidget::relativePath ( const QString &  filePath,
bool  removeRelative 
) const
protected

Returns a filePath with relative path options applied (or not) !

Definition at line 407 of file qgsfilewidget.cpp.

◆ relativeStorage()

QgsFileWidget::RelativeStorage QgsFileWidget::relativeStorage ( ) const

Returns if the relative path is with respect to the project path or the default path.

See also
setRelativeStorage()

Definition at line 246 of file qgsfilewidget.cpp.

◆ selectedFilter()

QString QgsFileWidget::selectedFilter ( ) const
inline

Returns the selected filter from the last opened file dialog.

See also
setSelectedFilter()

Definition at line 179 of file qgsfilewidget.h.

◆ setConfirmOverwrite()

void QgsFileWidget::setConfirmOverwrite ( bool  confirmOverwrite)
inline

Sets whether a confirmation to overwrite an existing file will appear.

By default, a confirmation will appear.

Parameters
confirmOverwriteIf set to true, an overwrite confirmation will be shown
See also
confirmOverwrite()

Definition at line 190 of file qgsfilewidget.h.

◆ setDefaultRoot()

void QgsFileWidget::setDefaultRoot ( const QString &  defaultRoot)

Returns the default root path used as the first shown location when picking a file and used if the RelativeStorage is RelativeDefaultPath.

See also
defaultRoot()

Definition at line 230 of file qgsfilewidget.cpp.

◆ setDialogTitle()

void QgsFileWidget::setDialogTitle ( const QString &  title)

Sets the title to use for the open file dialog.

Note
If not defined, the title is "Select a file" or "Select a directory" or "Select one or more files" depending on the configuration.
See also
dialogTitle()

Definition at line 127 of file qgsfilewidget.cpp.

◆ setFilePath()

void QgsFileWidget::setFilePath ( const QString &  path)

Sets the current file path.

See also
filePath()

Definition at line 106 of file qgsfilewidget.cpp.

◆ setFilePaths()

void QgsFileWidget::setFilePaths ( const QStringList &  filePaths)
protected

Update filePath according to filePaths list.

Definition at line 388 of file qgsfilewidget.cpp.

◆ setFileWidgetButtonVisible()

void QgsFileWidget::setFileWidgetButtonVisible ( bool  visible)

Sets whether the tool button is visible.

See also
fileWidgetButtonVisible()

Definition at line 158 of file qgsfilewidget.cpp.

◆ setFilter()

void QgsFileWidget::setFilter ( const QString &  filter)

setFilter sets the filter used by the model to filters.

The filter is used to specify the kind of files that should be shown.

Parameters
filterOnly files that match the given filter are shown, it may be an empty string. If you want multiple filters, separate them with ';;',

Definition at line 137 of file qgsfilewidget.cpp.

◆ setFullUrl()

void QgsFileWidget::setFullUrl ( bool  fullUrl)

Sets whether links shown use the full path.

See also
fullUrl()

Definition at line 220 of file qgsfilewidget.cpp.

◆ setOptions()

void QgsFileWidget::setOptions ( QFileDialog::Options  options)

Set additional options used for QFileDialog.

These options affect the look and feel of the QFileDialog shown when a user is interactively browsing for paths.

See also
options()
Since
QGIS 3.14

Definition at line 148 of file qgsfilewidget.cpp.

◆ setReadOnly()

void QgsFileWidget::setReadOnly ( bool  readOnly)
virtual

Sets whether the widget should be read only.

Reimplemented in QgsExternalStorageFileWidget.

Definition at line 112 of file qgsfilewidget.cpp.

◆ setRelativeStorage()

void QgsFileWidget::setRelativeStorage ( QgsFileWidget::RelativeStorage  relativeStorage)

Sets whether the relative path is with respect to the project path or the default path.

See also
relativeStorage()

Definition at line 251 of file qgsfilewidget.cpp.

◆ setSelectedFileNames()

void QgsFileWidget::setSelectedFileNames ( QStringList  fileNames)
protectedvirtual

Called whenever user select fileNames from dialog.

Reimplemented in QgsExternalStorageFileWidget.

Definition at line 375 of file qgsfilewidget.cpp.

◆ setSelectedFilter()

void QgsFileWidget::setSelectedFilter ( const QString &  selectedFilter)
inline

Sets the selected filter when the file dialog opens.

See also
selectedFilter()

Definition at line 172 of file qgsfilewidget.h.

◆ setStorageMode()

void QgsFileWidget::setStorageMode ( QgsFileWidget::StorageMode  storageMode)

Sets the widget's storage mode (i.e.

file or directory).

See also
storageMode()

Definition at line 240 of file qgsfilewidget.cpp.

◆ setUseLink()

void QgsFileWidget::setUseLink ( bool  useLink)

Sets whether the file path will be shown as a link.

See also
useLink()

Definition at line 206 of file qgsfilewidget.cpp.

◆ splitFilePaths()

QStringList QgsFileWidget::splitFilePaths ( const QString &  path)
static

Split the the quoted and space separated path and returns a list of strings.

See also
filePath()

Definition at line 85 of file qgsfilewidget.cpp.

◆ storageMode()

QgsFileWidget::StorageMode QgsFileWidget::storageMode ( ) const

Returns the widget's storage mode (i.e.

file or directory).

See also
setStorageMode()

Definition at line 235 of file qgsfilewidget.cpp.

◆ toUrl()

QString QgsFileWidget::toUrl ( const QString &  path) const
protected

returns a HTML code with a link to the given file path

Definition at line 435 of file qgsfilewidget.cpp.

◆ updateLayout()

void QgsFileWidget::updateLayout ( )
protectedvirtual

Update buttons visibility.

Reimplemented in QgsExternalStorageFileWidget.

Definition at line 261 of file qgsfilewidget.cpp.

◆ useLink()

bool QgsFileWidget::useLink ( ) const

Returns true if the file path will be shown as a link.

See also
setUseLink()

Definition at line 201 of file qgsfilewidget.cpp.

Friends And Related Function Documentation

◆ TestQgsExternalResourceWidgetWrapper

friend class TestQgsExternalResourceWidgetWrapper
friend

Definition at line 354 of file qgsfilewidget.h.

◆ TestQgsExternalStorageFileWidget

friend class TestQgsExternalStorageFileWidget
friend

Definition at line 353 of file qgsfilewidget.h.

◆ TestQgsFileWidget

friend class TestQgsFileWidget
friend

Definition at line 352 of file qgsfilewidget.h.

Member Data Documentation

◆ mButtonVisible

bool QgsFileWidget::mButtonVisible = true
protected

Definition at line 326 of file qgsfilewidget.h.

◆ mConfirmOverwrite

bool QgsFileWidget::mConfirmOverwrite = true
protected

Definition at line 335 of file qgsfilewidget.h.

◆ mDefaultRoot

QString QgsFileWidget::mDefaultRoot
protected

Definition at line 334 of file qgsfilewidget.h.

◆ mDialogTitle

QString QgsFileWidget::mDialogTitle
protected

Definition at line 331 of file qgsfilewidget.h.

◆ mFilePath

QString QgsFileWidget::mFilePath
protected

Definition at line 325 of file qgsfilewidget.h.

◆ mFileWidgetButton

QToolButton* QgsFileWidget::mFileWidgetButton = nullptr
protected

Definition at line 343 of file qgsfilewidget.h.

◆ mFilter

QString QgsFileWidget::mFilter
protected

Definition at line 332 of file qgsfilewidget.h.

◆ mFullUrl

bool QgsFileWidget::mFullUrl = false
protected

Definition at line 328 of file qgsfilewidget.h.

◆ mIsLinkEdited

bool QgsFileWidget::mIsLinkEdited = false
protected

Definition at line 330 of file qgsfilewidget.h.

◆ mLayout

QHBoxLayout* QgsFileWidget::mLayout = nullptr
protected

Definition at line 344 of file qgsfilewidget.h.

◆ mLineEdit

QgsFileDropEdit* QgsFileWidget::mLineEdit = nullptr
protected

Definition at line 341 of file qgsfilewidget.h.

◆ mLinkEditButton

QToolButton* QgsFileWidget::mLinkEditButton = nullptr
protected

Definition at line 342 of file qgsfilewidget.h.

◆ mLinkLabel

QLabel* QgsFileWidget::mLinkLabel = nullptr
protected

Definition at line 340 of file qgsfilewidget.h.

◆ mOptions

QFileDialog::Options QgsFileWidget::mOptions = QFileDialog::Options()
protected

Definition at line 338 of file qgsfilewidget.h.

◆ mReadOnly

bool QgsFileWidget::mReadOnly = false
protected

Definition at line 329 of file qgsfilewidget.h.

◆ mRelativeStorage

RelativeStorage QgsFileWidget::mRelativeStorage = Absolute
protected

Definition at line 337 of file qgsfilewidget.h.

◆ mSelectedFilter

QString QgsFileWidget::mSelectedFilter
protected

Definition at line 333 of file qgsfilewidget.h.

◆ mStorageMode

StorageMode QgsFileWidget::mStorageMode = GetFile
protected

Definition at line 336 of file qgsfilewidget.h.

◆ mUseLink

bool QgsFileWidget::mUseLink = false
protected

Definition at line 327 of file qgsfilewidget.h.

Property Documentation

◆ defaultRoot

QString QgsFileWidget::defaultRoot
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ dialogTitle

QString QgsFileWidget::dialogTitle
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ fileWidgetButtonVisible

bool QgsFileWidget::fileWidgetButtonVisible
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ filter

QString QgsFileWidget::filter
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ fullUrl

bool QgsFileWidget::fullUrl
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ options

QFileDialog::Options QgsFileWidget::options
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ relativeStorage

RelativeStorage QgsFileWidget::relativeStorage
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ storageMode

StorageMode QgsFileWidget::storageMode
readwrite

Definition at line 1 of file qgsfilewidget.h.

◆ useLink

bool QgsFileWidget::useLink
readwrite

Definition at line 1 of file qgsfilewidget.h.


The documentation for this class was generated from the following files: