1 // Copyright (C) 2014-2017 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<mailto:webmaster.salome@opencascade.com>
21 * ModuleBase_WidgetFileSelector.h
23 * Created on: Aug 28, 2014
27 #ifndef MODULEBASE_WIDGETFILESELECTOR_H_
28 #define MODULEBASE_WIDGETFILESELECTOR_H_
30 #include <ModuleBase.h>
31 #include <ModuleBase_ModelWidget.h>
35 #include <QStringList>
42 * Implementation of model widget for open file widget.
43 * It can be defined as following:
46 * id="import_file_selector"
50 * <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
53 * It can use following parameters:
54 * - id - name of object attribute
55 * - type - type of dialog. Possible values: open, save.
57 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
62 /// \param theParent the parent object
63 /// \param theData the widget configuration. The attribute of the model widget is obtained from
64 ModuleBase_WidgetFileSelector(QWidget* theParent,
65 const Config_WidgetAPI* theData);
66 virtual ~ModuleBase_WidgetFileSelector();
68 virtual QList<QWidget*> getControls() const;
70 /// Returns true if a file on the current path in the line edit
71 /// exists and has supported format
72 bool isCurrentPathValid();
75 /// Processing of path selection button press
76 void onPathSelectionBtn();
78 /// Processing of path changing
82 /// Saves the internal parameters to the given feature
83 /// \return True in success
84 virtual bool storeValueCustom();
86 virtual bool restoreValueCustom();
89 /// Converts format to filter string
90 static QString formatToFilter(const QString & theFormat);
92 /// Returns a short format string of theFilter string
93 static QString filterToShortFormat(const QString & theFilter);
95 /// Returns a list of extensions from theFilter
96 static QStringList filterToExtensions(const QString & theFilter);
98 /// Returns list of validator formats
99 QStringList getValidatorFormats() const;
101 /// Returns string containing formats
102 QString filterString() const;
104 /// Add an extension to file name if the extension is not defined
105 /// \param theFileName a file name
106 /// \param theFilter a file filter
107 /// \return the file name with extension
108 static QString applyExtension(const QString& theFileName, const QString& theFilter);
111 /// A control for path input
112 QLineEdit* myPathField;
114 /// A title of open file dialog box
118 QString mySelectedFilter;
120 /// A title of open file dialog box
122 WFS_OPEN, ///< open file
123 WFS_SAVE ///< save file
124 } myType; ///< type of dialog
127 QString myDefaultPath;
130 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */