1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef MODULEBASE_WIDGETFILESELECTOR_H_
21 #define MODULEBASE_WIDGETFILESELECTOR_H_
23 #include <ModuleBase.h>
24 #include <ModuleBase_ModelWidget.h>
28 #include <QStringList>
36 * Implementation of model widget for open file widget.
37 * It can be defined as following:
40 * id="import_file_selector"
44 * <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
47 * It can use following parameters:
48 * - id - name of object attribute
49 * - type - type of dialog. Possible values: open, save.
51 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
56 /// \param theParent the parent object
57 /// \param theData the widget configuration. The attribute of the model widget is obtained from
58 ModuleBase_WidgetFileSelector(QWidget* theParent,
59 const Config_WidgetAPI* theData);
60 virtual ~ModuleBase_WidgetFileSelector();
62 virtual QList<QWidget*> getControls() const;
64 /// Returns true if a file on the current path in the line edit
65 /// exists and has supported format
66 bool isCurrentPathValid();
69 /// Processing of path selection button press
70 void onPathSelectionBtn();
72 /// Processing of path changing
76 /// Reject the current editor dialog if it is shown and returns true.
77 virtual bool processEscape();
79 /// Saves the internal parameters to the given feature
80 /// \return True in success
81 virtual bool storeValueCustom();
83 virtual bool restoreValueCustom();
86 /// Converts format to filter string
87 static QString formatToFilter(const QString & theFormat);
89 /// Returns a short format string of theFilter string
90 static QString filterToShortFormat(const QString & theFilter);
92 /// Returns a list of extensions from theFilter
93 static QStringList filterToExtensions(const QString & theFilter);
95 /// Returns list of validator formats
96 QStringList getValidatorFormats() const;
98 /// Returns string containing formats
99 QString filterString() const;
101 /// Add an extension to file name if the extension is not defined
102 /// \param theFileName a file name
103 /// \param theFilter a file filter
104 /// \return the file name with extension
105 static QString applyExtension(const QString& theFileName, const QString& theFilter);
108 /// A control for path input
109 QLineEdit* myPathField;
110 QFileDialog* myFileDialog; ///< started dialog
112 /// A title of open file dialog box
116 QString mySelectedFilter;
118 /// A title of open file dialog box
120 WFS_OPEN, ///< open file
121 WFS_SAVE ///< save file
122 } myType; ///< type of dialog
125 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */