Workspace 6.21.5
Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
FileNameWidget Class Reference

Widget for specifying a file or directory name. More...

#include <Workspace/Widgets/filenamewidget.h>

Inherits QFrame.

Public Slots

void resetFileName ()
 
void setAcceptMode (QFileDialog::AcceptMode mode)
 
void setDirectoryMode (bool mode)
 
void setFileName (const QString &str)
 
void setHighlightInvalidFilePath (bool highlightInvalidFilePath)
 
void setNameFilters (const QStringList &filters)
 
void setShowRefreshButton (bool show)
 
void setShowTextField (bool show)
 
void setWarningMode (bool warningsOn)
 
void showRelativeToWorkspaceCheckbox (bool show)
 

Signals

void acceptModeChanged (QFileDialog::AcceptMode mode)
 
void directoryModeChanged (bool mode)
 
void editingFinished ()
 
void fileNameChanged (const QString &fileName)
 
void forceFileReload ()
 
void nameFiltersChanged (const QStringList &filters)
 
void showRefreshButtonChanged (bool show)
 
void userEditingFinished ()
 
void warningModeChanged (bool mode)
 

Public Member Functions

 FileNameWidget (QWidget *parent=nullptr)
 
 ~FileNameWidget () override
 
QFileDialog::AcceptMode getAcceptMode () const
 
bool getDirectoryMode () const
 
QString getFileName () const
 
bool getHighlightInvalidFilePath () const
 
const QStringListgetNameFilters () const
 
bool getShowRefreshButton () const
 
bool getShowRelativePathCheckBox () const
 
bool getShowTextField () const
 
bool getWarningMode () const
 
void setReadOnly (bool b)
 

Protected Member Functions

void enterEvent (QEvent *event) override
 

Properties

QFileDialog::AcceptMode acceptMode
 
bool directoryMode
 
QString fileName
 
bool highlightInvalidFilePath
 
QStringList nameFilters
 
bool showRefreshButton
 
bool showRelativePathCheckBox
 
bool showTextField
 
bool warnIfFileExists
 

Detailed Description

The widget is relatively simple, consisting of a line edit and a button. The button opens a file dialog which allows users to traverse the file system in order to select a file (or directory). It offers some basic configuration of the file dialog to customise it to the intended use of the widget.

Constructor & Destructor Documentation

◆ FileNameWidget()

FileNameWidget ( QWidget *  parent = nullptr)

The widget is initially constructed with no filters, the accept mode set to QFileDialog::AcceptOpen, the directory mode set to off and to not warn if the file name already exists.

◆ ~FileNameWidget()

~FileNameWidget ( )
overridedefault

Member Function Documentation

◆ acceptModeChanged

void acceptModeChanged ( QFileDialog::AcceptMode  mode)
signal

◆ directoryModeChanged

void directoryModeChanged ( bool  mode)
signal

◆ editingFinished

void editingFinished ( )
signal

This signal is emitted when the line edit part of the widget loses focus, when the user presses Return or Enter in the line edit part of the widget, or when the user accepts a selection from the file dialog opened via the button on the widget. Client code wanting to be notified of updates in a "batched" mode rather than every character change as the user types should connect to this signal rather than fileNameChanged().

See also
fileNameChanged()

◆ enterEvent()

void enterEvent ( QEvent *  event)
overrideprotected

◆ fileNameChanged

void fileNameChanged ( const QString &  fileName)
signal

This signal is emitted any time the file name changes for any reason. This includes both user interaction and the file name being changed programmatically. It also includes the file name being changed as a result of a selection from the file dialog opened from the button on the widget.

Since this signal is emitted for each character change as the user types, it is often not the signal client code wants to connect to for committing the changes to some data structure, etc.. For a more "batched" approach, editingFinished() can be used to detect when a set of changes should be committed, leaving the fileNameChanged() signal to be used only to receive notification that a change took place without actually storing the changed text.

See also
editingFinished()

◆ forceFileReload

void forceFileReload ( )
signal

signals that the refresh button has been pressed and the file should be reloaded, even if the filename has not changed.

◆ getAcceptMode()

QFileDialog::AcceptMode getAcceptMode ( ) const
Returns
The current accept mode that will be used for the file dialog created by the button.
See also
setAcceptMode()

◆ getDirectoryMode()

bool getDirectoryMode ( ) const
Returns
True if the file dialog will return a directory name rather than a file name.
See also
setDirectoryMode()

◆ getFileName()

QString getFileName ( ) const
Returns
The file name currently shown in the widget.
See also
setFileName(), resetFileName()

◆ getHighlightInvalidFilePath()

bool getHighlightInvalidFilePath ( ) const
Returns
Toggle state of highlighting behaviour for line edit when its file path is invalid.

◆ getNameFilters()

const QStringList & getNameFilters ( ) const
Returns
The currently specified filters to use in the file dialog created by the button. If an empty list is returned, no filters will be used in the dialog.
See also
setNameFilters()

◆ getShowRefreshButton()

bool getShowRefreshButton ( ) const

◆ getShowRelativePathCheckBox()

bool getShowRelativePathCheckBox ( ) const
Returns
Returns visibility state of relative path check box.

◆ getShowTextField()

bool getShowTextField ( ) const
Returns
Returns visibility state of text field.

◆ getWarningMode()

bool getWarningMode ( ) const
Returns
True if the user will be warned if the named file exists.

The warnings referred to by this function are only raised when the user sets a file name via the file system browser button.

See also
setWarningMode()

◆ nameFiltersChanged

void nameFiltersChanged ( const QStringList filters)
signal

◆ resetFileName

void resetFileName ( )
slot

Clears the file name.

See also
setFileName(), getFileName()

◆ setAcceptMode

void setAcceptMode ( QFileDialog::AcceptMode  mode)
slot
Parameters
modeControls whether the file dialog created by the button will behave as a load or save dialog.

The default value for the accept mode is QFileDialog::AcceptOpen.

◆ setDirectoryMode

void setDirectoryMode ( bool  mode)
slot
Parameters
modeIf true, then the file dialog created by the button will be configured to return a directory name rather than a file name. This is entirely analogous to the QFileDialog::Directory enum value. If mode is false, QFileDialog::AnyFile is used instead.

The default value for the directory mode is false.

See also
getDirectoryMode()

◆ setFileName

void setFileName ( const QString &  str)
slot
Parameters
strThe new file name for the widget.
See also
getFileName(), resetFileName()

◆ setHighlightInvalidFilePath

void setHighlightInvalidFilePath ( bool  highlightInvalidFilePath)
slot
Parameters
highlightInvalidFilePathToggles highlighting behaviour of line edit for invalid file paths.

◆ setNameFilters

void setNameFilters ( const QStringList filters)
slot
Parameters
filtersThe set of file name filters to be used in the file dialog. If these are empty, no filter will be used.

The default filter is empty.

See also
getNameFilters()

◆ setReadOnly()

void setReadOnly ( bool  b)

◆ setShowRefreshButton

void setShowRefreshButton ( bool  show)
slot
Parameters
showIf true then a refresh button appears alongside the folder button.

◆ setShowTextField

void setShowTextField ( bool  show)
slot
Parameters
showToggles visibility of the text field.

◆ setWarningMode

void setWarningMode ( bool  warningsOn)
slot
Parameters
warningsOnIf true, then warn the user if they specify a file name for which a file already exists. It is assumed that the file named will be written to, so the warning message will refer to overwriting the file.

The warnings referred to by this function are only raised when the user sets a file name via the file system browser button. Calling this function with warningsOn set to true only makes sense if the accept mode is set to QFileDialog::AcceptSave.

The default warning mode is false (ie no warnings).

See also
getWarningMode()

◆ showRefreshButtonChanged

void showRefreshButtonChanged ( bool  show)
signal

◆ showRelativeToWorkspaceCheckbox

void showRelativeToWorkspaceCheckbox ( bool  show)
slot
Parameters
showToggles visibility of the relative path checkbox.

◆ userEditingFinished

void userEditingFinished ( )
signal

◆ warningModeChanged

void warningModeChanged ( bool  mode)
signal

Property Documentation

◆ acceptMode

QFileDialog::AcceptMode acceptMode
readwrite

◆ directoryMode

bool directoryMode
readwrite

◆ fileName

QString fileName
readwrite

◆ highlightInvalidFilePath

bool highlightInvalidFilePath
readwrite

◆ nameFilters

QStringList nameFilters
readwrite

◆ showRefreshButton

bool showRefreshButton
readwrite

◆ showRelativePathCheckBox

bool showRelativePathCheckBox
readwrite

◆ showTextField

bool showTextField
readwrite

◆ warnIfFileExists

bool warnIfFileExists
readwrite