Salome HOME
Issue #529 : 4.07. Import IGES, export to BREP, STEP, IGES - Export IGES
[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 */
37 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
38 {
39   Q_OBJECT
40  public:
41   /// Constructor
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();
49
50   virtual bool restoreValue();
51
52   virtual QList<QWidget*> getControls() const;
53
54   /// Returns true if a file on the current path in the line edit
55   /// exists and has supported format
56   bool isCurrentPathValid();
57
58  public slots:
59    /// Processing of path selection button press
60   void onPathSelectionBtn();
61
62   /// Processing of path changing
63   void onPathChanged();
64
65 protected:
66   /// Saves the internal parameters to the given feature
67   /// \return True in success
68   virtual bool storeValueCustom() const;
69
70  protected:
71    /// Returns string containing formats
72   QString filterString() const;
73
74   /// Returns list of validator formats
75   QStringList getValidatorFormats() const;
76
77   /// Returns a format received from theArgument
78   QString getFormat( const std::string& theArgument ) const;
79
80  private:
81    /// A control for path input
82   QLineEdit* myPathField;
83
84   /// A title of open file dialog box
85   QString myTitle;
86
87   /// A title of open file dialog box
88   enum { WFS_OPEN, WFS_SAVE } myType;
89
90   /// Default path
91   QString myDefaultPath;
92 };
93
94 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */