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" />
37 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
42 /// \param theParent the parent object
43 /// \param theData the widget configuation. The attribute of the model widget is obtained from
44 /// \param theParentId is Id of a parent of the current attribute
45 ModuleBase_WidgetFileSelector(QWidget* theParent,
46 const Config_WidgetAPI* theData,
47 const std::string& theParentId);
48 virtual ~ModuleBase_WidgetFileSelector();
50 virtual bool restoreValue();
52 virtual QList<QWidget*> getControls() const;
54 /// Returns true if a file on the current path in the line edit
55 /// exists and has supported format
56 bool isCurrentPathValid();
59 /// Processing of path selection button press
60 void onPathSelectionBtn();
62 /// Processing of path changing
66 /// Saves the internal parameters to the given feature
67 /// \return True in success
68 virtual bool storeValueCustom() const;
71 /// Converts format to filter string
72 static QString formatToFilter(const QString & theFormat);
74 /// Returns a short format string of theFilter string
75 static QString filterToShortFormat(const QString & theFilter);
77 /// Returns a list of extensions from theFilter
78 static QStringList filterToExtensions(const QString & theFilter);
80 /// Returns list of validator formats
81 QStringList getValidatorFormats() const;
83 /// Returns string containing formats
84 QString filterString() const;
86 static QString applyExtension(const QString& theFileName, const QString& theFilter);
89 /// A control for path input
90 QLineEdit* myPathField;
92 /// A title of open file dialog box
96 QString mySelectedFilter;
98 /// A title of open file dialog box
99 enum { WFS_OPEN, WFS_SAVE } myType;
102 QString myDefaultPath;
105 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */