1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_WidgetFileSelector.h
6 * Created on: Aug 28, 2014
10 #ifndef MODULEBASE_WIDGETFILESELECTOR_H_
11 #define MODULEBASE_WIDGETFILESELECTOR_H_
13 #include <ModuleBase.h>
14 #include <ModuleBase_ModelWidget.h>
18 #include <QStringList>
25 * Implementation of model widget for open file widget.
26 * It can be defined as following:
29 * id="import_file_selector"
33 * <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
36 * It can use following parameters:
37 * - id - name of object attribute
38 * - type - type of dialog. Possible values: open, save.
40 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
45 /// \param theParent the parent object
46 /// \param theData the widget configuration. The attribute of the model widget is obtained from
47 ModuleBase_WidgetFileSelector(QWidget* theParent,
48 const Config_WidgetAPI* theData);
49 virtual ~ModuleBase_WidgetFileSelector();
51 virtual QList<QWidget*> getControls() const;
53 /// Returns true if a file on the current path in the line edit
54 /// exists and has supported format
55 bool isCurrentPathValid();
58 /// Processing of path selection button press
59 void onPathSelectionBtn();
61 /// Processing of path changing
65 /// Saves the internal parameters to the given feature
66 /// \return True in success
67 virtual bool storeValueCustom();
69 virtual bool restoreValueCustom();
72 /// Converts format to filter string
73 static QString formatToFilter(const QString & theFormat);
75 /// Returns a short format string of theFilter string
76 static QString filterToShortFormat(const QString & theFilter);
78 /// Returns a list of extensions from theFilter
79 static QStringList filterToExtensions(const QString & theFilter);
81 /// Returns list of validator formats
82 QStringList getValidatorFormats() const;
84 /// Returns string containing formats
85 QString filterString() const;
87 /// Add an extension to file name if the extension is not defined
88 /// \param theFileName a file name
89 /// \param theFilter a file filter
90 /// \return the file name with extension
91 static QString applyExtension(const QString& theFileName, const QString& theFilter);
94 /// A control for path input
95 QLineEdit* myPathField;
97 /// A title of open file dialog box
101 QString mySelectedFilter;
103 /// A title of open file dialog box
105 WFS_OPEN, ///< open file
106 WFS_SAVE ///< save file
107 } myType; ///< type of dialog
110 QString myDefaultPath;
113 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */