QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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.
 

Public Member Functions

 QgsFileWidget (QWidget *parent=nullptr)
 QgsFileWidget creates a widget for selecting a file or a folder.
 
bool confirmOverwrite () const
 Returns whether a confirmation will be shown when overwriting an existing file.
 
QString defaultRoot () const
 Returns the default root path.
 
QString dialogTitle () const
 Returns the open file dialog title.
 
QString filePath ()
 Returns the current file path(s).
 
bool fileWidgetButtonVisible () const
 Returns true if the tool button is shown.
 
QString filter () const
 returns the filters used for QDialog::getOpenFileName
 
bool fullUrl () const
 Returns true if the links shown use the full path.
 
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.
 
QSize minimumSizeHint () const override
 
QFileDialog::Options options () const
 Returns the additional options used for QFileDialog.
 
QgsFileWidget::RelativeStorage relativeStorage () const
 Returns if the relative path is with respect to the project path or the default path.
 
QString selectedFilter () const
 Returns the selected filter from the last opened file dialog.
 
void setConfirmOverwrite (bool confirmOverwrite)
 Sets whether a confirmation to overwrite an existing file will appear.
 
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.
 
void setDialogTitle (const QString &title)
 Sets the title to use for the open file dialog.
 
void setFilePath (const QString &path)
 Sets the current file path.
 
void setFileWidgetButtonVisible (bool visible)
 Sets whether the tool button is visible.
 
void setFilter (const QString &filter)
 setFilter sets the filter used by the model to filters.
 
void setFullUrl (bool fullUrl)
 Sets whether links shown use the full path.
 
void setOptions (QFileDialog::Options options)
 Set additional options used for QFileDialog.
 
virtual void setReadOnly (bool readOnly)
 Sets whether the widget should be read only.
 
void setRelativeStorage (QgsFileWidget::RelativeStorage relativeStorage)
 Sets whether the relative path is with respect to the project path or the default path.
 
void setSelectedFilter (const QString &selectedFilter)
 Sets the selected filter when the file dialog opens.
 
void setStorageMode (QgsFileWidget::StorageMode storageMode)
 Sets the widget's storage mode (i.e.
 
void setUseLink (bool useLink)
 Sets whether the file path will be shown as a link.
 
QgsFileWidget::StorageMode storageMode () const
 Returns the widget's storage mode (i.e.
 
bool useLink () const
 Returns true if the file path will be shown as a link.
 

Static Public Member Functions

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

Protected Member Functions

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

Static Protected Member Functions

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

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 37 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 219 of file qgsfilewidget.cpp.

◆ dialogTitle()

QString QgsFileWidget::dialogTitle ( ) const

Returns the open file dialog title.

See also
setDialogTitle()

Definition at line 116 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 78 of file qgsfilewidget.cpp.

◆ fileWidgetButtonVisible()

bool QgsFileWidget::fileWidgetButtonVisible ( ) const

Returns true if the tool button is shown.

See also
setFileWidgetButtonVisible()

Definition at line 147 of file qgsfilewidget.cpp.

◆ filter()

QString QgsFileWidget::filter ( ) const

returns the filters used for QDialog::getOpenFileName

Definition at line 126 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 209 of file qgsfilewidget.cpp.

◆ isMultiFiles()

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

Returns true if path is a multifiles.

Definition at line 158 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.

Definition at line 250 of file qgsfilewidget.cpp.

◆ minimumSizeHint()

QSize QgsFileWidget::minimumSizeHint ( ) const
override

Definition at line 444 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 137 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 417 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 240 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 224 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 121 of file qgsfilewidget.cpp.

◆ setFilePath()

void QgsFileWidget::setFilePath ( const QString &  path)

Sets the current file path.

See also
filePath()

Definition at line 100 of file qgsfilewidget.cpp.

◆ setFilePaths()

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

Update filePath according to filePaths list.

Definition at line 398 of file qgsfilewidget.cpp.

◆ setFileWidgetButtonVisible()

void QgsFileWidget::setFileWidgetButtonVisible ( bool  visible)

Sets whether the tool button is visible.

See also
fileWidgetButtonVisible()

Definition at line 152 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 131 of file qgsfilewidget.cpp.

◆ setFullUrl()

void QgsFileWidget::setFullUrl ( bool  fullUrl)

Sets whether links shown use the full path.

See also
fullUrl()

Definition at line 214 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 142 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 106 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 245 of file qgsfilewidget.cpp.

◆ setSelectedFileNames()

void QgsFileWidget::setSelectedFileNames ( QStringList  fileNames)
protectedvirtual

Called whenever user select fileNames from dialog.

Reimplemented in QgsExternalStorageFileWidget.

Definition at line 385 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 234 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 200 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 83 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 229 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 454 of file qgsfilewidget.cpp.

◆ updateLayout()

void QgsFileWidget::updateLayout ( )
protectedvirtual

Update buttons visibility.

Reimplemented in QgsExternalStorageFileWidget.

Definition at line 255 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 195 of file qgsfilewidget.cpp.

Friends And Related Symbol Documentation

◆ TestQgsExternalResourceWidgetWrapper

friend class TestQgsExternalResourceWidgetWrapper
friend

Definition at line 357 of file qgsfilewidget.h.

◆ TestQgsExternalStorageFileWidget

friend class TestQgsExternalStorageFileWidget
friend

Definition at line 356 of file qgsfilewidget.h.

◆ TestQgsFileWidget

friend class TestQgsFileWidget
friend

Definition at line 355 of file qgsfilewidget.h.

Member Data Documentation

◆ mButtonVisible

bool QgsFileWidget::mButtonVisible = true
protected

Definition at line 325 of file qgsfilewidget.h.

◆ mConfirmOverwrite

bool QgsFileWidget::mConfirmOverwrite = true
protected

Definition at line 334 of file qgsfilewidget.h.

◆ mDefaultRoot

QString QgsFileWidget::mDefaultRoot
protected

Definition at line 333 of file qgsfilewidget.h.

◆ mDialogTitle

QString QgsFileWidget::mDialogTitle
protected

Definition at line 330 of file qgsfilewidget.h.

◆ mFilePath

QString QgsFileWidget::mFilePath
protected

Definition at line 324 of file qgsfilewidget.h.

◆ mFileWidgetButton

QToolButton* QgsFileWidget::mFileWidgetButton = nullptr
protected

Definition at line 342 of file qgsfilewidget.h.

◆ mFilter

QString QgsFileWidget::mFilter
protected

Definition at line 331 of file qgsfilewidget.h.

◆ mFullUrl

bool QgsFileWidget::mFullUrl = false
protected

Definition at line 327 of file qgsfilewidget.h.

◆ mIsLinkEdited

bool QgsFileWidget::mIsLinkEdited = false
protected

Definition at line 329 of file qgsfilewidget.h.

◆ mLayout

QHBoxLayout* QgsFileWidget::mLayout = nullptr
protected

Definition at line 343 of file qgsfilewidget.h.

◆ mLineEdit

QgsFileDropEdit* QgsFileWidget::mLineEdit = nullptr
protected

Definition at line 340 of file qgsfilewidget.h.

◆ mLinkEditButton

QToolButton* QgsFileWidget::mLinkEditButton = nullptr
protected

Definition at line 341 of file qgsfilewidget.h.

◆ mLinkLabel

QLabel* QgsFileWidget::mLinkLabel = nullptr
protected

Definition at line 339 of file qgsfilewidget.h.

◆ mOptions

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

Definition at line 337 of file qgsfilewidget.h.

◆ mReadOnly

bool QgsFileWidget::mReadOnly = false
protected

Definition at line 328 of file qgsfilewidget.h.

◆ mRelativeStorage

RelativeStorage QgsFileWidget::mRelativeStorage = Absolute
protected

Definition at line 336 of file qgsfilewidget.h.

◆ mSelectedFilter

QString QgsFileWidget::mSelectedFilter
protected

Definition at line 332 of file qgsfilewidget.h.

◆ mStorageMode

StorageMode QgsFileWidget::mStorageMode = GetFile
protected

Definition at line 335 of file qgsfilewidget.h.

◆ mUseLink

bool QgsFileWidget::mUseLink = false
protected

Definition at line 326 of file qgsfilewidget.h.

Property Documentation

◆ defaultRoot

QString QgsFileWidget::defaultRoot
readwrite

Definition at line 56 of file qgsfilewidget.h.

◆ dialogTitle

QString QgsFileWidget::dialogTitle
readwrite

Definition at line 54 of file qgsfilewidget.h.

◆ fileWidgetButtonVisible

bool QgsFileWidget::fileWidgetButtonVisible
readwrite

Definition at line 51 of file qgsfilewidget.h.

◆ filter

QString QgsFileWidget::filter
readwrite

Definition at line 55 of file qgsfilewidget.h.

◆ fullUrl

bool QgsFileWidget::fullUrl
readwrite

Definition at line 53 of file qgsfilewidget.h.

◆ options

QFileDialog::Options QgsFileWidget::options
readwrite

Definition at line 59 of file qgsfilewidget.h.

◆ relativeStorage

RelativeStorage QgsFileWidget::relativeStorage
readwrite

Definition at line 58 of file qgsfilewidget.h.

◆ storageMode

StorageMode QgsFileWidget::storageMode
readwrite

Definition at line 57 of file qgsfilewidget.h.

◆ useLink

bool QgsFileWidget::useLink
readwrite

Definition at line 52 of file qgsfilewidget.h.


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