Version: 9.15.0
SUIT_FileDlg Class Reference

An extension of the Qt Open/Save file dialog box. More...

#include <SUIT_FileDlg.h>

Inheritance diagram for SUIT_FileDlg:
Inheritance graph

Public Member Functions

 SUIT_FileDlg (QWidget *, bool, bool=true, bool=true)
 Constructor. More...
 
 SUIT_FileDlg (QWidget *parent, const QString &initial, const QStringList &filters, const QString &caption=QString(), const bool open=true, const bool showQuickDir=true, SUIT_FileValidator *validator=0)
 Constructor. More...
 
virtual ~SUIT_FileDlg ()
 Destructor. More...
 
bool isOpenDlg () const
 Check if the dialog box is used for opening or saving the file. More...
 
bool checkPermissions () const
 Get 'check file permissions' flag. More...
 
void setCheckPermissions (const bool)
 Set 'check file permissions' flag. More...
 
SUIT_FileValidatorvalidator () const
 Get file validator. More...
 
void setValidator (SUIT_FileValidator *)
 Set file validator. More...
 
bool addWidgets (QWidget *, QWidget *, QWidget *)
 Adds the specified widgets to the bottom of the file dialog. More...
 
QStringList selectedFiles () const
 Get list of selected files. More...
 
QString selectedFile () const
 Get selected file. More...
 
void selectFile (const QString &)
 Selects current file. More...
 

Static Public Member Functions

static QString getLastVisitedDirectory ()
 Get last visited directory. More...
 
static QString getFileName (QWidget *, const QString &, const QStringList &, const QString &=QString(), const bool=true, const bool=true, SUIT_FileValidator *=0)
 Show dialog box for the file opening/saving. More...
 
static QString getFileName (QWidget *, const QString &, const QString &, const QString &=QString(), const bool=true, const bool=true, SUIT_FileValidator *=0)
 Show dialog box for the file opening/saving. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This method can be used to select the file for opening or saving. The behavior is defined by the open parameter. Note, that selection validation depends on the dialog mode used. More...
 
static QString getFileName (QWidget *parent, const QString &initial, const QStringList &filters, QString &selectedFilter, const QString &caption=QString(), const bool open=true, const bool showQuickDir=true, SUIT_FileValidator *validator=0)
 Show dialog box for the file opening/saving. More...
 
static QStringList getOpenFileNames (QWidget *, const QString &, const QStringList &, const QString &=QString(), const bool=true, SUIT_FileValidator *=0)
 Show dialog box for the multiple files selection. More...
 
static QStringList getOpenFileNames (QWidget *, const QString &, const QString &, const QString &=QString(), const bool=true, SUIT_FileValidator *=0)
 Show dialog box for the multiple file opening. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If initial parameter is not null string it is used as starting directory or file at which dialog box is opened. More...
 
static QString getExistingDirectory (QWidget *, const QString &, const QString &=QString(), const bool=true, SUIT_FileValidator *=0)
 Show dialog box for the existing directory selection. More...
 
static QString getLastVisitedPath ()
 Get last visited path. More...
 

Protected Slots

void accept ()
 Called when the user presses "Open"or "Save" button. More...
 
void quickDir (const QString &)
 Called when user selects directory from the "Quick Dir" combo box. More...
 
void addQuickDir ()
 Called when user presses "Quick Dir Add" button. More...
 

Protected Member Functions

virtual bool event (QEvent *)
 Customize events processing. More...
 
QLineEditlineEdit () const
 Get line edit which is used to enter file name. More...
 
virtual bool acceptData ()
 Validate user selection. More...
 
QString addExtension (const QString &) const
 Add an extension to the specified file name. More...
 
bool processPath (const QString &)
 Processes selection : tries to set specified sirectory or filename as current file dialog selection. More...
 
void addFilter (const QString &)
 Add file filter and activates it. More...
 

Static Protected Member Functions

static bool hasWildCards (const QString &)
 Check if the string contains wildcard symbols. More...
 

Private Member Functions

void polish ()
 Polish the dialog box. More...
 
void updateSideBar ()
 Update side bar URLs list. More...
 

Private Attributes

SUIT_FileValidatormyValidator
 file validator More...
 
QLabelmyQuickLab
 quick dir panel: label More...
 
QComboBoxmyQuickCombo
 quick dir panel: combo box More...
 
QPushButton * myQuickButton
 quick dir panel: button More...
 
QStringList myUrls
 sidebar urls More...
 
bool myCheckPermissions
 check permissions option More...
 

Static Private Attributes

static QString myLastVisitedPath
 last visited path More...
 

Detailed Description

An extension of the Qt Open/Save file dialog box.

The class SUIT_FileDlg provides a set of static methods which canbe used for file or directories selection:

Examples:

// select file to dump contents of the view
QStringList filters;
filters << "Image files (*.bmp *.gif *.jpg )" << "All files (*)";
QString fileName = SUIT_FileDlg::getFileName( desktop(),
QString(),
filters,
"Dump view",
false );
if ( !fileName.isEmpty() ) {
... writing image to the file
}
// select list of files to open in the editor windows
QStringList filters;
filters << "*.cpp | *.cxx | *.c++" << "*.h | *.hpp | *.hxx";
QStringList fileNames = SUIT_FileDlg::getOpenFileName( desktop(),
QString(),
filters,
QString() );
if ( !fileNames.isEmpty() ) {
... open files
}
static QString getFileName(QWidget *, const QString &, const QStringList &, const QString &=QString(), const bool=true, const bool=true, SUIT_FileValidator *=0)
Show dialog box for the file opening/saving.
Definition: SUIT_FileDlg.cxx:815

The class SUIT_FileDlg can be subclassed to implement custom file dialog boxes. The class provides a set of methods which can be used in subclasses:

See also
SUIT_FileValidator class.

Constructor & Destructor Documentation

◆ SUIT_FileDlg() [1/2]

SUIT_FileDlg::SUIT_FileDlg ( QWidget parent,
bool  open,
bool  showQuickDir = true,
bool  modal = true 
)

Constructor.

Parameters
parentparent widget
openif true dialog box is used for file opening, otherwise - for saving
showQuickDirif true the quick directory list widgets will be shown
modalif true the dialog box will be modal

References addQuickDir(), addWidgets(), QtxResourceMgr::booleanValue(), myLastVisitedPath, myQuickButton, myQuickCombo, myQuickLab, myUrls, myValidator, processPath(), quickDir(), SUIT_Session::resourceMgr(), SUIT_Session::session(), QtxResourceMgr::stringValue(), and updateSideBar().

◆ SUIT_FileDlg() [2/2]

SUIT_FileDlg::SUIT_FileDlg ( QWidget parent,
const QString &  initial,
const QStringList &  filters,
const QString &  caption = QString(),
const bool  open = true,
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)

Constructor.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters list
captiondialog box title
openif true dialog box is used for file opening, otherwise - for saving
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator

References processPath(), setValidator(), and validator().

◆ ~SUIT_FileDlg()

SUIT_FileDlg::~SUIT_FileDlg ( )
virtual

Destructor.

References setValidator().

Member Function Documentation

◆ accept

void SUIT_FileDlg::accept ( )
protectedslot

Called when the user presses "Open"or "Save" button.

Verifies the user choice and closes dialog box, setting the return code to QDialog::Accepted

See also
acceptData()

References acceptData(), and myLastVisitedPath.

◆ acceptData()

bool SUIT_FileDlg::acceptData ( )
protectedvirtual

Validate user selection.

The validation is done by calling the corresponding methods of the validator. If the validator is not set, this method always returns true.

This method can be re-implemented in the subclasses to customize the file dialog behavior. Another solution could be implementing own file validator class.

Returns
true if user selection (file(s) or directory) is valid
See also
SUIT_FileValidator class, validator(), setValidator()

References addFilter(), SUIT_FileValidator::canOpen(), SUIT_FileValidator::canReadDir(), SUIT_FileValidator::canSave(), SUIT_FileValidator::canWriteDir(), checkPermissions(), hasWildCards(), isOpenDlg(), lineEdit(), selectedFiles(), and validator().

◆ addExtension()

QString SUIT_FileDlg::addExtension ( const QString &  fileName) const
protected

Add an extension to the specified file name.

The extension is extracted from the active filter.

Parameters
fileNamefile name to be processed
Returns
fileName with the extension added

References Qtx::extension(), and IGNORE_NON_MATCHING_EXTENSION.

◆ addFilter()

void SUIT_FileDlg::addFilter ( const QString &  filter)
protected

Add file filter and activates it.

Parameters
filternew file filter

◆ addQuickDir

void SUIT_FileDlg::addQuickDir ( )
protectedslot

Called when user presses "Quick Dir Add" button.

Adds current directory to the quick directories list and to the preferences.

References myQuickCombo, myUrls, SUIT_Session::resourceMgr(), SUIT_Session::session(), QtxResourceMgr::setValue(), QtxResourceMgr::stringValue(), and updateSideBar().

◆ addWidgets()

bool SUIT_FileDlg::addWidgets ( QWidget l,
QWidget w,
QWidget b 
)

Adds the specified widgets to the bottom of the file dialog.

The first widget (usually label) l is placed underneath the "file name" and the "file types" labels. The widget w is placed underneath the file types combobox. The last widget (usually button) b is placed underneath the Cancel push button.

In general, the widgets can be arbitrary. This method is added to support the functionality provided by the Qt series 3.x.

If you don't want to have one of the widgets added, pass 0 in that widget's position. Every time this function is called, a new row of widgets is added to the bottom of the file dialog.

Parameters
lfirst widget (e.g. text label)
wsecond widget (e.g. combo box)
bthird widget (e.g. push button)
Returns
true if widgets have been added successfully

◆ checkPermissions()

bool SUIT_FileDlg::checkPermissions ( ) const

Get 'check file permissions' flag.

Returns
flag value
See also
setCheckPermissions()

References myCheckPermissions.

◆ event()

bool SUIT_FileDlg::event ( QEvent e)
protectedvirtual

Customize events processing.

Parameters
eevent
Returns
true if the event e was recognized and processed

References polish().

◆ getExistingDirectory()

QString SUIT_FileDlg::getExistingDirectory ( QWidget parent,
const QString &  initial,
const QString &  caption = QString(),
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the existing directory selection.

If initial parameter is not null string it is used as starting directory at which dialog box is opened.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial directory dialog box to be opened on
captiondialog box title
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected directory name or null string if dialog box is cancelled
See also
getFileName(), getOpenFileNames()

References processPath(), selectedFile(), setValidator(), and validator().

◆ getFileName() [1/3]

QString SUIT_FileDlg::getFileName ( QWidget parent,
const QString &  initial,
const QString &  filters,
const QString &  caption = QString(),
const bool  open = true,
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the file opening/saving. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.This method can be used to select the file for opening or saving. The behavior is defined by the open parameter. Note, that selection validation depends on the dialog mode used.

If initial parameter is not null string it is used as starting directory or file at which dialog box is opened.

The parameter filters defines file filters (wildcards) to be used. This is the list of wildcards, separated by the ";;" symbols. If filters list is empty, "All files (*)" is used by default.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters separated by ";;"
captiondialog box title
openif true dialog box is used for file opening, otherwise - for saving
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected file name or null string if dialog box is cancelled
See also
getOpenFileNames(), getExistingDirectory()

References getFileName(), and validator().

◆ getFileName() [2/3]

QString SUIT_FileDlg::getFileName ( QWidget parent,
const QString &  initial,
const QStringList &  filters,
const QString &  caption = QString(),
const bool  open = true,
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the file opening/saving.

This method can be used to select the file for opening or saving. The behavior is defined by the open parameter. Note, that selection validation depends on the dialog mode used.

If initial parameter is not null string it is used as starting directory or file at which dialog box is opened.

The parameter filters defines file filters (wildcards) to be used. If filters list is empty, "All files (*)" is used by default.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters list
captiondialog box title
openif true dialog box is used for file opening, otherwise - for saving
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected file name or null string if dialog box is cancelled
See also
getOpenFileNames(), getExistingDirectory()

References selectedFile(), and validator().

◆ getFileName() [3/3]

QString SUIT_FileDlg::getFileName ( QWidget parent,
const QString &  initial,
const QStringList &  filters,
QString &  selectedFilter,
const QString &  caption = QString(),
const bool  open = true,
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the file opening/saving.

This method can be used to select the file for opening or saving. The behavior is defined by the open parameter. Note, that selection validation depends on the dialog mode used.

If initial parameter is not null string it is used as starting directory or file at which dialog box is opened.

The parameter filters defines file filters (wildcards) to be used. If filters list is empty, "All files (*)" is used by default.

The parameter selectedFilter outputs a filter selected by user.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters list
selectedFilteroutputs a filter selected by user
captiondialog box title
openif true dialog box is used for file opening, otherwise - for saving
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected file name or null string if dialog box is cancelled
See also
getOpenFileNames(), getExistingDirectory()

References selectedFile(), and validator().

◆ getLastVisitedDirectory()

QString SUIT_FileDlg::getLastVisitedDirectory ( )
static

Get last visited directory.

Note, that last visited path is memorized only if the dialog box is accepted.

Returns
last visited directory

References myLastVisitedPath.

◆ getLastVisitedPath()

QString SUIT_FileDlg::getLastVisitedPath ( )
static

Get last visited path.

Returns
last visited path

References myLastVisitedPath.

◆ getOpenFileNames() [1/2]

QStringList SUIT_FileDlg::getOpenFileNames ( QWidget parent,
const QString &  initial,
const QString &  filters,
const QString &  caption = QString(),
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the multiple file opening. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.If initial parameter is not null string it is used as starting directory or file at which dialog box is opened.

The parameter filters defines file filters (wildcards) to be used. This is the list of wildcards, separated by the ";;" symbols. If filters list is empty, "All files (*)" is used by default.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters separated by ";;"
captiondialog box title
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected file names or empty list if dialog box is cancelled
See also
getFileName(), getExistingDirectory()

References getOpenFileNames(), and validator().

◆ getOpenFileNames() [2/2]

QStringList SUIT_FileDlg::getOpenFileNames ( QWidget parent,
const QString &  initial,
const QStringList &  filters,
const QString &  caption = QString(),
const bool  showQuickDir = true,
SUIT_FileValidator validator = 0 
)
static

Show dialog box for the multiple files selection.

If initial parameter is not null string it is used as starting directory or file at which dialog box is opened.

The parameter filters defines file filters (wildcards) to be used. If filters list is empty, "All files (*)" is used by default.

The parameter caption is used as dialog box title. If it is is empty, the default title is used.

The parameter showQuickDir specifies if it is necessary to show additional quick directories list controls in the bottom part of the dialog box.

The validation of the user selection is done with help of the file validator (SUIT_FileValidator class). The last parameter validator can be used to pass the custom file validator to the dialog box.

Parameters
parentparent widget
initialinitial file (or directory) dialog box to be opened on
filtersfile filters list
captiondialog box title
showQuickDirif true the quick directory list widgets will be shown
validatorcustom file validator
Returns
selected file names or empty list if dialog box is cancelled
See also
getFileName(), getExistingDirectory()

References processPath(), selectedFiles(), setValidator(), and validator().

◆ hasWildCards()

bool SUIT_FileDlg::hasWildCards ( const QString &  s)
staticprotected

Check if the string contains wildcard symbols.

Parameters
sstring to be checked (for example, file name)
Returns
true if string contains "*" or "?" symbols

◆ isOpenDlg()

bool SUIT_FileDlg::isOpenDlg ( ) const

Check if the dialog box is used for opening or saving the file.

Returns
true if dialog is used for file opening and false otherwise

◆ lineEdit()

QLineEdit * SUIT_FileDlg::lineEdit ( ) const
protected

Get line edit which is used to enter file name.

Returns
line edit widget or0 if it could not be found

◆ polish()

void SUIT_FileDlg::polish ( )
private

Polish the dialog box.

◆ processPath()

bool SUIT_FileDlg::processPath ( const QString &  path)
protected

Processes selection : tries to set specified sirectory or filename as current file dialog selection.

Parameters
pathfile or directory path
Returns
true if path is processed correctly and false otherwise

References Qtx::dir(), Qtx::file(), and selectFile().

◆ quickDir

void SUIT_FileDlg::quickDir ( const QString &  dirPath)
protectedslot

Called when user selects directory from the "Quick Dir" combo box.

Browses the file dialog to the specified directory (if it is valid).

Parameters
dirPathselected directory

References SUIT_MessageBox::critical(), and processPath().

◆ selectedFile()

QString SUIT_FileDlg::selectedFile ( ) const

Get selected file.

Returns
selected file name or null string if file is not selected

References selectedFiles().

◆ selectedFiles()

QStringList SUIT_FileDlg::selectedFiles ( ) const

Get list of selected files.

Returns
selected file names

References addExtension().

◆ selectFile()

void SUIT_FileDlg::selectFile ( const QString &  f)

Selects current file.

This version of selectFile() methods works similar to Qt version 3.x: it selects the given file as current and it changes the current file dialog's directory to the directory of the file

Parameters
f- new current file name

References Qtx::dir().

◆ setCheckPermissions()

void SUIT_FileDlg::setCheckPermissions ( const bool  checkPerm)

Set 'check file permissions' flag.

If this flag is set and file validator is not null, the validator will check the file permissions also.

Parameters
checkPermnew flag value
See also
checkPermissions()

References myCheckPermissions.

◆ setValidator()

void SUIT_FileDlg::setValidator ( SUIT_FileValidator v)

Set file validator.

Destroys previous validator if the dialog owns it.

Parameters
vnew file validator
See also
validator()

References myValidator, and SUIT_FileValidator::parent().

◆ updateSideBar()

void SUIT_FileDlg::updateSideBar ( )
private

Update side bar URLs list.

References myUrls.

◆ validator()

SUIT_FileValidator * SUIT_FileDlg::validator ( ) const

Get file validator.

Returns
current file validator
See also
setValidator()

References myValidator.

Member Data Documentation

◆ myCheckPermissions

bool SUIT_FileDlg::myCheckPermissions
private

check permissions option

◆ myLastVisitedPath

QString SUIT_FileDlg::myLastVisitedPath
staticprivate

last visited path

◆ myQuickButton

QPushButton* SUIT_FileDlg::myQuickButton
private

quick dir panel: button

◆ myQuickCombo

QComboBox* SUIT_FileDlg::myQuickCombo
private

quick dir panel: combo box

◆ myQuickLab

QLabel* SUIT_FileDlg::myQuickLab
private

quick dir panel: label

◆ myUrls

QStringList SUIT_FileDlg::myUrls
private

sidebar urls

◆ myValidator

SUIT_FileValidator* SUIT_FileDlg::myValidator
private

file validator


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