Salome HOME
Doxygen warning fixes
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetFileSelector.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * ModuleBase_WidgetFileSelector.h
5  *
6  *  Created on: Aug 28, 2014
7  *      Author: sbh
8  */
9
10 #ifndef MODULEBASE_WIDGETFILESELECTOR_H_
11 #define MODULEBASE_WIDGETFILESELECTOR_H_
12
13 #include <ModuleBase.h>
14 #include <ModuleBase_ModelWidget.h>
15
16 #include <QList>
17 #include <QString>
18 #include <QStringList>
19
20 class QWidget;
21 class QLineEdit;
22
23 /**
24 * \ingroup GUI
25 *  Implementation of model widget for open file widget.
26 *  It can be defined as following:
27 *  \code
28 *      <file_selector
29 *          id="import_file_selector"
30 *          type="open"
31 *          title="Import file"
32 *          path="">
33 *          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
34 *      </file_selector>
35 *  \endcode
36 * It can use following parameters:
37 * - id - name of object attribute
38 * - type - type of dialog. Possible values: open, save.
39 */
40 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
41 {
42   Q_OBJECT
43  public:
44   /// Constructor
45   /// \param theParent the parent object
46   /// \param theData the widget configuration. The attribute of the model widget is obtained from
47   /// \param theParentId is Id of a parent of the current attribute
48   ModuleBase_WidgetFileSelector(QWidget* theParent,
49                                 const Config_WidgetAPI* theData,
50                                 const std::string& theParentId);
51   virtual ~ModuleBase_WidgetFileSelector();
52
53   virtual QList<QWidget*> getControls() const;
54
55   /// Returns true if a file on the current path in the line edit
56   /// exists and has supported format
57   bool isCurrentPathValid();
58
59  public slots:
60    /// Processing of path selection button press
61   void onPathSelectionBtn();
62
63   /// Processing of path changing
64   void onPathChanged();
65
66 protected:
67   /// Saves the internal parameters to the given feature
68   /// \return True in success
69   virtual bool storeValueCustom() const;
70
71   virtual bool restoreValueCustom();
72
73 protected:
74   /// Converts format to filter string
75   static QString formatToFilter(const QString & theFormat);
76
77   /// Returns a short format string of theFilter string
78   static QString filterToShortFormat(const QString & theFilter);
79
80   /// Returns a list of extensions from theFilter
81   static QStringList filterToExtensions(const QString & theFilter);
82
83   /// Returns list of validator formats
84   QStringList getValidatorFormats() const;
85
86   /// Returns string containing formats
87   QString filterString() const;
88
89   /// Add an extension to file name if the extension is not defined
90   /// \param theFileName a file name
91   /// \param theFilter a file filter
92   /// \return the file name with extension
93   static QString applyExtension(const QString& theFileName, const QString& theFilter);
94
95 protected:
96    /// A control for path input
97   QLineEdit* myPathField;
98
99   /// A title of open file dialog box
100   QString myTitle;
101
102   /// A current format
103   QString mySelectedFilter;
104
105   /// A title of open file dialog box
106   enum {
107     WFS_OPEN, ///< open file
108     WFS_SAVE ///< save file
109   } myType; ///< type of dialog
110
111   /// Default path
112   QString myDefaultPath;
113 };
114
115 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */