Salome HOME
4f64d215ca7ebdeec9fdfd2192d1f7fd6f4ddb7c
[modules/shaper.git] / 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 *          title="Import file"
31 *          path="">
32 *          <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
33 *      </file_selector>
34 *  \endcode
35 */
36 class MODULEBASE_EXPORT ModuleBase_WidgetFileSelector : public ModuleBase_ModelWidget
37 {
38   Q_OBJECT
39  public:
40   /// Constructor
41   /// \param theParent the parent object
42   /// \param theData the widget configuation. The attribute of the model widget is obtained from
43   /// \param theParentId is Id of a parent of the current attribute
44   ModuleBase_WidgetFileSelector(QWidget* theParent,
45                                 const Config_WidgetAPI* theData,
46                                 const std::string& theParentId);
47   virtual ~ModuleBase_WidgetFileSelector();
48
49   virtual bool restoreValue();
50
51   QWidget* getControl() const;
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  protected:
72    /// Returns string containing formats
73   QString formatsString() const;
74
75   /// Return list of validator formats
76   QStringList getValidatorFormats() const;
77
78  private:
79    /// A control for path input
80   QLineEdit* myPathField;
81
82   /// Container
83   QWidget* myMainWidget;
84
85   /// A title of open file dialog box
86   QString myTitle;
87
88   /// Default path
89   QString myDefaultPath;
90 };
91
92 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */