Salome HOME
Merge branch 'Dev_0.7.1' of newgeom:newgeom.git into Dev_0.7.1
[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 *  Implementation of model widget for open file widget.
25 *  It can be defined as following:
26 *  \code
27 *      <file_selector
28 *          id="import_file_selector"
29 *          title="Import file"
30 *          path="">
31 *          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
32 *      </file_selector>
33 *  \endcode
34 */
35 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
36 {
37   Q_OBJECT
38  public:
39   /// Constructor
40   /// \param theParent the parent object
41   /// \param theData the widget configuation. The attribute of the model widget is obtained from
42   /// \param theParentId is Id of a parent of the current attribute
43   ModuleBase_WidgetFileSelector(QWidget* theParent,
44                                 const Config_WidgetAPI* theData,
45                                 const std::string& theParentId);
46   virtual ~ModuleBase_WidgetFileSelector();
47
48   virtual bool storeValue() const;
49
50   virtual bool restoreValue();
51
52   QWidget* getControl() const;
53
54   virtual QList<QWidget*> getControls() const;
55
56   /// Returns true if a file on the current path in the line edit
57   /// exists and has supported format
58   bool isCurrentPathValid();
59
60  public slots:
61    /// Processing of path selection button press
62   void onPathSelectionBtn();
63
64   /// Processing of path changing
65   void onPathChanged();
66
67  protected:
68    /// Returns string containing formats
69   QString formatsString() const;
70
71   /// Return list of validator formats
72   QStringList getValidatorFormats() const;
73
74  private:
75    /// A control for path input
76   QLineEdit* myPathField;
77
78   /// Container
79   QWidget* myMainWidget;
80
81   /// A title of open file dialog box
82   QString myTitle;
83
84   /// Default path
85   QString myDefaultPath;
86 };
87
88 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */