Salome HOME
Selection priority in Sketch, clear selection when sketch goes from entity to neutral...
[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   ModuleBase_WidgetFileSelector(QWidget* theParent,
48                                 const Config_WidgetAPI* theData);
49   virtual ~ModuleBase_WidgetFileSelector();
50
51   virtual QList<QWidget*> getControls() const;
52
53   /// Returns true if a file on the current path in the line edit
54   /// exists and has supported format
55   bool isCurrentPathValid();
56
57  public slots:
58    /// Processing of path selection button press
59   void onPathSelectionBtn();
60
61   /// Processing of path changing
62   void onPathChanged();
63
64 protected:
65   /// Saves the internal parameters to the given feature
66   /// \return True in success
67   virtual bool storeValueCustom();
68
69   virtual bool restoreValueCustom();
70
71 protected:
72   /// Converts format to filter string
73   static QString formatToFilter(const QString & theFormat);
74
75   /// Returns a short format string of theFilter string
76   static QString filterToShortFormat(const QString & theFilter);
77
78   /// Returns a list of extensions from theFilter
79   static QStringList filterToExtensions(const QString & theFilter);
80
81   /// Returns list of validator formats
82   QStringList getValidatorFormats() const;
83
84   /// Returns string containing formats
85   QString filterString() const;
86
87   /// Add an extension to file name if the extension is not defined
88   /// \param theFileName a file name
89   /// \param theFilter a file filter
90   /// \return the file name with extension
91   static QString applyExtension(const QString& theFileName, const QString& theFilter);
92
93 protected:
94    /// A control for path input
95   QLineEdit* myPathField;
96
97   /// A title of open file dialog box
98   QString myTitle;
99
100   /// A current format
101   QString mySelectedFilter;
102
103   /// A title of open file dialog box
104   enum {
105     WFS_OPEN, ///< open file
106     WFS_SAVE ///< save file
107   } myType; ///< type of dialog
108
109   /// Default path
110   QString myDefaultPath;
111 };
112
113 #endif /* MODULEBASE_WIDGETFILESELECTOR_H_ */