Class SBGWidgetFileSelector#
ClassList > SBGWidgetFileSelector
The SBGWidgetFileSelector class is a convenience widget for specifying a file path - it contains a label, a line edit, and a push button to browse for a file.More...
#include <SBGWidgetFileSelector.hpp>
Inherits the following classes: QWidget
Public Slots#
| Type | Name |
|---|---|
| slot void | onBrowse Opens a file dialog to let the user select a file. |
Public Signals#
| Type | Name |
|---|---|
| signal void | pathChanged |
Public Functions#
| Type | Name |
|---|---|
| SBGWidgetFileSelector (QWidget * parent=nullptr) Constructs a path selector widget. |
|
| QString | getDefaultDirectory () const Returns the default directory of the selector. |
| QString | getFilePath () Returns the path. |
| QString | getFilter () const Returns the filter of the selector. |
| QString | getLabel () const Returns the label shown in the selector. |
| void | setDefaultDirectory (const QString & dir) Sets the default directory for the selector that will be used for browse if the file path is not set. |
| void | setFilePath (const QString & path) Sets the path. |
| void | setFilter (const QString & filter) Sets the filter for the selector. |
| void | setLabel (const QString & label) Sets the label shown in the selector. |
| virtual | ~SBGWidgetFileSelector () Destructs the path selector widget. |
Public Static Functions#
| Type | Name |
|---|---|
| bool | checkFile (const QString & path, bool askUser) Check whether the file exists. |
Detailed Description#
Short name: SBFileSelector
Public Slots Documentation#
slot onBrowse#
Opens a file dialog to let the user select a file.
Determines the initial directory based on the current file path or the default directory, then invokes SBGWindowDialog::getFileNameFromUser. If the user selects a file, updates the line edit and emits pathChanged() if the path changed.
Public Signals Documentation#
signal pathChanged#
Public Functions Documentation#
function SBGWidgetFileSelector#
Constructs a path selector widget.
When the user clicks on the browse button of this widget, it internally invokes the SBGWindowDialog::getFileNameFromUser function.
The file dialog's working directory is set to the directory of the file path, if specified, else it is set to the default directory, if specified.
// create the file selector widget
SBFileSelector* fileSelector = new SBFileSelector();
fileSelector->setLabel("Choose input file");
// add the file selector widget into a layout
// ...
You can specify the filter in the same way it is specified in QFileDialog. Only files that match the given filter are shown.
You can provide a single filter, for example:
If you want multiple filters, separate them with ';;', for example:
See also: SAMSON::getFileNameFromUser, SAMSON::getFileNamesFromUser, SAMSON::getSaveFileNameFromUser Constructs a file selector widget.
Initializes the widget with an optional parent widget. Sets up the internal layout, group box, line edit, and browse button.
Parameters:
parentOptional parent widget.
function getDefaultDirectory#
Returns the default directory of the selector.
Returns the default directory used for browsing when the file path is not set.
Returns:
The default directory path.
function getFilePath#
Returns the path.
Returns the currently selected file path.
Returns:
The file path string from the line edit.
function getFilter#
Returns the filter of the selector.
Returns the filter string used by the file selector.
Returns:
The current filter expression.
function getLabel#
Returns the label shown in the selector.
Returns the label shown in the selector's group box.
Returns:
The current label text.
function setDefaultDirectory#
Sets the default directory for the selector that will be used for browse if the file path is not set.
Sets the default directory for the file selector.
The directory will be used as the starting point for the file dialog if the current file path is empty.
Parameters:
dirThe default directory path.
function setFilePath#
Sets the path.
Sets the file path displayed in the line edit.
Updates the line edit with the trimmed path and emits pathChanged() if the new path differs from the previous one.
Parameters:
pathThe new file path.
function setFilter#
Sets the filter for the selector.
Sets the filter string for the file selector.
Parameters:
filterThe filter expression, e.g., "PDB file (*.pdb)".
function setLabel#
Sets the label shown in the selector.
Sets the label shown in the selector's group box.
Parameters:
labelThe new label text.
function ~SBGWidgetFileSelector#
Destructs the path selector widget.
Destroys the file selector widget.
Releases any allocated resources associated with the widget.
Public Static Functions Documentation#
function checkFile#
Check whether the file exists.
Checks whether the specified file exists.
If the file does not exist and askUser is true, an error dialog is shown to the user.
Parameters:
pathPath to the file to check.askUserIf true, display an error dialog when the file does not exist.
Returns:
true if the file exists, otherwise false.